Apparently mining Monero on Raspberry Pis seems to be all the rave now? So let’s try:

I had 5 Raspi 3B and one 4B 8GB lying around…

Mining In A Pool

Although you can download the official wallet and just start mining, the hash rate of your computer will most certainly be too small to ever solve a block and get a reward. So we will use a mining pool, where the work and rewards are distributed across all miners in the pool.

There are a lot of mining pools with different parameters around. I use xmrfast because they also pay out rewards as small as 0.005 XMR and I expect to not make much $XMR anyway. Also, it’s not a big pool so I contribute to the decentral nature of Monero.

Setup Ansible Scripts

So let’s set up some miners. As always I use Ansible to get rid of the repetitive tasks. You can use the scripts below as starting point. All you need is some 64bit Pis with SSH access and python3 installed.

miners.ymlview raw
---
- hosts: miners
roles:
- xmrig
...

That’s enough for the playbook, we will do the rest in the role:

roles/xmrig/tasks/main.ymlview raw
---
- name: Ensure build environment
apt:
name:
- build-essential
- git
- cmake
- libuv1-dev
- libssl-dev
- libhwloc-dev

- name: Clone xmrig repo
git:
repo: https://github.com/xmrig/xmrig.git
dest: /home/pi/xmrig
version: v6.16.2
become_user: pi
register: clone_repo

- name: Clean
command: rm -rf /home/pi/xmrig/build
when: clone_repo.changed
register: clean

- name: Ensure build directory
file:
name: /home/pi/xmrig/build
state: directory
become_user: pi
when: clean.changed

- name: Configure
command:
cmd: cmake ..
chdir: /home/pi/xmrig/build
become_user: pi
when: clean.changed

- name: Make
command:
cmd: "make -j4"
chdir: /home/pi/xmrig/build
become_user: pi
when: clean.changed

- name: Install
copy:
src: /home/pi/xmrig/build/xmrig
dest: /usr/local/bin/xmrig
remote_src: yes
mode: '0755'
when: clean.changed

- name: Copy systemd unit file
copy:
src: files/xmrig.service
dest: /etc/systemd/system/xmrig.service
mode: 0644

- name: Ensure config directory
file:
name: /etc/xmrig
state: directory

- name: Copy config
copy:
src: files/config.json
dest: /etc/xmrig/config.json
mode: 0644

- name: Ensure xmrig service
service:
name: xmrig
state: started
enabled: yes
...

So basically we download the source code, compile and install it and make a service out of it. The code is tailored to Raspi 4Bs with the explicit user “pi” and the “make -j4”. You should maybe adapt that to your needs.

The service file looks like this:

files/xmrig.serviceview raw
[Unit]
Description = xmrig Monero Mining Service

[Service]
ExecStart = /usr/local/bin/xmrig -c /etc/xmrig/config.json

[Install]
WantedBy=multi-user.target

There, we reference the config file. Mine uses CPU only as we are on Pis and TLS to connect to the server. Don’t forget to fill in you Monero wallet address in user.

files/config.jsonview raw
{
"autosave": true,
"cpu": true,
"opencl": false,
"cuda": false,
"pools": [
{
"url": "pool.xmrfast.com:9000",
"user": "...",
"keepalive": true,
"tls": true
}
]
}

That’s my host file:

hosts.ymlview raw
---
all:
hosts:
miner01:
ansible_host: miner01.fritz.box
miner02:
ansible_host: miner02.fritz.box
miner03:
ansible_host: miner03.fritz.box
miner04:
ansible_host: miner04.fritz.box
miner05:
ansible_host: miner05.fritz.box
miner06:
ansible_host: miner06.fritz.box
children:
miners:
hosts:
miner01:
miner02:
miner03:
miner04:
miner05:
miner06:
vars:
ansible_port: 22
ansible_user: pi
ansible_become: yes
ansible_ssh_private_key_file: ~/.ssh/id_rsa
ansible_python_interpreter: /usr/bin/python3
...

Does it work?

YES! I also loaded a node-exporter on every Pi and logged to my Prometheus:

So how well does it work?

Here is the absolute hash rate of the Pis taken from the 15min average of xmrig. I included my Dell XPS 15 with a i9-9880HK and GTX 1650 as a comparison:

Now the Dell absolutely destroys both Pis. Although it’s interesting to see that the Pi 4B is nearly four times as fast as the Pi 3B. Also, the anti-CPU tactics of Monero seem to be working: The CPU is much more performant than the GPU.

But in Mining, absolute performance matters less than efficiency. So I measured the energy consumption of the 3 devices and divided the hash rate by it:

Again, the Dell CPU is far ahead, but less so, as it’s using 50W of power. The Pi 3B only uses 5.92W and the 4B 6W. In this test the GPU is the worst as the Laptop still uses 46W of power for the comparatively bad hash rate.

Of course measuring the Dell carries some uncertainties due to the included battery and automatic CPU throttling. Also I did not reinstall the system before the tests but I undervolted the CPU by 0.1 V. Anyway, you should start the miner with admin privileges. That nearly doubled the hash rate for me.

So what does all that mean in Euro? The following plot shows the expected earnings. I assumed my current energy price of 0.305 €/kWh and also the current $XMR price of €198.21:

So only the Dell CPU has any real chance of making profit. Excluding the cost of the machine, internet, cables etc., of course. And my energy cost would have to fall drastically. I guess I can forget about Mining in Germany.

And How Much Did I Earn Mining Monero?

Nothing. Although I had the Pis run over several weeks they stand no chance against the around 3 giga hashes already in the network. Even though I am mining with others, the pool will only pay above 0.005 XMR, which I did’t reach yet. The xmrfast page projects that I will earn around 0.0129 XMR in a year of mining with my Pis. That’s not much…

And Now?

I guess I need bigger machines. Maybe I can find some in the cloud…