Skip to main content

Mining Bitcoins with Raspberry Pi - Part 3

·405 words·2 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure
Mining Bitcoins with Raspberry Pi - This article is part of a series.
Part 3: This Article

Continuing on from the good work we have achieved thus far in Part 1 & Part 2, we are going to complete our Bitcoin Mining journey by making our Raspberry Pi start mining as soon as it is powered on.

We previously had the following command to start the cgminer application as a background process (i.e. a service)

sudo nohup ./cgminer --compact --real-quiet --config /path/to/config.conf >/dev/null 2>&1&

Now, we are going to take that command, change it up one final time and have it run upon startup.

First, lets open up rc.local file, which contains startup commands with nano by doing the following

sudo nano /etc/rc.local

Next, create some space above this line

exit 0

In this space, we will put in our cgminer as a background process command with a few changes below

nohup /home/pi/cgminer/cgminer --compact --real-quiet --config /home/pi/path/to/config.conf >/dev/null 2>&1&

So what’s changed?

Firstly, we have removed the use of sudo which elevates us to an administrator. Anything ran from the rc.local file will be run by the root user and thus there is no need for sudo.

Secondly, we have changed the path of both cgminer and the config file so that it is the full path. Previously we made use of the ~ character which is shorthand for the current users home directory. Once again, this isn’t relevant to the root user as we git cloned cgminer to the home directory of our standard user on the Raspberry Pi, which is pi. All home directories in Raspbian are located under /home/ and thus the full path to any folders or files located in our home directory is /home/pi/

Once you have successfully edited the file in nano, hit CTRL-X followed by y to exit and save the file.

Now you can restart your Raspberry Pi to test. To do so from the command line punch in

sudo shutdown -r now

After the restart, check the running processes/services with the top command

If you got your paths correct you will see cgminer ticking away.

That’s it. Thanks for following along on journey of mining the cryptocurrency Bitcoin on the humble Raspberry Pi with USB ASIC mining hardware. Not only have we covered using cgminer but also vital parts of Linux such as the nohup command, top, kill as well as using the rc.local file.

Chime in below with your results or if you have any other suggestions for a Raspberry Pi project!

Mining Bitcoins with Raspberry Pi - This article is part of a series.
Part 3: This Article

Related

Mining Bitcoins with Raspberry Pi - Part 2
·396 words·2 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
In a previous post, we covered how to setup your Raspberry Pi with cgminer along with some USB ASIC mining hardware.
Mining Bitcoins with Raspberry Pi - Part 1
·537 words·3 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
Continuing with my last post’s theme surrounding my recently received Raspberry Pi; after the initial configuration, I put it into action by mining Bitcoins with some Aussie USB ASIC miners I purchased of eBay for $36 (for two).
Raspberry Pi A+
·215 words·2 mins
tech iot linux raspberry-pi raspbian technology
Christmas brought me a very special gift in the form of a Raspberry Pi A+