Installation of BTC / LTC Ubuntu 13.04 headless miner

20 May 2013 13:51
Tags bitcoin headless litecoin miner mining ubuntu

Back to list of posts

Before some time I've spent several days figuring out how to install standalone Bitcoin (or some-other-coin) headless miner which wouldn't need any attention at all. Finally I've finished the job succesfully, but few days ago it become clear, that I need to reinstall the system .. I reallized that I'll probably have to go through all of that process again .. well done: I haven't made any notes :)

So I've decided to make some notes and as such, this should be a collection of instructions on how to install standalone BTC (Bitcoin) or LTC (Litecoin) miner based on Ubuntu Linux 13.04 server distribution. I tried Ubuntu 12.04.2 LTS but had some serious problems with GPU drivers, so I don't reccomend to even try that way to anyone !

Usefull links:

Hardware

Motherboard Gigabyte GA-990XA-UD3
CPU AMD FX-4130 3,8 GHz (AM3+)
GPU 3x AMD Radeon HD 7950 OEM 3 GB GDDR5
RAM 2GB 1600 DDR3
PSU Corsair GS800
Storage 4GB micro Flash drive
WIFI card CM9

Setup the system

  1. download Ubuntu 12.04.2 LTS image
  2. make the install disk - unfortunatelly none of the utilities like Universal USB Installer (1.9.3.4), UNetbootin, or LiLi doesn't work for creation of bootable instalation USB key. All of them will generate USB install disk which will fail to instal the system in the middle of the process. Instead use Startup Disk Creator inside Ubuntu Desktop. I personally use virtual machine with Ubuntu 12.04 LTS to do this.
  3. install Ubuntu normally, with nothing except SSH server. I'm installing onto 4GB USB micro flash drive, so manual partitioning is required to ensure I make swap partition around 500MB and 3.4GB is left for the system. Swap is not needed on such machine.
  4. connect to the machine with ssh client like Putty.

Preparation

Login as root, update the system and download necessary upgrades:

sudo su 
apt-get update && apt-get upgrade

WiFi card setup

I have WiFi card in my computer that I want to setup first so here is small how-to

Compiler, etc.

Install compiler, make, cmake, development support, MidnigtCommander …

Install additional tools like svn, git …

sudo su
apt-get install -y build-essential gcc make cmake mc python-dev subversion git bzip2 unzip

Install GPU Drivers

First of all we need to install X-Server as it is required by ATI drivers. Also you may want to install minimalistic openbox, although I do not use it:

apt-get install xorg
apt-get install openbox

Then we need to download the most recent ATI Catalyst driver from their page or some older from their archive. I experienced problems with newest drivers so I would rather go with older, but debugged.
cd ~
mkdir download
cd download
wget http://www2.ati.com/drivers/linux/amd-catalyst-13.4-linux-x86.x86_64.zip
unzip amd-catalyst-13.4-linux-x86.x86_64.zip
rm amd-catalyst-13.4-linux-x86.x86_64.zip
chmod +x amd-catalyst-13.4-linux-x86.x86_64.run
./amd-catalyst-13.4-linux-x86.x86_64.run --force
aticonfig --adapter=all --initial

Use key —force if you want to refresh installed drivers. Second command initializes ATI adapters, there are however some MEGA-troublesome issues when you use many cards. More on this on next subchapter and on "Problems with aticonfig ".

Reboot the system !

X-server issue

If you want to run cgminer without ability to monitor temperature / change clock etc, then don't build with ADL library and everything will be running ok - and you can happily skip this subchapter. However there are some catches if you want to use those features.

First of all try to initialize the driver and check current temperature:

aticonfig --initial --adapter=all
aticonfig --adapter=all --odgt

But if you try to set clocks or monitor GPU, nasty error "ERROR - X needs to be running to perform AMD Overdrive(TM) commands" will appear. Problem is described here and reason should be that there is not xinit running. Here is the script for it's autostartup based on this article and others.:
vi /etc/init.d/xinit

#!/bin/bash
# standard functions library
. /lib/lsb/init-functions
# Start the xinit
start() {
        # Start xinit on background and redirect stdout and stderr to log file
        echo "Starting xinit"
        xinit &> /var/log/xinit.log &
}
# Restart the xinit
stop() {
        echo "Stopping xinit"
        killall xinit
}
### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status xinit
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac
exit 0

Then we have to make this script executable and set it up for automatic startup.
chmod +x /etc/init.d/xinit 
update-rc.d xinit defaults 90

export DISPLAY=:0
echo export DISPLAY=:0 >> ~/.bashrc

Those two lines about DISPLAY are supposed to tell cgminer on which cards to mine (they say everywhere).

