The Open-Source Classroom

Prospecting for Ones and Zeros

Shawn Powers

Issue #230, June 2013

Create money out of thin air with cryptocurrency.

At the current market rates (April 24, 2013), a user with a single AMD Radeon 7950HD video card can make $6 a day mining cryptocurrency. Granted, it'll cost around $1 in electricity, but that's still a $5-per-day profit. Of course, tomorrow the market could tank, and it'll be worthless, but at this precise moment, it's profitable. I've written about cryptocurrency before in Linux Journal, but as you can imagine, I've gotten lots of questions about mining since the price skyrocketed. In this article, I want to talk specifically about mining. If you're unsure about cryptocurrency in general, look back at my past article: www.linuxjournal.com/content/cryptocurrency-your-total-cost-01001010010. If you just want to get down and nerdy, keep reading.

CPUs or GPUs?

Cryptocurrencies come in several varieties, but the most popular, and most valuable, is the Bitcoin. Since its early days, it's been silly to mine Bitcoins with a CPU. The raw horsepower of a GPU blows the doors off any CPU, regardless of the CPU's speed. Because of that wasted opportunity, Litecoin was developed specifically to make mining difficult for GPUs.

For several months, it proved to be a great way to take advantage of idle CPUs. It also opened up mining to the regular desktop user, because a standard workstation CPU would be able to contribute and create coinage. Brilliant programmers being what they are, however, GPUs now are able to mine Litecoins more efficiently than CPUs. It's still profitable to mine Litecoins with high-end CPUs, but the profits are measured in pennies instead of dollars.

Although Bitcoins still are the most popular cryptocurrency, an interesting mining fact is that it's more profitable to mine Litecoins and then trade them for Bitcoins. Perhaps that's my own little trade secret, but it's held true for several months, and it looks to continue. Once you figure out the hash rate you can achieve with Bitcoins versus your Litecoin hash rate, it's as simple as plugging the numbers in to the calculator at allchains.info/calc to see which is more profitable.

Where to Begin?

If you want to get into mining, it certainly sounds like a good idea to start with CPU mining on your existing desktop computer. Although that's definitely possible, my fear is that it will cause more frustration than fun. The profits, if any, will be in the pennies. If the market fluctuates (which it always does), you could go from making three cents a day to losing a nickel a day overnight. Plus, your system will be running at 100% CPU usage, making the rest of your computing frustrating. Still, if you just want to dabble, it's a way to start. If you want to mine with your desktop machine, you'll need to use a mining pool; otherwise, it will take years before you see any profit.

To start with serious mining, it means purchasing video cards. For Bitcoins, there also are custom FPGA and ASIC boards that can do mining, but most people still use GPUs, so I focus on those here. Also, in this article, I focus more on Litecoins because they're slightly more profitable to mine, but also because the mining rigs are harder to configure. If you can mine Litecoins, Bitcoins are a breeze, so let's focus on Litecoins.

Currently, the best price/hashrate/electrical-usage video card is the AMD 7950HD. For about $300, the 7950 produces around 600kH/s on the Litecoin network. There is a great wiki that compares the various GPU chipsets and their wattage versus hashrate. You owe it to yourself to study the wiki to see what will work best for you: https://github.com/litecoin-project/litecoin/wiki/Mining-hardware-comparison.

(There is a similar chart for Bitcoin mining. It's worth reading that in case the Litecoin market crashes and burns, and being able to switch to mining Bitcoins efficiently is a bonus: https://en.bitcoin.it/wiki/Mining_hardware_comparison.)

In addition to the hash rate and electrical usage, the allchains.info site mentioned previously is a great tool for figuring out how much money a particular set of GPUs will create. Keep in mind that the market is highly volatile, but it's a nice way to see a snapshot daily rate.

And of course, to use a GPU, you need a motherboard that will hold it. Thankfully, cryptocurrencies don't require anything more than PCI-E 1x for bandwidth, so as long as you can get the cards into the slots (or use extenders), you're set. Add a cheap CPU, a gig or two of RAM and a power supply big enough to support your rig, and you're golden! I know, it's a lot to think about and a lot to consider, but if this sort of planning is fun, mining cryptocurrency is perfect for you!

My Head Hurts

Did the last section dash your hopes of ever becoming a miner? Too complicated? Too many variables? I understand. Here's a sample mining rig, part by part:

Motherboard: ASRock 970 EXTREME4—this motherboard is about $99 and has the convenient spacing that allows (three) GPUs to be mounted at the same time (Figure 1). They'll be crammed together, but I'll talk about cooling a little later.

Figure 1. The PCI-E slots are far enough apart that all three are usable.

RAM: Crucial 2GB Kit (2x1GB) 240 pin DDR3 1333—for $30 or so, this is more than enough RAM to mine with. When I tried to find a 1GB kit, it cost more, so I got this kit because it was the cheapest.

CPU: AMD Sempron 145 Sargas 2.8GHz—this single-core CPU is less than $40, fits in the AM3+ slot on the motherboard listed above and is horrible for mining anything. You could buy an expensive CPU and get some mining hashes out of it, but the time it would take to recoup the expense is crazy. I recommend slow and cheap.

Hard Drive: anything—if you're considering building a mining rig, chances are you have a pile of old hard drives sitting in a closet or on a shelf. Just use one of those. Otherwise, any old SATA hard drive will work.

Power Supply: 850Watt 80 PLUS certified or better—don't go less than 850 watts, even if you don't start with three full cards. Give yourself room to grow. Also, the more efficient power supply you buy, the more profitable your rig will be in the long run. The price you pay will vary anywhere from $90 to $175 or so. Make sure you have enough PCI-E power connectors for the cards you're going to be installing. (Note: you can get adapters to convert SATA power connectors to PCI-E connectors, but I wouldn't recommend using too many of those in a single rig.)

