Linux GPU Miner Management Scripts for Upgrade and Auto-start
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.
March 20, 2017 @ 5:04 pm
Hi Rolf. Have you looked at: ethosdistro.com which I’ve had running pretty reliably for several weeks. Upgrading is extremely easy to the latest Claymore or Optiminer..
March 21, 2017 @ 10:27 am
Zij, I will give ethos a try. I have 10 rigs I am building up with RX470’s in the next week or two, and I’ll see what I can do with it. Thanks!
June 18, 2017 @ 6:51 am
can some one please make a ubantu claymore noob friednly setup please
June 24, 2017 @ 6:42 pm
this one is a little older, but give it a try:
February 6, 2018 @ 4:11 am
Hello there, I followed a similar TMUX-based auto-start tutorial, but I find that the tmux-session does not get full-GPU-power until a user logs onto the computer. The session starts with the computer only connected to the wall socket and powered on, but the hashrates are looooow (about 60% of normal).
I’m using Linux Mint, and I think GPUs don’t go full-power unless the standard log-in sequence is initiated. Investigating now, but wonder if anyone has any information on this. Absolutely nothing on the internet about this it seems.
February 21, 2018 @ 9:01 pm
Can some give some advice to start a second intsance (three cards one, three other user and pool) of miner via tmux? I created another mine_mnx2.sh, put other user and device (-d 3 -d 4 -d 5), also created startmining2.sh but got error:
terminate called after throwing an instance of ‘boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::
Any advice? Thanks
February 21, 2018 @ 9:03 pm
…Also changed name of new session
p.s. Very nice tutorial I forgot to mention.
February 21, 2018 @ 9:10 pm
Full log problem
[2018-02-21 19:47:36.192] [info] Optiminer/Equihash 2.0.0 (C) Optiminer 2017
terminate called after throwing an instance of ‘boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector >’
what(): bind: Address already in use