Bitcoin Mining on Ubuntu 11.04 "Natty" with poclbm and ATI


Updated 6/19/2011 - updated bitcoin app version to 0.3.23, simplified bitcoin setup directions

Updated 6/8/2011 - updated example app versions, clarified use of pools, clarified use of bitcoin standalone app, path cleanup, added link to headless mining guide

1. Introduction


Recently, I got interested in the new peer-to-peer digital currency, Bitcoin (read about it all about it at bitcoin.org if you're not familiar with it yet). Having decided to make use of my idling ATI graphics card for some bitcoin mining, I was able to cobble together a mining setup on Ubuntu 11.04 "Natty Narwhal" without too much trouble. It uses a standard miner app "poclbm", the Python OpenCL Bitminer.



Note that I already had a working official, ATI 'fglrx' graphics card driver package installed, so you'll want that taken care of before starting. I am also running the 32-bit version of Ubuntu; if you are on 64-bit, you can follow the 64-bit specific directions here (tested on 64-bit systems).

2. Install Ubuntu packages


Install required packages:

sudo aptitude install python-setuptools python-numpy \
subversion g++ libboost-all-dev

3. Install Bitcoin


Get the latest Bitcoin distribution, (0.3.23 as of this writing), unpack it to ~/bitcoin-0.3.23/, and set permissions.

cd ~ 
wget http://downloads.sourceforge.net/project/bitcoin/Bitcoin/bitcoin-0.3.23/bitcoin-0.3.23-linux.tar.gz 
tar xzvf bitcoin-0.3.23-linux.tar.gz 
chmod +x bitcoin-0.3.23/bin/*/bitcoin*

Configuring bitcoin:
cd ~
mkdir -p .bitcoin

Make up user/password here if you like:

echo "rpcuser=user" >> .bitcoin/bitcoin.conf
echo "rpcpassword=password" >> .bitcoin/bitcoin.conf

Now we can run bitcoin in server mode,
~/bitcoin-0.3.23/bin/32/bitcoin -server & 

And wait...and wait...hours...until the current block chain is downloaded and verified by your bitcoin client to catch up with the rest of the network. In the meantime, you can continue installing the rest of the software required for mining.

4. Install python-jsonrpc library


Install python-jsonrpc from official Subversion repository:
cd ~
svn checkout http://svn.json-rpc.org/trunk/python-jsonrpc
cd python-jsonrpc/
sudo python setup.py install

5. Install AMD APP SDK


Grab the AMD APP SDK from the AMD website and install it:

64-bit:

cd ~
wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.4-lnx64.tgz
tar xvzf AMD-APP-SDK-v2.4-lnx64.tgz

echo export AMDAPPSDKROOT=${HOME}/AMD-APP-SDK-v2.4-lnx64/ >> ~/.bashrc
echo export AMDAPPSDKSAMPLESROOT=${HOME}/AMD-APP-SDK-v2.4-lnx64/ >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=${AMDAPPSDKROOT}lib/x86_64:${LD_LIBRARY_PATH}' >> ~/.bashrc

source ~/.bashrc
cd /

sudo tar xfz $AMDAPPSDKROOT/icd-registration.tgz

32-bit:

cd ~
wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.4-lnx32.tgz
cd ~
tar xzvf AMD-APP-SDK-v2.4-lnx32.tgz
cd AMD-APP-SDK-v2.4-lnx32/

echo export AMDAPPSDKROOT=${HOME}/AMD-APP-SDK-v2.4-lnx32/ >> ~/.bashrc
echo export AMDAPPSDKSAMPLESROOT=${HOME}/AMD-APP-SDK-v2.4-lnx32/ >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=${AMDAPPSDKROOT}/lib/x86:$LD_LIBRARY_PATH' >> ~/.bashrc

source ~/.bashrc
     
cd /
sudo tar xfz $AMDAPPSDKROOT/icd-registration.tgz


6. Install pyopencl


Now you have to install pyopencl from source because the Ubuntu package depends on the Nvidia driver package, which will mess up our system if we are on ATI.

cd ~
wget http://pypi.python.org/packages/source/p/pyopencl/pyopencl-0.92.tar.gz#md5=0680f7272fe3ab5a3bcb0b6cfbd74994
tar xzvf pyopencl-0.92.tar.gz
cd pyopencl-0.92

32-bit configure:

./configure.py --cl-inc-dir=${AMDAPPSDKROOT}include --cl-lib-dir=${AMDAPPSDKROOT}lib/x86

64-bit configure:

./configure.py --cl-inc-dir=${AMDAPPSDKROOT}include --cl-lib-dir=${AMDAPPSDKROOT}lib/x86_64

Now build pyopencl:

make
sudo make install

7. Install poclbm command line miner


Get poclbm modules:
cd ~
mkdir poclbm
cd poclbm
wget --no-check-certificate https://github.com/m0mchil/poclbm/raw/master/BitcoinMiner.cl
wget --no-check-certificate https://github.com/m0mchil/poclbm/raw/master/BitcoinMiner.py
wget --no-check-certificate https://github.com/m0mchil/poclbm/raw/master/poclbm.py
wget --no-check-certificate https://github.com/m0mchil/poclbm/raw/master/sha256.py
cd ~


8a. Solo mining


When the block chain is downloaded fully, you can start up poclbm for solo mining:
python poclbm/poclbm.py -d 0 --user user --pass password
And wait a bit until you see khash/second appear.

8b. Pooled mining


To get more granularity from your mining results (i.e. the ability to make smaller earnings sooner, in exchange for a 0-3% fee), you can sign up for pooled mining at one of many pools, such as btcguild, btcmine, BitcoinPool, bitcoins.lc, or eligius. I recommend choosing one of the smaller pools in order to maintain health of the network, rather than favoring the largest pool by default. Search Google for "50% bitcoin hashpower problem" for more information on why this is important.

After you create an account at a pool, you'll generally need to create a separate worker for each miner that you run.

My poclbm command to mine in a pool looks like this:
python poclbm/poclbm.py -d 0 --host=[pool hostname] --port=8332 --user=[worker] --pass='[worker password]'

9. Final notes and related resources


After I wrote this, I found another complete guide for Ubuntu 11.04, targeted at 64-bit users, including the ATI fglrx driver installation if you haven't done that yet. You can find it on the bitcoin.org forums.

A guide for headless mining on Ubuntu 11.04 64-bit also exists on the bitcoin.org forums.

Debian users may also be interested in LinuxCoin, a ready-to-go Bitcoin client/mining distro based on Debian Squeeze.

Any problems following the directions, or comments, let me know. Happy mining!

21 comments:

  1. Hi, I did all the things in the guide, when I want to mine I get this message :


    erfan@erfan-desktop:~/Programs$ python poclbm.py -d 0 --user erfan --pass electr1cm0nk00
    *** CAL version mismatch:
    This OpenCL build requires version 1.4.879, version 1.4.635 installed.
    Aborting.

    can you tell me what does it mean, what is CAL version and how to fix it ? please !

    ReplyDelete
  2. Thanks for a grate post. There were a few bug in this for me so i posted on my blod with a few updates. My link is http://www.the-server-admin.com.
    I told everyone to drop you some coin. So plese post a address so we can hook you up.

    ReplyDelete
  3. Erfan, what version of the AMD App SDK did you install? It sounds like a mismatch, maybe you need a newer version installed.

    Marc: I'm glad the post was useful and thanks for linking back to me, I'll check to see what you had to do differently in your installation.

    Per your request I have created a Bitcoin address 1AS6Zq1JEUtfWhmnNwkLumeCSErVzfnfzD if you'd like to donate. Thanks!

    ReplyDelete
  4. I used the wget command you had for SDK
    wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.4-lnx64.tgz
    tar xvzf AMD-APP-SDK-v2.4-lnx64.tgz

    The main changes was the install command I had to used sudo apt-get install. Also I got the new version of bitcoin and I have to change the connect command.

    ReplyDelete
  5. The 4 poclbm files need to be downloaded to a *separate* directory, not into the pyopencl directory as the instructions seem to indicate.

    If you see 'ImportError: No module named _cl' you have above problem.

    ReplyDelete
  6. Reinout,
    Thanks for the comment, I've corrected that section of the directions to use a separate directory/

    ReplyDelete
  7. I compleated your guide, but I ran into a problem. After trying to run poclbm i get this.

    Traceback (most recent call last):
    File "poclbm/poclbm.py", line 3, in
    from BitcoinMiner import *
    File "/home/box1/poclbm/BitcoinMiner.py", line 4, in
    from log import *
    ImportError: No module named log


    Any ideas what I might have done wrong. I am pretty new to linux so this is all a little overwhelming.

    ReplyDelete
  8. That's odd:
    Traceback (most recent call last):
    File "poclbm.py", line 3, in
    from BitcoinMiner import *
    File "/home/todor/poclbm/BitcoinMiner.py", line 4, in
    from log import *
    ImportError: No module named log

    Maybe somethings has changed lately.

    ReplyDelete
  9. svn doesn't seem to be working for me but
    http://json-rpc.org/wiki/python-json-rpc
    describes how to use bazaar to do a checkout of the python-jsonrpc

    I put this here because it came up early in my search for a solution

    in case it's lost from there the exact line is
    $ bzr checkout http://bzr.json-rpc.org/trunk/python-jsonrpc

    ReplyDelete
  10. I also got the error

    Traceback (most recent call last):
    File "poclbm/poclbm.py", line 3, in
    from BitcoinMiner import *
    File "/home/spleenux/poclbm/BitcoinMiner.py", line 4, in
    from log import *

    ReplyDelete
  11. Yep i also get:

    Traceback (most recent call last):
    File "poclbm.py", line 3, in
    from BitcoinMiner import *
    File "/home/ashley/BitcoinMiner.py", line 4, in
    from log import *
    ImportError: No module named log

    ReplyDelete
  12. Hi, im getting an error when I try to make the pyopnecl:

    bpl-subset/bpl_subset/boost/python/detail/wrap_python.hpp:75:24: fatal error: patchlevel.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    make: *** [all] Error 1

    Can you help me out I can figure whats wrong

    ReplyDelete
  13. Yeah getting the same error, and all the docs on bitcoin.org are gone..



    Traceback (most recent call last):
    File "poclbm/poclbm.py", line 3, in
    from BitcoinMiner import *
    File "/home/devious/poclbm/BitcoinMiner.py", line 4, in
    from log import *
    ImportError: No module named log


    Any help would be greatly appriciated.

    ReplyDelete
  14. For those of you running into the import log and import util problems here's how you get past them. Instead of following the poclbm instructions above, only do these steps:

    apt-get install git-core
    cd
    git clone git://github.com/m0mchil/poclbm.git

    Now you can run it fine:
    cd poclbm
    ./poclbm.py

    ReplyDelete
  15. Actually the latest python-jsonrpc correct command should be:

    "git clone https://github.com/trepca/python-jsonrpc.git"

    instead of:

    "svn checkout http://svn.json-rpc.org/trunk/python-jsonrpc"

    ReplyDelete
  16. The patchlevel.h header error is due to not having python-dev installed. Additionally, if running Ubuntu, the following packages are required:

    python-setuptools python-numpy subversion g++ libboost-all-dev python-dev git-core

    git-core is required for the updated git version of poclbm (suggested).

    ReplyDelete
  17. I would like to thank you for the efforts you have put in writing this blog. I’m hoping
    the same high-grade web site post from you in the future also. Actually your
    creative writing abilities has encouraged me to get my own web site going now.
    Really blogging is spreading its wings and growing fast. Your write up is a great example.

    ReplyDelete
  18. For everyone having trouble with the missing modules log util Transport etc. It is because you need all files accompanied by poclbm.py. Go to

    https://github.com/m0mchil/poclbm

    and see the list of files. Then download them one by one
    wget --no-check-certificate https://github.com/m0mchil/poclbm/raw/master/log.py
    wget --no-check-certificate https://github.com/m0mchil/poclbm/raw/master/Transport.py

    etc.

    Then to connect to bitcoin, use the command:
    python poclbm.py -d 0 https://user:pass@127.0.0.1:8334

    where user and pass and 8334 are specified in your bitcoin.conf file
    rpcuser=user
    rpcpassword=pass
    rpcport=8334

    ReplyDelete
    Replies
    1. git clone git://github.com/m0mchil/poclbm.git

      does the thing.

      Delete
  19. File "./poclbm.py", line 80, in
    import BFLMiner
    File "/home/pkarc/poclbm/poclbm/BFLMiner.py", line 4, in
    from ioutil import find_udev, find_serial_by_id, find_com_ports
    File "/home/pkarc/poclbm/poclbm/ioutil.py", line 2, in
    from serial.tools import list_ports
    ImportError: No module named tools

    ReplyDelete
  20. Hello everyone, I'm sorry for not being able to update this post recently. I haven't been mining but I'd still like to update the original post for Ubuntu 12.04 at some point. Thank you all commenters who clarified/corrected the changes since last year.

    ReplyDelete

Comments welcome!

Recent Posts