There are lots of reason to use Linux for GPU mining, and one of the best is the automation of management with shell scripts. I got tired of upgrading the linux miners that I have, and I recently had a power outage, so I wrote and enabled two scripts to take care of those issues.
Along the way, I decided to start using tmux instead of screen for the mining sessions. I’m about to build 10 more miners, this time with RX470 GPU’s from AMD, so I’ll write an updated HowTo for Zcash (and it’s forks) and Ethereum with the new information. Meanwhile, here are the scripts.
Automatic mining start on Boot for Optiminer
If you used the 6-GPU Mining Rig for Linux on Optiminer I wrote in January, we created a mine.sh start script that was designed to run in a virtual terminal. I’ve changed what I use for vty, so now I use Tux. Here is how to set it up.
Create a file in your user directory called startmining.sh and fill it with commands, replacing “user” with your username:
Here is what goes in the file:
#!/bin/bash tmux new-session -d -n mining tmux send-keys -t mining "cd /home/user/optiminer-zcash " tmux send-keys -t mining "./mine.sh "
Make it executable by typing
chmod +x startmining.sh
The test it by giving the command:
What you should see is…nothing. This script opened a new tmux, then sent it two commands. To enter the tmux session and see what happened, type
And you should see Optiminer running and mining
Type ctrl-b d to get out of the tmux session.
Now let’s set things up so this script is run whenever the miner reboots. To do this, type
Then at the bottom of the file (if you chose Vim, selection 3, just hit GG to go to bottom, then o to enter a new line of text), add:
Now whenever the machine reboots, it will start mining right away.
Script to Upgrade, Free Up Space on /boot, and Reboot
I had a problem where I was upgrading Ubuntu, but not purging the old kernel images off the /boot directory. That was fine…until the /boot directory was full. Then things started to go sideways. Mining still worked, but Ubuntu was not happy. So I created this script, and set it up so I could call it remotely from a different server if I wanted to. For the first few times, I am running it while watching it, because sometimes the Linux upgrade acts funny. But after a while, I will probably have it run in a tmux and just upgrade all the miners at once with a single script.
Create this file and script:
Fill it with:
#!/bin/bash sudo apt autoremove --purge -y sudo apt update && sudo apt upgrade -y sudo reboot
Then make it executable:
chmod +x upgradelinux.sh
Now set it up so it can be run without typing in the sudo password. First type
This takes you to editing the visudo file, which let’s you change the privileges of users. Add this to the bottom, and put in your username for user:
user ALL=(ALL) NOPASSWD: /home/user/upgradelinux.sh
Save this file (in nano it’s ctrl-x, Y, and return), and now give it a try by typing
What you should see happen is the whole upgrade process, then a reboot. On reboot, the machine should start mining right away. When you log back in, access the mining by typing
Get out of the session by typing ctrl-b d
And there you go. Two handy scripts to make managing all your 6-GPU Mining Rigs easier!
Upgrade and Reboot All the Miners!
If you want to take it to the next level, and you have a Ubuntu box you can use to send commands to the other boxes, you can upgrade them all at once by creating a script that logs in and issues the upgrade command. Create this script on another box:
#!/bin/bash ssh firstname.lastname@example.org "/usr/bin/sudo /home/user/upgradelinux.sh" ssh email@example.com "/usr/bin/sudo /home/user/upgradelinux.sh" ssh firstname.lastname@example.org "/usr/bin/sudo /home/user/upgradelinux.sh"
Make it executable, then run it. The script will ssh into each one of your miners, run the linux upgrade script, then reboot the box. On reboot, it will start mining. I like to do this when I am near my miners, just in case one of them hangs on reboot and I have to go turn the power switch off then on by hand.