GPUs: AMD Radeon 7950 HD—these seem to be available from a fairly wide variety of on-line sources. The prices range from $299 to around $329, and each card will do around 600kH/s on the Litecoin network. Other cards work, some are faster, and if you can get a deal on something else, just compare on the charts mentioned previously. If you just want a parts list, however, go with the 7950. It's a great card.

Case: don't use a case. GPUs produce a ton of heat while they're mining, so it's best to have them out in the open air. Plus, you can get a $10 box fan and push more cooling air over an exposed rig than any number of case fans could do.

The Build

If you've researched for days and ordered what you found to be the absolute best possible combination of hardware, or if you just used my list, the build is similar. When not using a case, find a fairly secure location where you can set up computer equipment and not worry about anyone bumping it. (I have my rigs set up in the basement; see Figure 2.)

Figure 2. It's not pretty, but it does the job!

I should add a disclaimer that you should wear a static wrist strap, make sure everything is grounded, and securely mount the motherboards and power supplies onto whatever surface you're using. Those are all very important things. As you can see in my photo, however, my motherboards are sitting on empty boxes, and I turn my rigs on by shorting the power connector on the motherboard with a screwdriver. My setup is a bit redneck, and I can't recommend that you do the same, but I won't judge you if you do.

These rigs will be headless, as you can tell by the photo, but for the operating system install, you'll need a monitor. I recommend installing Xubuntu. I won't go through the details on how to install Xubuntu, but you can use a USB stick to install it or a temporary CD drive—whatever floats your boat. Be sure to have the system log in automatically. This is a requirement for later on when you won't have a monitor connected! Once Xubuntu is installed, you need to go to amd.com and get the latest Catalyst driver for Linux. (Make sure to get the version that matches your installed system in regards to 32- or 64-bit.) Please note that although there are proprietary drivers in the Xubuntu distro, those drivers do not have the things required for mining. You'll need to install the driver from amd.com in order to mine properly.

After you run the installer, you'll be forced to reboot. Once rebooted, you need to make sure the video card(s) are all initialized. This is a squirrelly procedure, which doesn't work consistently. Simply open a terminal and type:

sudo aticonfig --adapter=all --initial

The squirrelly part is that sometimes it doesn't detect all the cards. Look at the output, and make sure it listed the number of cards you have installed. If not, run the same command over, and it likely will detect them. (I know, it's weird.) Once that's done, you'll need to reboot again. At that point, configuring the GPU drivers should be done.

The other tools you'll need installed (these from the product repositories) are screen and openssh-server. Those come into play when you run the miners in headless mode. Make sure you have a static IP address set on your mining rig, then reboot it one final time, disconnecting the keyboard, mouse and monitor. If everything goes right, you should have a headless miner set to log in automatically, with an SSH server running so you can connect remotely. Leave the dark basement and go back to your comfy workstation. You should be able to do the rest from there.

A Bit about Pools

Before you actually set up the mining programs, it's important to decide where you're going to mine. Back in the day before cryptocurrencies were popular, a user would install the litecoin client and mine locally. The problem with that method now is that it would take weeks or months to find a “block” mining on your own. Unless you have many thousands of dollars worth of mining rigs, you'll want to mine at a pool. Basically, users at a pool will combine their mining horsepower and then split the coins they mine proportionally to the hashing power they contribute. This means instead of mining for months and possibly finding a block of 50 coins, the pool miners get a regular payout daily based on their contribution to the network. With my nine GPUs mining 24/7, I can earn only ten Litecoins a day. If I didn't mine with a pool, it would become frustrating quickly.

