Ethereum (ETH) mining on Ubuntu Server 18.04
What am I up to?
Every winter, to heat my house, I mine cryptocurrency. These are my notes on setting up a server for running ethminer with the new AMDGPU-Pro 18.40 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 18.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 18.04
We are going to be running Ubuntu server 18.04.1 as recent versions of AMD's OpenCL implementation do not require an X Server to run. So, go ahead and download ubuntu-18.04.1-live-server-amd64.iso if you do not already have it:
wget http://releases.ubuntu.com/18.04/ubuntu-18.04.1-live-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-18.04.1-live-server-amd64.iso of=/dev/sdb
$ sync
I won't walk you through installing Ubuntu Server as it is pretty self explanatory. 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 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-18.40-697810-ubuntu-18.04.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 amdgpu-pro-18.40-697810-ubuntu-18.04.tar.xz
cd amdgpu-pro-18.40-697810-ubuntu-18.04/
./amdgpu-pro-install --compute
# Add yourself to the video group
sudo usermod -a -G video $LOGNAME
# 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:
/opt/amdgpu-pro/bin/clinfo
Install ethminer miner
On your workstation, download the latest version of ethminer here. Then copy it to the server:
scp ethminer-0.16.1-linux-x86_64.tar.gz server:/work
On the server, unpack the tarball and put it someplace sane:
cd /work
tar xvf ethminer-0.16.1-linux-x86_64.tar.gz
# and move it into a sane directory name
mv bin ethminer-0.16.1
Next, create a start.sh
to meet your needs. Mine looks like this:
#!/bin/sh
./ethminer --opencl stratum://YOURWALLETADDRESS.server@eth-us-west1.nanopool.org:9999/youremailaddress@email.com
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/ethminer.sh
:
#!/bin/sh
### BEGIN INIT INFO
# Provides: ethminer
# 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 ethminer' >&2
cd /work/ethminer-0.16.1
su your_username -c "screen -dmS ethminer ./start.sh" &
echo 'Service started ethminer' >&2
}
stop() {
echo 'Stopping service ethminer' >&2
su your_username -c "screen -S ethminer -X stuff ^C"
echo 'Service stopped ethminer' >&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 ethminer.sh
is executable and use update-rc.d
to configure it to be executed on boot:
sudo chmod a+x ethminer.sh
sudo update-rc.d ethminer.sh defaults
sudo update-rc.d ethminer.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.ethminer (12/11/2018 08:22:31 AM) (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 ethminer
. 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 toethminer
and it will terminate.
Final notes
We now have a server mining ETH! On my hardware I get ~21.45MH/s per (stock, not overclocked) AMD RX-470 GPU. Don't forget to pay your taxes!