Ever since the emergence of Bitcoin in 2008, people worldwide have been closely following the developments in the world of cryptocurrency. As Bitcoin’s reputation soared, going from being worth just two pizzas to a staggering $60,000 per coin, its journey has been nothing short of astonishing. Currently, there are two widely recognized ways to acquire Bitcoin: Trading and Mining.
Bitcoin mining, however, is a complex and energy-intensive process that demands specialized hardware and substantial investments. For enthusiasts and DIYers looking for a cost-effective entry into cryptocurrency mining, there’s a pathway – Raspberry Pi. The purpose of this article is to guide you through the process of mining Bitcoin using a Raspberry Pi, offering an accessible way to start mining. It’s essential to note that this is not a get-rich-quick scheme but rather a project for hobbyists.

Configuring Raspberry Pi
Basic Configuration
- First, go to the official Raspberry Pi website and select and download the operating system image that matches your Raspberry Pi model.
- Once the operating system is installed, the next steps include configuring your Raspberry Pi, which involves connecting hardware, booting up the Raspberry Pi, and completing the initial setup.
- After the configuration is complete, you can interact with it through remote connections such as SSH, VNC, and SCP.
Software Updates
To ensure that your system remains up-to-date with the latest security patches and application updates while running securely on the internet, it’s important to regularly execute the following two commands:
$ sudo apt update
$ sudo apt full-upgrade
Install all necessary packages
$ sudo apt install htop git curl bash-completion jq qrencode dphys-swapfile hdparm
Create Blockchain Nodes
Create New User
Create the “admin” user and add it to the “sudo” group:
$ sudo adduser admin
$ sudo usermod -aG sudo admin
The program for Bitcoin mining needs to run in the background. To ensure security, create a “bitcoin” user without system administration privileges:
$ sudo adduser bitcoin
The first command adds the “admin” user to the “bitcoin” group. The second command assumes that the Bitcoin configuration files are stored in /path/to/config/files and changes the ownership of this directory to the “bitcoin” user and group to ensure read-only permissions:
$ sudo usermod -aG bitcoin admin
$ sudo chown -R bitcoin:bitcoin /path/to/config/files
Restart your computer to ensure all changes take effect:
$ sudo rebot
Create a Bitcoin Data Directory
To set user access rights, change the ownership of the /mnt/ext/ directory and all its files and subdirectories to the “bitcoin” user and the “bitcoin” group. Now, this directory is owned by the “bitcoin” user:
$ sudo chown -R bitcoin:bitcoin /mnt/ext/
Switch to the “bitcoin” user, navigate to the external drive, and create the Raspberry Pi Bitcoin node directory:
$ sudo su - bitcoin
$ cd /mnt/ext
$ mkdir bitcoin
$ ls -la
> total 28
> drwxr-xr-x 4 bitcoin bitcoin 4096 Dec 12 17:43 .
> drwxr-xr-x 4 root root 4096 Dec 12 17:38 ..
> drwxr-xr-x 2 bitcoin bitcoin 4096 Dec 12 17:43 bitcoin
> drwx------ 2 bitcoin bitcoin 16384 Dec 12 17:30 lost+found
Create a test file named “test.file” in the new “bitcoin” directory and then delete it:
$ touch bitcoin/test.file
$ rm bitcoin/test.file
Exit the “bitcoin” user session:
$ exit
Install Bitcoin Core
Log in as “admin” and navigate to the “tmp” directory. This is a temporary directory present in Linux systems, used for storing temporary files and directories. It is typically configured to clear its contents upon reboot to ensure that temporary files do not permanently occupy disk space:
cd /tmp
Go to the official website to download the latest Bitcoin Core:
# download Bitcoin Core binary
$ wget http://bitcoincore.org/bin/bitcoin-core-0.20.1/bitcoin-0.20.1-arm-linux-gnueabihf.tar.gz
$ wget https://bitcoincore.org/bin/bitcoin-core-0.20.1/SHA256SUMS.asc
$ wget https://bitcoin.org/laanwj-releases.asc
# check that the reference checksum matches the real checksum
# (ignore the "lines are improperly formatted" warning)
$ sha256sum --check SHA256SUMS.asc --ignore-missing
> bitcoin-0.20.1-arm-linux-gnueabihf.tar.gz: OK
# import the public key of Wladimir van der Laan, verify the signed checksum file
# and check the fingerprint again in case of malicious keys
$ gpg --import ./laanwj-releases.asc
$ gpg --refresh-keys
$ gpg --verify SHA256SUMS.asc
> gpg: Good signature from "Wladimir J. van der Laan ..."
> Primary key fingerprint: 01EA 5486 DE18 A882 D4C2 6845 90C8 019E 36C2 E964
Unpack and install the Bitcoin Core binary files and verify the installation’s success. After the installation is complete, you can launch the Bitcoin Core node using the “bitcoind” command and verify its version with “bitcoind –version.
$ tar -xvf bitcoin-0.20.1-arm-linux-gnueabihf.tar.gz
$ sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-0.20.1/bin/*
$ bitcoind --version
> Bitcoin Core version v0.20.1
Set Data Directory
Switch to the “bitcoin” user and create a symbolic link. When you view files in the directory located at “/home/bitcoin/.bitcoin,” you are actually seeing the files and content from the directory “/mnt/ext/bitcoin” on the external drive. This configuration allows you to store Bitcoin node data on the external drive instead of the Raspberry Pi’s internal storage, saving space and providing greater storage capacity.
$ sudo su - bitcoin
$ ln -s /mnt/ext/bitcoin /home/bitcoin/.bitcoin
Navigate to your home directory and check for symbolic links.
$ ls -la
Configuration File
Create the configuration file for the Bitcoin Core node and open it using the nano text editor:
# RaspiBolt: bitcoind configuration
# /mnt/ext/bitcoin/bitcoin.conf
# Bitcoin daemon
server=1
txindex=1
# Network
listen=1
listenonion=1
proxy=127.0.0.1:9050
bind=127.0.0.1
# Connections
rpcuser=raspibolt # Your Raspberry Pi's root username
rpcpassword=PASSWORD_[B] # Root password
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
# Raspberry Pi optimizations
maxconnections=40
maxuploadtarget=5000
# Initial block download optimizations
dbcache=2000
blocksonly=1
Auto-Start at Boot
Use systemd to configure the service unit file for the Bitcoin process. This is a standard tool in Linux systems for managing system services, allowing you to ensure that the Bitcoin process runs automatically in the background, even without a user logged in.
$ sudo nano /etc/systemd/system/bitcoind.service
# RaspiBolt: systemd unit for bitcoind
#/etc/systemd/system/bitcoind.service
[Unit]
Description=Bitcoin daemon
After=network.target
[Service]
# Service execution
###################
ExecStart=/usr/local/bin/bitcoind-daemon\ -pid=/run/bitcoind/bitcoind.pid\ -conf=/mnt/ext/bitcoin/bitcoin.conf\ -datadir=/mnt/ext/bitcoin
# Process management
####################
Type=forking
PIDFile=/run/bitcoind/bitcoind.pid
Restart=on-failure
TimeoutSec=300
RestartSec=30
# Directory creation and permissions
#####################################
Run as bitcoin:bitcoin
User=bitcoin
Group=bitcoin
# /run/bitcoind
RuntimeDirectory=bitcoind
RuntimeDirectoryMode=0710
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Deny access to /home, /root and /run/user
ProtectHome=true
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
Create a symbolic link on the Linux system to link the Bitcoin data directory to the “.bitcoin” folder in the home directory of the user “admin.”
$ ln -s /mnt/ext/bitcoin/ /home/admin/.bitcoin
Restart the Raspberry Pi used for mining Bitcoin
$ sudo reboot
Connect External Drive
Before connecting an external drive to the Raspberry Pi, first clear the kernel message buffer, then continuously monitor new kernel messages to ensure that you can capture any new messages related to the connection and recognition of the external drive, allowing you to stay informed about the status of the external drive’s connection.
$ sudo dmesg -C
$ sudo dmesg -w
It is recommended to physically connect the external drive to the Raspberry Pi’s USB3 port, which is usually the blue-colored port, to ensure faster data transfer speeds. Use a high-quality USB cable that comes with the external drive to ensure a stable connection.
Once the external drive is successfully connected to the Raspberry Pi, the Linux system will automatically detect and recognize the drive. You can view detailed information about this connection by using the “dmesg” command to check kernel messages. If you want to stop continuous monitoring of kernel messages, press the Ctrl and C keys together to halt the execution of “dmesg.”
$ lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE,LABEL,MODEL
> NAME MOUNTPOINT UUID FSTYPE SIZE LABEL MODEL
> sda 447.1G SATA_III_SSD
> └─sda1 9ec0b784-d448-4757-a3b2-8abd57c544f3 ext4 447.1G
> mmcblk0 14.9G
> ├─mmcblk0p1 /boot 5203-DB74 vfat 256M boot
> └─mmcblk0p2 / 2ab3f8e1-7dc6-43f5-b0db-dd5759d51d4e ext4 14.6G rootfs
Format External Drive
Format a specific partition on the external drive using the Ext4 file system. Replace “[NAME]” with the actual partition name.
$ sudo mkfs.ext4 /dev/[NAME]
To facilitate the recognition and selection of the correct device and partition for subsequent operations, list the block device information in the system, including device name, mount point, UUID, file system type, device capacity, device label, and device model, etc.
$ lsblk -o NAME,MOUNTPOINT,UUID,FSTYPE,SIZE,LABEL,MODEL
Added a configuration line in the /etc/fstab file to specify detailed information about the device or partition to be mounted, ensuring it’s automatically mounted during system startup.
$ sudo nano /etc/fstab
UUID=123456/mnt/extext4rw,nosuid,dev,noexec,noatime,nodiratime,auto,nouser,async,nofail 0 2
Create a new directory in the system for users to mount external devices to, making the content of the external device available within this directory. Before mounting, ensure that the directory’s ownership and permissions are set correctly to grant users access to the data within the mount point.
$ sudo mkdir /mnt/ext
Mount all the drives configured in the /etc/fstab file and check the mounted file systems. If the mounting is successful, you should be able to see relevant file system information in /mnt/ext.
$ sudo mount -a
$ df -h /mnt/ext
> Filesystem Size Used Avail Use% Mounted on
> /dev/sda1 440G 73M 417G 1% /mnt/ext
REGTEST Test Network
Start REGTEST
y@ubuntu:~$ bitcoind -regtest -txindex -daemon
Bitcoin server starting



illustrate:
- regtest: This is used to start Bitcoin in the REGTEST testing network. It’s an isolated Bitcoin test network separate from the main network and testnet. The key distinction between these networks lies in their genesis block, which means their transaction and blockchain data are separate.
- txindex: This flag instructs the Bitcoin node to index all transactions. By default, Bitcoin nodes only index transactions related to wallet addresses for performance reasons. If you need broader access to transaction data, you can use the -txindex parameter to enable full transaction indexing.
- daemon: This is particularly useful when setting up a Bitcoin node as a long-running service. It tells the Bitcoin node to run in the background, without displaying output in the foreground, thus preventing the node process from occupying your terminal session.
Alternatively, you can configure Bitcoin by editing its configuration file.
regtest=1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
rpcuser=test
rpcpassword=test
server=1
daemon=1
txindex=1
As shown in the diagram below, after successfully launching the Bitcoin REGTEST test network, the system will automatically create a dedicated folder for the REGTEST network in the /home/bitcoin/.bitcoin directory:



Use of basic commands
Mining Bitcoin using Raspberry Pi:
bitcoin-cli -regtest generate 500
View block information:
y@ubuntu:~$ bitcoin-cli -regtest getblockchaininfo
{
"chain": "regtest",
"blocks": 500,
"headers": 500,
"bestblockhash": "0139f2493a3d10dec105df453510b7104e8155e9a536558b2760d2563c5c0f2b",
"difficulty": 4.656542373906925e-10,
"mediantime": 1531385979,
"verificationprogress": 1,
"initialblockdownload": false,
"chainwork": "00000000000000000000000000000000000000000000000000000000000003ea",
"size_on_disk": 156650,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "active",
"startTime": 0,
"timeout": 9223372036854775807,
"since": 432
},
"segwit": {
"status": "active",
"startTime": -1,
"timeout": 9223372036854775807,
"since": 0
}
},
"warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
}
View mining results:
y@ubuntu:~$ bitcoin-cli -regtest getbalance
12462.50000000
View the address of the wallet account:
y@ubuntu:~$ bitcoin-cli -regtest getaccountaddress
error code: -32
error message:
getaccountaddress is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.
Assign new address:
y@ubuntu:~$ bitcoin-cli -regtest getnewaddress
2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX
To transfer money to a new address:
y@ubuntu:~$ bitcoin-cli -regtest sendtoaddress 2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX 100
053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961
View the details of this transaction:
y@ubuntu:~$ bitcoin-cli -regtest listreceivedbyaddress
[
{
"address": "2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX",
"account": "",
"amount": 100.00000000,
"confirmations": 1,
"label": "",
"txids": [
"053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961"
]
}
]
Generate a block so that the transaction is confirmed:
y@ubuntu:~$ bitcoin-cli -regtest generate 1
[
"223012d674962e92a73b76f2e37277ab723935a0a8d0d68b5d6211997ecb2d06"
]
View the Bitcoins received:
y@ubuntu:~$ bitcoin-cli -regtest listreceivedbyaddress
[
{
"address": "2MvZH9rH1cQN6NSR6sY1Xkdku2e4hqU9aqX",
"account": "",
"amount": 100.00000000,
"confirmations": 1,
"label": "",
"txids": [
"053753fb919378974b864c8baec3bdd172ad75dd20676b137575be60630fa961"
]
}
]
You Might Be Interested


When you need to connect to your Raspberry Pi, you don’t necessarily have to rely on a computer; you can also achieve this using a


This article provides a comprehensive guide on mining Bitcoin using a Raspberry Pi, offering an accessible entry point for cryptocurrency enthusiasts. It covers essential steps,


The article provides a detailed overview of essential files in the Raspberry Pi file system, covering their functions and significance in system operation. It explores


This Raspberry Pi project successfully integrates a servo pan-tilt module for remote control, allowing precise movement and positioning. The servo motor’s principles, Python control logic,


This article details the creation of a Raspberry Pi surveillance system for beginners. It covers webcam connection, Motion software configuration, and the setup of an


This tutorial streamlines Raspberry Pi’s auto-connect feature by editing the wpa_supplicant.conf file, allowing users to specify preferred Wi-Fi networks. By customizing network configurations, it ensures


This tutorial provides a clear and detailed guide on installing the Mosquitto MQTT broker on a Raspberry Pi. It covers the significance of MQTT and


This guide provides a comprehensive overview of how to use SSH (Secure Shell) for remote management of a Raspberry Pi. It covers enabling SSH via