Several mining pools are available for Litecoins and Bitcoins. Regardless of what pool you choose, I recommend withdrawing your earnings on a regular basis, because pool owners are anonymous, and I'm not terribly trusting. (Perhaps Linux Journal should start a pool—hmmm....) Here's a partial list of pools: https://github.com/litecoin-project/litecoin/wiki/Comparison-of-mining-pools.

One Miner to Rule Them All

I know I'm focusing on GPU mining here, but since I'm talking about miner programs, it seems a good time at least to mention how to CPU mine. If you're mining Litecoins with a CPU, you want to use pooler's miner (https://github.com/pooler/cpuminer). For mining with a GPU, whether you want to mine Bitcoins or Litecoins, cgminer is the tool of choice (https://github.com/ckolivas/cgminer). I use cgminer here and configure it to mine Litecoins. Be sure to get the latest binary, because Litecoin support is a fairly recent addition to cgminer.

From the comfort of your workstation, ssh in to your miner. Assuming everything is working correctly, you should be able to log right in. Now that you're logged in, type screen to get a screen session going, so once you start mining, you can disconnect and it will keep mining. Because mining requires OpenCL, it means that you have to be using the X Window System display. Because you're SSH'd in, that would be a problem, except that Linux is so very flexible. In the screen session, type:

export DISPLAY=:0

That should give you the ability to use OpenCL. While you're at it, export a couple other variables that fix a few oddities with how GPU memory is handled:

export GPU_USE_SYNC_OBJECTS=1
export GPU_MAX_ALLOC_PERCENT=100

There should be nothing returned from the system; you're just setting some environment variables so that cgminer works properly. If you haven't downloaded and extracted the cgminer program, do so now. Then, cd to that directory:

cd cgminer_folder_name

Now, see if cgminer sees all your GPUs:

./cgminer -n

You should see something like this:

[2013-04-24] CL Platform 0 vendor: Advanced Micro Devices, Inc.

[2013-04-24] CL Platform 0 name: AMD Accelerated Parallel Processing

[2013-04-24] CL Platform 0 version: OpenCL 1.2 AMD-APP (1084.4)                 

[2013-04-24] Platform 0 devices: 3                    
[2013-04-24]  0       Cypress                    
[2013-04-24]  1       Cypress                    
[2013-04-24]  2       Cypress                                        
[2013-04-24]  3 GPU devices max detected    

Assuming all your cards are showing, you're ready to mine! If not, you might have to fiddle with the aticonfig tool again. Remember, it's a bit squirrelly. Because you're inside a screen session, you can start mining and then disconnect the screen session without stopping cgminer. For a quick start, type something like this (all on one line):

./cgminer --scrypt -o stratum+tcp://your.pool:3333 
 ↪-u pool_user -p pool_pass -I 13               

You'll need to fill in your information for pool IP, port, user and password. If everything works correctly, after a few moments, you should see cgminer doing its thing with all your GPUs. (Figure 3 shows one of my rigs.)

Figure 3. These are actually three 5850 cards, not 7950s

Step 73—Profit?

To be honest, all this work got you only to the beginning of configuring your mining rigs. If there's enough interest, perhaps I'll do another column on tweaking and overclocking for maximum hash rates and maximum profit. In the meantime, reading forums like https://bitcointalk.org will yield some valuable information. (It also will yield trolls, scammers and so on—the forum is like the dirty underbelly of the Bitcoin mining community.) The next steps I recommend are:

  • Read the cgminer options and configuration options in the README. It's an amazing piece of software.

  • Tweak your memory speeds, clock speeds, thread concurrency and intensities to get better hash rates.

  • Set up scripts to start your miners, and create config files for cgminer instead of putting everything on a really long command-line argument. Use your script to export those environment variables so you don't forget to do so.

  • Install the litecoin (or bitcoin) client on a computer, so you can withdraw your coins to your own local wallet.

  • Check out the Resources section for this article. Lots of information is available; it's a data-geek's dream.

If you're a cryptocurrency miner or are about to become one, please send photos of your mining rigs to info@linuxjournal.com. You can tell by my setup that we don't care about professionalism, it's just really cool to see other people's setups. If you'd like to hear more about Bitcoins or Litecoins, let us know that too!

Shawn Powers is the Associate Editor for Linux Journal. He's also the Gadget Guy for LinuxJournal.com, and he has an interesting collection of vintage Garfield coffee mugs. Don't let his silly hairdo fool you, he's a pretty ordinary guy and can be reached via e-mail at info@linuxjournal.com. Or, swing by the #linuxjournal IRC channel on Freenode.net.