Ethereum (ETH) mining on Ubuntu Server 16.04
What am I up to?
I recently became interested in cryptocurrency mining. These are my notes on setting up a server for running Claymore's ETH miner with the new AMDGPU-Pro Beta Mining Driver for Linux driver.
I will be referring to two machines in these instructions. The first is a computer that is already setup for completing tasks (the workstation), the second is a computer that we will be configuring (the server). My workstation runs Ubuntu Mate 16.04, so these instructions will assume a Unix-like environment.
PS - I spend a lot more time writing software than administrating servers. If I have made any horrible errors please let me know: taborkelly@gmail.com.
Hardware
I have the following hardware which I will be setting up to mine ETH. This is my server:
- ASRock H81 PRO BTC R2.0 motherboard
- Intel Celeron G1840 Processor
- 4GB RAM
- EVGA SuperNOVA 1000 G2 power supply
- six PCIe riser cables
- six SAPPHIRE NITRO Radeon RX 470 4GB GPUs
- An SSD that I had sitting around
- Homemade case/frame
Install Ubuntu Server 16.04
We are going to be running Ubuntu server 16.04.03 as recent versions of AMD's OpenCL implementation do not require an X Server to run. So, go ahead and download ubuntu-16.04.3-server-amd64.iso if you do not already have it:
wget http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso
I personally prefer to copy ISOs to installation media (thumb-drives) using dd
. So, plug in your USB thumb-drive. The USB thumb-drive will most likely be auto-mounted and you will need to unmount it. There are lots of ways to figure out which partition(s) to unmount, one ways is to tail
/var/log/syslog while you plug in the USB thumb-drive:
$ tail -f /var/log/syslog | grep Mounted
Jul 11 18:24:50 workstation udisksd[2429]: Mounted /dev/sdb1 at /media/your_username/foo on behalf of uid 1000
Now unmount the partition(s) and use dd
to write the iso file to the thumb-drive. Note that while we unmount the partitions /dev/sdAN (where A is a letter and N is a number) we dd
to the device /dev/sdA. Be extra careful to dd
to the correct device on your system or you could end up overwriting one of your hard-drives.
$ umount /dev/sdb?
$ sudo dd bs=4M if=ubuntu-16.04.3-server-amd64.iso of=/dev/sdb
$ sync
I won't walk you through installing Ubuntu Server as it is pretty self explanatory. However, I would suggest that:
- When asked about automatic security updates, choose to take automatic security updates.
- When asked what extra software to install, select OpenSSH Server.
Upon first booting into your new server, bring the system completely up to date:
sudo apt-get update
sudo apt-get dist-upgrade
I strongly suggest that you install your ssh public key on the server and disable password based logins. If you do not have an ssh public key you can read about creating one here. On your workstation:
ssh-copy-id server
Now, on the server, edit /etc/ssh/sshd_config
and add the line PasswordAuthentication no
. This will prevent future password based logins.
Install AMD's OpenCL environment
First, make sure to reboot the server so that if you installed a new kernel during the system update that the AMD installer compiles for the new kernel version.
sudo reboot
Next, using your workstation, download the the new AMDGPU-Pro Beta Mining Driver for Linux.
I like to do my work outside of my home directory, so I'm going to setup a directory on the server at /work.
cd /
sudo mkdir work
sudo chown your_username:your_username work/
On your workstation, copy over the AMD driver installer:
scp amdgpu-pro-17.40-483984.tar.xz server:/work
On the server, unpack and install the AMD driver. Make sure to add the --compute
to ./amdgpu-pro-install
so that you don't pull in X.
cd /work
tar xvf amdgpu-pro-17.40-483984.tar.xz
cd amdgpu-pro-17.40-483984/
./amdgpu-pro-install --compute
# Add yourself to the video group
sudo usermod -a -G video $LOGNAME
# Add amdgpu.vm_fragment_size=9 to GRUB_CMDLINE_LINUX_DEFAULT
sudo vim /etc/default/grub
# update your grub image
sudo update-grub
# Finally, reboot again so that the kernel module gets loaded correctly.
sudo reboot
At this point you should be able to log back in and verify that OpenCL is working correctly and that the kernel command-line was passed correctly:
/opt/amdgpu-pro/bin/clinfo
cat /proc/cmdline
Install Claymore's ETH miner
On your workstation, download the latest version of Claymore's ETH miner here. Then copy it to the server:
scp Claymore\'s\ Dual\ Ethereum+Decred_Siacoin_Lbry_Pascal\ AMD+NVIDIA\ GPU\ Miner\ v10.2\ -\ LINUX.tar.gz server:/work
On the server, unpack the tarball, put it someplace sane, and install the required libcurl3
package:
cd /work
tar xvf Claymore\'s\ Dual\ Ethereum+Decred_Siacoin_Lbry_Pascal\ AMD+NVIDIA\ GPU\ Miner\ v10.2\ -\ LINUX.tar.gz
# and move it into a sane directory name
mv Claymore\'s\ Dual\ Ethereum+Decred_Siacoin_Lbry_Pascal\ AMD+NVIDIA\ GPU\ Miner\ v10.2\ -\ LINUX claymore_eth_v10.2
sudo apt-get install libcurl3
Next, create a start.sh
to meet your needs. Mine looks like this:
#!/bin/sh
./ethdcrminer64 -epool eth-us-west1.nanopool.org:9999 -ewal ADDRESS.server/emailaddress -epsw x
Make sure that start.sh
is executable:
chmod a+x start.sh
Finally, we can setup an init.d
script to start mining in a screen session after every reboot. Copy the following file to /etc/init.d/claymore.sh
:
#!/bin/sh
### BEGIN INIT INFO
# Provides: claymore
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: <DESCRIPTION>
### END INIT INFO
start() {
echo 'Starting service claymore' >&2
cd /work/claymore_eth_v10.2
su your_username -c "screen -dmS claymore ./start.sh" &
echo 'Service started claymore' >&2
}
stop() {
echo 'Stopping service claymore' >&2
su your_username -c "screen -S claymore -X stuff ^C"
echo 'Service stopped claymore' >&2
}
uninstall() {
echo "uninstall() "
}
case "$1" in
start)
start
;;
stop)
stop
;;
uninstall)
uninstall
;;
retart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac
Now make sure that claymore.sh
is executable and use update-rc.d
to configure it to be executed on boot:
sudo chmod a+x claymore.sh
sudo update-rc.d claymore.sh defaults
sudo update-rc.d claymore.sh enable
One more time, reboot to check your configuration. Now, when you login, you should already see your screen session running:
screen -list
There is a screen on:
1101.claymore (12/22/2017 09:22:31 PM) (Detached)
1 Socket in /var/run/screen/S-your_username.
This is cool for a couple reasons:
- After a power outage (if your BIOS is set correctly), your server will reboot and immediately start mining again.
- You can setup your firewall to allow you to SSH in and check your server from anywhere in the world. To view your mining status use
screen -x claymore
. However, when you are done checking make sure to detach the screen session with^A+D
(CTRL-A followed by D), not^C
, as the^C
will be delivered toclaymore
and it will terminate.
Final notes
We now have a server mining ETH! On my hardware I get ~21.7MH/s per (stock, not overclocked) AMD RX-470 GPU. Don't forget to pay your taxes!