If you want to disable that xinit auto startup:

update-rc.d -f xinit remove

Now you can use aticonfig for example to see temperatures:

sudo aticonfig --adapter=all --odgt

Problems with aticonfig

There are however problems with drivers. In order to see if GPUs are initialized properly, try to run:

fglrxinfo

which should output something like this:
display: :0  screen: 0
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon HD 7900 Series
OpenGL version string: 4.2.12217 Compatibility Profile Context 12.104

display: :0  screen: 1
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon HD 7900 Series
OpenGL version string: 4.2.12217 Compatibility Profile Context 12.104

display: :0  screen: 2
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon HD 7900 Series
OpenGL version string: 4.2.12217 Compatibility Profile Context 12.104

If fglrxinfo is not working normally then try to install fglrx-control:
apt-get install -y fglrx-amdcccle-updates

When I configured miner with this procedure, I experienced some very serious issues with drivers and initialisation of the cards. On forums there are numerous complains by users that their cgminer cannot monitor temperatures or that it cannot overclock the GPUs (which is very, very important). If there is problem with configuration of the driver, then when you run cgminer it will show that number of GPUs received from AMD APP SDK is not the same as from ADL SDK (or something simmilar) and therefore it is disabling overclocking / monitoring. It happened to me A LOT OF TIMES and I installed system maybe 20x with different distributions of Ubuntu, vertsiond of drivers etc., until I was able to figure this out.

Some of the guyz on forums will tell you that you need tp use "dummy plugs". I believe that maybe on windows, or GUI Linux it may be neccessary, however I found out that their usage is comletely rendundand for solving my problem. As well as are crossfire-bridges. Only important thing is the xorg.conf file located at:

vi /etc/X11/xorg.conf

It's content is generated by:
aticonfig --adapter=all --initial

aticonfig --adapter=<card_num> --initial

I had the problem that first command which must be run after GPU driver installation generated xorg.conf file with two card with ID 1 for whatever reason. I've tried to use dummy plugs, bridges, switching cards etc … nothing worked when I used the first command for all cards. But once I used 2 on place of <card_num> it generated correct config file and everything started to work OK. I believe that one should be able to write this config file by hand if aticonfig —adapter=all —initial fails completely. lspci command is useful in determining what is wrong.

AMD APP SDK

The following code is result of attempt to automate download process because of AMD's enforcement to accept their license. By using this code you are automatically accepting it (! :). After some time when they change their site this code may not be functional anymore. Change file name AMD-APP-SDK-v2.8-lnx64.tgz to anything appropriate. Here is their site.

sudo su
cd ~
cd ~/download/
wget -O licenseAgreement http://developer.amd.com/wordpress/media/files/AMD-APP-SDK-v2.8-lnx64.tgz
key=`grep "name=\"f\"" licenseAgreement | sed 's_\(.*value=\"\)\([.]*\)_\2_' | sed 's_\([.]*\)\".*_\1_'`
wget -O AMD-APP-SDK.tgz --post-data "f=$key" http://developer.amd.com/wordpress/media/download.php
rm licenseAgreement

Now install it:

tar zxvf AMD-APP-SDK.tgz -C /opt
cd /opt
chmod +x Install-AMD-APP.sh
./Install-AMD-APP.sh
reboot

If there is problem during build of cgminer try:

sudo tar zxvf /opt/icd-registration.tgz -C /

AMD ADL library

This will allow cgminer adjustments of such things as your GPU’s clocking, voltage and fan speed. Here is the site. Download and use most recent:

cd ~
cd ~/download/
wget -O licenseAgreement http://developer.amd.com/wordpress/media/files/ADL_SDK_5.0.zip
key=`grep "name=\"f\"" licenseAgreement | sed 's_\(.*value=\"\)\([.]*\)_\2_' | sed 's_\([.]*\)\".*_\1_'`
wget -O AMD-ADL.zip --post-data "f=$key" http://developer.amd.com/wordpress/media/download.php
rm licenseAgreement

Now install it:

unzip AMD-ADL.zip -d /opt/AMD-ADL/

CGMiner prerequisities

Install Python, numpy, scipy and other prerequisities:

apt-get -y install libcurl4-openssl-dev libncurses5-dev pkg-config automake yasm libtool
apt-get install -y python2.7 python-numpy python-scipy

PyOpenCL

Download:

cd ~/download/
wget http://pypi.python.org/packages/source/p/pyopencl/pyopencl-0.92.tar.gz
tar zxfv pyopencl-0.92.tar.gz -C /opt

Build and install:

