DEV Community

Jason
Jason

Posted on • Originally published at blog.ijasoneverett.com on

CPU Mining on a Raspberry Pi

Monero is one of the most profitable cryptocurrencies that can still be mined using a CPU. Unlike other cryptocurrencies that rely on specialized hardware, you can mine XMR (RandomX) using your computer or, in this case, a raspberry pi. With that said if you’re going to use your raspberry pi to mine Monero don’t expect to get rich doing so. This is more of a learning experience if you have a spare raspberry pi lying around or if you simply want to support the coin.

To get started, you should already have Raspian running on your pi. If you haven’t done so already I suggest you follow one of the many tutorials out there. Its your choice whether you choose to have a monitor, keyboard and mouse attached to your pi or if you prefer to go headless and utilize SSH. I prefer the latter but this tutorial can be done either way. We’re going to be using XMRig to mine Monero with a mining pool. XMRig only runs on 64-bit so we’ll be using a 64-bit container called raspbian-nspawn-64. First let’s make sure you’re raspberry pi is up to date. Using terminal lets run the following commands:

sudo apt update
sudo apt full-upgrade


For good measure, lets run clean up to free up some space:

sudo apt-get clean

Reboot if necessary:

sudo shutdown -r now

Once you’re pi is up to date, we can get started installing raspbian-nspawn-64 using the following command:

sudo apt-get install -y raspbian-nspawn-64

If you’re not currently using the official 64-bit kernel, you’ll be prompted to enable it during installation. Select Yes and you should be prompted to reboot afterwards. If you were already using the 64-bit kernel then a reboot isn’t necessary. Once everything is installed and you’ve rebooted if necessary, you can start using the 64-bit container with the following command:

ds64-shell

.

To return to 32-bit simply type exit. You can toggle between 32-bit and 64-bit with these commands.

Now let’s install XMRig from within your 64-bit shell. First you’ll need to install all the dependencies.

sudo apt-get install git build-essential cmake libuv1-dev libssl-dev libhwloc-dev

Once thats finished with hopefully no errors run the following commands:

git clone https://github.com/xmrig/xmrig.git
cd xmrig
mkdir build
cd build
cmake ..
make

The build process can take some time to complete so be patient. After installation the next step is to choose a mining pool and start mining. I choose supportxmr because of their low pool fee but feel free to choose what best works for you. To start mining type:

./xmrig --donate-level 1 -o pool.supportxmr.com:3333 -u 49NU9LmdsTc1KCiiRd9LE4Qm23gt1i75vWHsTGhB8agy93K4cq16KVtLKifsBy3YdzT2Zg69ggDKfDq5YdnfWshG6BZxGh3 -p YourWorkerName

Make sure you run this from the build folder. If you aren’t already there then its cd xmrig/build

–donate-level can be set to whatever you feel like donating to the pool.

-o is the URL of your pool.

-u should be your Monero wallet address. Make sure to change that to your address or else you’ll be giving to me free XMR!

-p stands for password but since SupportXMR doesnt require a password, this is used to identify your worker so give it a unique name.

Thats all you need to get started mining Monero on your Raspberry Pi.

For other XMRig options use ./xmrig -h

Top comments (7)

Collapse
 
fabiolln profile image
Fábio Leal da Luz

On Raspberry pi 4
root@debian-buster-64:~/xmrig/build# cmake ..
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_CXX_COMPILER could be found.

Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.

-- Configuring incomplete, errors occurred!
See also "/root/xmrig/CMakeFiles/CMakeOutput.log".
See also "/root/xmrig/CMakeFiles/CMakeError.log".
root@debian-buster-64:~/xmrig/build#

Collapse
 
jmaderer1 profile image
watsamader

Jason how do I update this version to version 10.0, could you spare a second it will fix my brain I’m learning and I like how your instructions were sooooo nice to follow, I’ve had my miner working for over a year but I’m getting illegal instruction error ever few days and it stops my miner, id like to update it but everything I’ve tried isn’t working, it’s probably the easiest fix but I just don’t see it

Collapse
 
grantrocks profile image
Grant McNamara

A more updated article here
theoverpoweredpc.ml/2021/12/how-to...

Collapse
 
mrsaugas profile image
MrSaugas

Running the make fails for me:
cc: error: unrecognized command-line option '-maes'
make[2]: *** [src/crypto/ghostrider/CMakeFiles/ghostrider.dir/build.make:82: src/crypto/ghostrider/CMakeFiles/ghostrider.dir/sph_blake.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:240: src/crypto/ghostrider/CMakeFiles/ghostrider.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

What is missing?
Thanks
D

Collapse
 
giuseppegarzotto profile image
Giuseppe Garzotto

What model of Raspberry is used in this example ?

Collapse
 
haru02w profile image
Haru02w

probably raspberry PI 3, because Raspberry pi 2, 1 and zero doesn't support 64bit applications

Collapse
 
grantrocks profile image
Grant McNamara

sadly to say this the 64-bit shell no longer works. You can use the 64-bit os though.
cryptoandpi.cf/blog/posts/mining-o...