Simplified GPU-powered cryptocurrency mining on Ubuntu 16.04

I recently won $12k in Microsoft Azure credits at a Hackathon, which I didn’t have any real use for. Since I didn’t want them to expire either, I decided to at last mine some cryptocurrency on Azure’s GPU-powered VMs of the NV-series.
Getting everything set up on Ubuntu 16.04 proved to be a very manual and tedious process, especially when spinning up several VMs.

To that end, I created some scripts that make installing the required miners incl. all dependencies, libs and frameworks a lot easier.
In the /steps folder of the repo, you will find a few scripts that - when executed in the given order with root permissions - will setup everything you need to start mining with ccminer

1. Prepare packages

We create a subfolder ~/mining in the users home directory, where we will install everything we’re going to need. We also have to install a number of packages later steps depend on.

1_aptget.sh
1
2
3
mkdir ~/mining
apt-get update && apt-get -y dist-upgrade
apt-get install gcc g++ build-essential libssl-dev automake linux-headers-$(uname -r) git gawk libcurl4-openssl-dev libjansson-dev xorg libc++-dev libgmp-dev python-dev

2. Download Nvidia Driver and CUDA

At the time of writing this, versions 375.66 of the Nvidia driver and 8.0 of CUDA were the most recent - change accordingly, if newer versions are available.

2_getinstaller.sh
1
2
3
cd ~/mining && wget http://us.download.nvidia.com/XFree86/Linux-x86_64/375.66/NVIDIA-Linux-x86_64-375.66.run
chmod +x ~/mining/NVIDIA-Linux-x86_64-375.66.run
cd ~/mining && wget https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb

3a. Disable Nouveau driver

In order to use the Nvidia Driver, we first will have to disable the default Noveau driver. The installation of the Nvidia driver will fail on the first run, but will also disable the Noveau driver, so that after rebooting the machine, the installation will work.

3a_install-nvidia-driver.sh
1
~/mining/NVIDIA-Linux-x86_64-375.66.run --accept-license --no-questions --disable-nouveau --no-install-compat32-libs

3b. Install Nvidia driver

Noveau driver has been disabled by the previous run of the Nvidia Installer. This will now work

3b_install-nvidia-driver.sh
1
~/mining/NVIDIA-Linux-x86_64-375.66.run --accept-license --no-questions --disable-nouveau --no-install-compat32-libs

4. Install CUDA

Cryptocurrencies are obtained by using computing power to calculate for a large number of input variables (hashes) if they match certain criteria.
The possibility of finding a match is often referred to as the difficulty of the currency, i.e. at the time of writing Bitcoin’s difficulty was 595,921,917,085, meaning that only one out of 600 Billion checks would result in an actual positive result, aka a Bitcoin.
It is obvious that doing more calculations in parallel is favourable to the yield of the mining.

That’s where GPUs come in - they have significantly more computing units, thus allowing a much higher rate of parallelism at checking hashes.
CUDA is a technology developed by Nvidia that enables using GPUs to process general purpose calculations (such as checking hashes).

This speeds up calculations significantly, simply due to the total number of cores available (4096 cores in an Nvidia M60 vs. 4 in a current gen Intel i7)

4_install-cuda.sh
1
2
3
4
5
6
7
8
dpkg -i ~/mining/cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64-deb

apt-get update
apt-get install cuda-toolkit-8-0
usermod -a -G video $(whoami)
echo "" >> ~/.bashrc
echo "export PATH=/usr/local/cuda-8.0/bin:$PATH" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64:$LD_LIBRARY_PATH" >> ~/.bashrc

dkpg might take a while. If shell script hangs or dies, try executing it manually.

Reboot again

5. Install ccminer

After a reboot, we have all the drivers installed and ready. The only thing missing is a mining software that knows how to do the actual calculations that will result in coins.
ccminer is one of the most widespread solutions and provides support for a large number of different currencies

5_make-ccminer.sh
1
2
3
4
5
6
7
8
9
10
11
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
make
/usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery
cd ~/mining
git clone https://github.com/tpruvot/ccminer
cd ccminer
git checkout linux
./autogen.sh
./configure
make
make install

Other miners

Setting up other miners (i.e. Marlin for Siacoin - see 6_install-marlin.sh)should be fairly easy at this point since most complexity goes into preparing the system to correctly utilize its GPU units.

Happy mining