cd /opt/pyopencl-0.92
sudo sh -c 'echo "/opt/AMDAPP/lib/x86_64/" >> /etc/ld.so.conf.d/local.conf'
sudo ./configure.py --cl-inc-dir=/opt/AMDAPP/include/ --cl-lib-dir=/opt/AMDAPP/lib/x86_64
ldconfig
source ~/.bashrc
make -j3
make install

JSON RPC

cd ~/download/
wget https://eclipsemc.com/files/python-jsonrpc.tar.gz
tar xvfz python-jsonrpc.tar.gz -C /opt
cd /opt/python-jsonrpc/
python setup.py install

Build CGMiner

Clone CGMiner Git repository and copy ADL_SDL includes into it's dirrectory:

cd ~
git clone git://github.com/ckolivas/cgminer.git newcgminer
mkdir ~/newcgminer/ADL_SDK/
cp /opt/AMD-ADL/include/* ~/newcgminer/ADL_SDK/

Configure & build it. It is necessary to run autogen.sh when building from git repository. It will generate error however, but ./configure script repairs everything:

cd ~/newcgminer/
./autogen.sh
CFLAGS="-O2 -Wall -march=native -I/opt/AMDAPP/include" DFLAGS="-L/opt/AMDAPP/lib/x86_64" ./configure --enable-scrypt
make install

Test cgminer:

./cgminer -n

There was one problem with segmentation fault when compiled with ADL. Delete AMD_ADL folder and rerun config.

RUN!

Now you should be able to run cgminer. Here is my example config file for BTC mining:

cd ~/newcgminer/
vi btc-template.conf

{
    "pools" : [
        {
            "url" : "stratum.xyz.com",
            "user" : "my.miner",
            "pass" : "passwd"
        }
    ],

    "intensity" : "14,14,14",
    "gpu-engine" : "0-1000,0-1000,0-1000",
    "gpu-fan" : "95",
    "gpu-memclock" : "940,940,940",
    "gpu-powertune" : "0,0,0",
    "temp-overheat" : "100,100,100",
    "temp-target" : "85,85,85",

    "kernel" : "diablo,diablo,diablo",
    "auto-gpu" : true,
    "expiry" : "120",
    "failover-only" : true,
    "expiry" : "120",
    "gpu-dyninterval" : "7",
    "gpu-platform" : "0",
    "gpu-threads" : "2",
    "log" : "5",
    "queue" : "5",
    "retry-pause" : "5",
    "scan-time" : "60",
    "temp-hysteresis" : "3",
    "shares" : "0",
    "kernel-path" : "/usr/local/bin"
}

To run cgminer with above config file:

./cgminer -c btc-template.conf

Tuning the configuration

File for BTC mining does set constant fan speed, if you want the cgminer to regulate your fans according to temperature, add this line into config file:

    "auto-fan" : true,

And set ranges for fan speed:
    "gpu-fan" : "20-95,20-95,20-95",

Good configuration for my 7950 without overclocking:

./cgminer --scrypt -o stratum+tcp://eu.wemineltc.com:3333 -u mzamba.1 -p x --intensity 20 --lookup-gap 2 --shaders 1792 --thread-concurrency 24576

API access

If you want to access your cgminer from another machine add following parameters when starting up cgminer:

--api-network --api-listen

If you want to limit acccess from particular IP use:
--api-allow address[/subnets]

If there is problem with connection debug comes handy:
--debug

Troubleshooting

Booting hangup

There is a quite nasty problem with the GRUB bootloader waiting endlessly on the booting screen waiting for <enter> key to be pressed (more often after no-clean shutdown). Obviously this is not very helpful behaviour when your headless system is 500km from you physically :) So there are some attempts how to solve this - I'm not sure whether they really help. It is discussed here.

Tip 1:
Edit /etc/default/grub:

vi /etc/default/grub

Find lines:
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true

and change them to:
GRUB_HIDDEN_TIMEOUT=10
GRUB_HIDDEN_TIMEOUT_QUIET=false

uptade GRUB:
sudo update-grub

Tip 2:
Edit /etc/default/grub:

vi /etc/default/grub

Add line:
GRUB_RECORDFAIL_TIMEOUT=5

It will hang on booting screen only after 5 fails instead of one.
uptade GRUB:
sudo update-grub

Donations welcome!

If you like this tutorial and it helped to solve your problem, and can spend some coin, I will gladly accept that as 'thank you' :). Here are my addresses:

LTC LbrSpsCbbcc5joGyreq1Cu7AyZypUChX7w
BTC 1CioY5GWvBeNXZuQTgBphs9aDfewdQMpbL

Comments: 2

Add a New Comment

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License