Overview
This guide walks you through setting up a Raspberry Pi as a Monero (XMR) CPU miner using XMRig, a high-performance, open-source RandomX miner. Monero uses the RandomX proof-of-work algorithm, designed specifically for CPU mining.
What You'll Learn
Flash OS
Install Raspberry Pi OS Lite (64-bit) and configure initial settings.
Build XMRig
Compile XMRig from source with all required dependencies.
Wallet Setup
Create a Monero wallet to receive mining rewards.
Pool Mining
Connect to a mining pool and start earning XMR.
Optimization
Tune CPU performance and configure automatic startup.
Overclocking
Optional advanced tuning for improved hashrate.
Requirements
Gather the following hardware and software before starting.
Required Hardware
- Raspberry Pi 4 (4GB or 8GB recommended) or Pi 5
- MicroSD card (16GB+ Class 10/UHS-1)
- Official Raspberry Pi power supply (3A USB-C)
- Ethernet cable or reliable WiFi
- Computer for initial setup
Recommended Hardware
- Heatsink and active cooling fan
- Case with ventilation
- External SSD (optional, extends SD card life)
Section 1 — Install Raspberry Pi Imager
Download and use the official Raspberry Pi Imager to flash the operating system.
Download Raspberry Pi Imager
Get the official imaging tool from the Raspberry Pi website.
Download Raspberry Pi ImagerInsert MicroSD Card
Insert your microSD card into your computer's card reader.
Configure Image Settings
Open Raspberry Pi Imager and configure the following:
- Device: Raspberry Pi 4 (or your model)
- Operating System: Raspberry Pi OS Lite (64-bit)
- Storage: Select your microSD card
Configure Advanced Options
Click the gear icon or "Edit Settings" to configure:
- Enable SSH: Use password authentication
- Set hostname: e.g.,
miner - Set username/password: Create secure credentials
- Configure WiFi: Enter SSID and password (if not using Ethernet)
- Set locale: Configure timezone and keyboard layout
Flash the SD Card
Click "Write" and wait for the process to complete. Safely eject the card when finished.
Section 2 — First Boot and System Update
Boot your Raspberry Pi and perform initial system updates.
Connect via SSH
Insert the SD card into your Pi, connect power, and SSH into the device:
ssh username@raspberrypi.local
Replace username with the username you configured. If you changed the hostname, use that instead of raspberrypi.
Update System Packages
Run the following commands to update all packages:
sudo apt update
sudo apt upgrade -y
sudo apt full-upgrade -y
sudo reboot
Clean Up After Reboot
After the system reboots, reconnect via SSH and remove unused packages:
sudo apt autoremove -y
Section 3 — Install Required Dependencies
Install the build tools and development libraries needed to compile XMRig.
Install Build Tools
sudo apt install -y git cmake build-essential
Install Development Libraries
Install the libraries required for RandomX-based CPU mining:
sudo apt install -y \
libssl-dev \
libuv1-dev \
libhwloc-dev \
libmicrohttpd-dev \
libjansson-dev \
libgmp-dev \
libunbound-dev \
libsodium-dev \
pkg-config
Dependency Reference
Build Tools
build-essential— GCC, make, core build toolscmake— Build configuration systemgit— Source code version control
Libraries
libssl-dev— Cryptography (OpenSSL)libuv1-dev— Async networkinglibhwloc-dev— CPU topology detectionlibjansson-dev— JSON parsing
Section 4 — Clone and Build Mining Software
Download and compile XMRig, a high-performance open-source Monero CPU miner.
Clone XMRig Repository
git clone https://github.com/xmrig/xmrig.git
cd xmrig
Create Build Directory and Compile
mkdir build
cd build
cmake ..
make -j$(nproc)
Build Process Explanation
mkdir build
Creates a separate directory for build artifacts, keeping the source tree clean.
cmake ..
Generates makefiles based on the project configuration. The .. points to the parent directory containing CMakeLists.txt.
make -j$(nproc)
Compiles the source code using all available CPU cores. $(nproc) returns the number of processing units.
Build Time
Compilation takes approximately 10-20 minutes on a Raspberry Pi 4, depending on cooling and clock speed.
xmrig executable in the build directory.
Section 5 — Monero Wallet Setup
Create a Monero wallet to receive your mining rewards.
Download Official Wallet
Download the official Monero GUI or CLI wallet from the Monero website.
Download Monero WalletCreate New Wallet
Open the wallet application and select "Create new wallet". Follow the on-screen instructions to generate your wallet.
Backup Seed Phrase
Write down the 25-word mnemonic seed phrase and store it securely offline. This is your wallet backup — never share it or store it digitally.
Copy Wallet Address
Copy your public wallet address (starts with 4 or 8). You'll need this to configure the mining software.
Section 6 — Configure Mining Software
Configure XMRig with your wallet address and mining pool settings.
Configuration Requirements
- Wallet address — Your Monero public address
- Mining pool URL — Pool server address and port
- Worker name — Identifier for this miner
- CPU thread configuration — Number of threads to use
Create Configuration File
Create a config.json file in the build directory:
nano ~/xmrig/build/config.json
Example Configuration
Add the following configuration (replace placeholders with your values):
{
"autosave": true,
"cpu": true,
"opencl": false,
"cuda": false,
"pools": [
{
"url": "pool.example.com:3333",
"user": "YOUR_WALLET_ADDRESS_HERE",
"pass": "worker1",
"coin": "monero",
"algo": "rx/0",
"keepalive": true,
"tls": false
}
],
"print-time": 60,
"health-print-time": 60,
"retries": 5,
"retry-pause": 5
}
Configuration Fields
url
Mining pool address and port. Choose a pool close to your location for lower latency.
user
Your Monero wallet address. Some pools also accept wallet.workername format.
pass
Worker password/identifier. Often used as worker name or can be left as x.
algo
rx/0 is RandomX, the current Monero mining algorithm.
Section 7 — Start Mining
Launch XMRig in a screen session for interactive monitoring. Using screen allows you to detach from the mining session while it continues running in the background.
Install Screen
If screen is not already installed:
sudo apt install -y screen
Start XMRig in a Screen Session
Navigate to the build directory and start XMRig in a detached screen session:
cd ~/xmrig/build
screen -dmS xmrig ./xmrig
This starts XMRig in a detached screen session named xmrig. The miner runs in the background and you can safely disconnect from SSH.
Attach to the Screen Session
To view the live mining output, attach to the screen session:
screen -r xmrig
Detach from the Screen Session
To detach and leave XMRig running in the background, press:
Ctrl+A, then D
This returns you to the normal shell while XMRig continues mining.
Screen Commands Reference
screen -dmS xmrig ./xmrig
Start XMRig in a new detached screen session named "xmrig".
screen -r xmrig
Reattach to the running screen session to view live output.
Ctrl+A, D
Detach from the screen session (leaves miner running).
screen -ls
List all active screen sessions.
Expected Console Output
When XMRig starts successfully, you'll see output similar to:
* ABOUT XMRig/6.x.x
* LIBS libuv/1.x.x OpenSSL/x.x.x hwloc/2.x.x
* HUGE PAGES supported
* CPU ARM Cortex-A72 (4) 64-bit
* MEMORY 3.7/7.8 GB
* DONATE 1%
* POOL #1 pool.example.com:3333
* COMMANDS hashrate, pause, resume, results, connection
[2026-02-06 12:00:00.000] net new job from pool.example.com
[2026-02-06 12:00:01.000] cpu accepted (1/0) diff 10000 (62 ms)
[2026-02-06 12:01:00.000] miner speed 10s/60s/15m 85.2 85.0 n/a H/s
Understanding the Output
Hashrate
Shows mining speed in hashes per second (H/s). The three values are 10-second, 60-second, and 15-minute averages.
Accepted Shares
accepted (1/0) shows accepted vs rejected shares. High rejection rates indicate connection or configuration issues.
Difficulty
Pool-assigned difficulty. Higher difficulty means fewer but larger shares.
Response Time
Latency to the pool server in milliseconds. Lower is better.
Section 8 — Optional Optimization
Tune your miner for improved performance and stability.
Adjust Thread Count
Edit config.json to specify the number of mining threads. For a Raspberry Pi 4 with 4 cores, start with 3-4 threads:
"cpu": {
"enabled": true,
"huge-pages": true,
"max-threads-hint": 100
}
Monitor CPU Temperature
vcgencmd measure_temp
Set CPU Governor to Performance
For maximum hashrate, set the CPU frequency scaling governor to performance mode:
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Cooling Recommendations
Heatsink
Attach a heatsink to the CPU for passive cooling.
Active Fan
Use an active cooling fan to maintain lower temperatures under load.
Ventilated Case
Use a case with ventilation or an open-air design.
Section 9 — Autostart on Boot (systemd + screen)
Configure XMRig to start automatically in a screen session when the Raspberry Pi boots. This method combines the power of systemd for auto-start with screen for interactive monitoring.
- Full interactive console output via
screen -r xmrig - Automatic start on boot via systemd
- Persistent service that survives reboots
- Auto-restart if XMRig crashes
Step 1: Create the Start Script
Create a script in your home directory that manages the screen session:
nano ~/start-xmrig.sh
Add the following content:
#!/bin/bash
cd /home/pi/xmrig/build
# Kill any old xmrig screen
screen -S xmrig -X quit 2>/dev/null
# Start in detached screen
screen -dmS xmrig bash -c './xmrig; exec bash'
# Keep script alive so systemd service stays active
while true; do sleep 3600; done
pi, replace /home/pi with /home/<your-username> in both the script and the service file.
Make the script executable:
chmod +x ~/start-xmrig.sh
Step 2: Create the systemd Service
Create a new systemd service file:
sudo nano /etc/systemd/system/xmrig-screen.service
Add the following configuration:
[Unit]
Description=XMRig Monero Miner (Screen Session)
After=network.target
[Service]
User=pi
WorkingDirectory=/home/pi
ExecStart=/home/pi/start-xmrig.sh
Restart=always
RestartSec=10
StandardOutput=inherit
StandardError=inherit
[Install]
WantedBy=multi-user.target
Step 3: Enable and Start the Service
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable to start at boot
sudo systemctl enable xmrig-screen.service
# Start the service immediately
sudo systemctl start xmrig-screen.service
# Check that it's running
sudo systemctl status xmrig-screen.service
Interacting with the Miner
Once the service is running, you can attach to the screen session to view live mining output:
# Attach to the mining session
screen -r xmrig
# Detach (leave running): Press Ctrl+A, then D
Cleaning Up Dead Screens
If you have stale or dead screen sessions, clean them up with:
screen -wipe
Service Management Commands
systemctl status xmrig-screen
Check if the service is running and view recent log output.
systemctl restart xmrig-screen
Restart the mining service (kills and restarts XMRig).
systemctl stop xmrig-screen
Stop the mining service.
journalctl -u xmrig-screen -f
View live service logs from systemd.
How It Works
Screen Session
XMRig runs inside a screen session, providing full interactive console access. You can attach/detach at any time without interrupting mining.
systemd Management
systemd keeps the start script running. The infinite loop ensures the service stays "active" so systemd doesn't think it has stopped.
Auto-Restart
Restart=always ensures the entire setup restarts if XMRig crashes or the script exits unexpectedly.
Boot Persistence
The service is enabled at boot, so mining automatically resumes after power outages or reboots.
Optional: Advanced Performance Tuning (Overclocking)
Overclocking can improve CPU and memory performance but increases heat and power consumption.
Edit Boot Configuration
sudo nano /boot/config.txt
CPU Overclocking Settings
Add or modify the following lines (example for Raspberry Pi 4):
# CPU frequency (example for Pi 4)
arm_freq=2000
# Increase core frequency
core_freq=600
# Enable overvoltage (use conservative values)
over_voltage=6
Memory Tuning (Optional)
# Increase SDRAM frequency
sdram_freq=550
Apply Changes
sudo reboot
Monitor Temperature
Install monitoring tools:
sudo apt install -y lm-sensors
Check temperature:
vcgencmd measure_temp
Overclocking Guidelines
Temperature
Keep temperatures under ~80°C for stability. Throttling begins at 85°C.
Cooling
Active cooling (fan + heatsink) is essential for overclocked operation.
Power Supply
Use the official 3A power supply to ensure stable power delivery.
Silicon Lottery
Stability varies by individual chip. Test thoroughly before relying on overclocked settings.
Reverting Changes
To revert to default settings, remove or comment out the added lines from /boot/config.txt and reboot:
sudo nano /boot/config.txt
# Comment out or remove overclocking lines
sudo reboot