WHAT'S NEW?
Loading...

[TUTORIAL] Compile and Run as service Monero (XMR) CPU miner for RaspberryPi 2 and 3

Monero mining is more efficient on GPU but its technically totally possible to do it on a Raspberry CPU. The Raspberry is an 32bit processor and the cpu miner is 64bit only, you have to recompile it. If you are able to acquire raspberry pi at no cost and have no power cost its possible and would be proficient. You must avoid solo mining and must use a pool to have some results.



I assume that you have Raspbian or Ubuntu 14/16 as the OS Linux distribution installed under your Raspberry Pi. Due to the lack of a GPU, with a Raspberry Pi we have to use the CPU. Let's start!

Do a SSH connection to your Raspberry Pi, become ROOT and download the needed development libraries with apt:

sudo -i


apt-get update -y



apt install autoconf libcurl4-openssl-dev libjansson-dev openssl libssl-dev gcc gawk automake git -y

git clone https://github.com/lucasjones/cpuminer-multi.git


cd cpuminer-multi

./autogen.sh





Now optimize the build for your Raspberry version
You can read more infos about this here https://gist.github.com/fm4dd/c663217935dc17f0fc73c9c81b0aa845


As for mining, you’ll need to create a Monero wallet https://mymonero.com/ and find a pool to join. Mining in a pool means you get a small part of the reward for the mining you do. In our example we use Nanopool https://xmr.nanopool.org/help

To start the mining we use the minerd command

/usr/local/bin/minerd -a cryptonight -o stratum+tcp://xmr-eu1.nanopool.org:14444 -u stratum+tcp://xmr-eu1.nanopool.org:14444 -u yourmoneroaddress.raspberry -p yourpassword -t 2 

For example

/usr/local/bin/minerd -a cryptonight -o stratum+tcp://xmr-eu1.nanopool.org:14444 -u stratum+tcp://xmr-eu1.nanopool.org:14444 -u 43x4C2pwcvWgGS9Mb9sCcY9SxFjthrk92YM3dT1VHR8QNc4kpj2MJfGQYAYKWBp2s9R9s6sheFx7DWCUezRkZrehDzenTqd.raspberry -p yourpassword -t 2

NOTE: on the command line the {key}.raspberry -p password, the .raspberry (worker name) and the password can be anything you invent yourself.
REMEMBER to replace the wallet address dot worker name with your own.
Set the t parameter equal to the number of cores your cpu has.  So if you have a 4 core cpu then it would be -t 4

In the console you will see, something like this

[2017-10-20 17:08:09] Using JSON-RPC 2.0
[2017-10-20 17:08:09] CPU Supports AES-NI: NO
[2017-10-20 17:08:09] Starting Stratum on stratum+tcp://xmr-eu1.nanopool.org:14444
[2017-10-20 17:08:09] 2 miner threads started, using 'cryptonight' algorithm.
[2017-10-20 17:08:09] Pool set diff to 120001
[2017-10-20 17:08:09] Stratum detected new block
[2017-10-20 17:08:10] thread 0: 26925360 hashes, 0.00 H/s
[2017-10-20 17:08:10] thread 1: 26925368 hashes, 0.00 H/s
.....
[2017-10-20 19:29:00] thread 1: 29985080 hashes, 0.00 H/s
[2017-10-20 19:29:35] thread 1: 29985080 hashes, 0.00 H/s
[2017-10-20 19:29:36] accepted: 1/1 (100.00%), 3.23 H/s at diff 120001 (yay!!!)

It works fine but the only issue is its only shows Hash rate if the share is accepted. Note that with some pools, your Hash Rate will be reported as zero for most of the time, until you suddenly submit a 'share' to the pool from your mining efforts. You will temporarily see your Hash Rate reported, after which it will return to zero. This is normal for some pools, and you do not need to worry that something is not working correctly. As long as after a while you see the "total hashes submitted" figure increase, then your mining setup is working. 
If you want limit CPU usage (75%) you install cpulimit

apt-get install cpulimit

and use

cpulimit -e minerd -l 75 -b 

To keep the miner running at all times, we should set up a daemon to run in the background. In Raspian you must install systemd using:

apt-get install systemd

Systemd, if being used, is the first processes executed in user space in the Linux startup process. If init was used then the first process would have been init. The first process will be the root of the user space’s process tree.

Let’s move to the system and make a service file:
cd /lib/systemd/system/

nano miner.service
and copy in

[Unit]
Description=monero miner daemon
[Service]
ExecStart=<put your minerd command here, example /usr/local/bin/minerd etc etc> 
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target
and Ctrl + X to save it and then reload it with:

systemctl daemon-reload
systemctl enable miner.service
systemctl start miner.service
If the service (minerd) dies, don't worry, Linux will start it again automatically. BTW, the minerd service will start up automatically on every boot.

To View the stdout/stderr of the systemd service

Just use the journalctl command, as in:
journalctl -u miner.service
Or, to see only log messages for the current boot:
journalctl -u miner.service -b

5 comments: Leave Your Comments

  1. Hi, Thanks for sharing. Do you mind sharing what is the hash rate?

    ReplyDelete
  2. In my example with the optimized compile instructions and using raspberry 2 and only 2 CPU cores at 70% i have 3,4 H/s

    ReplyDelete
  3. Hi and thanks for sharing.
    I have a issue, after running the command./minerd -a cryptonight..... my raspberry reboots

    ReplyDelete
  4. For the Strech version (and RBP3) :

    ./configure --with-crypto --with-curl CFLAGS="-Ofast -mtune=cortex-a53 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ffast-math" CXXFLAGS="-Ofast -mtune=cortex-a53 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ffast-math"

    ReplyDelete