Raspberry Pi 2 B Bitcoin Full Node
Installation and Configuration (2 of 2)
This procedures installs a Bitcoin Full Node with or without the Graphical User Interface (headless). A prerequisite procedure 'Raspberry Pi Prep and Hardening' is required to be executed before this procedure is executed. A dedicated extended storage device (MicroSD or SSD) is required to support this procedure.
Extended Storage: Format, partition, auto mount & set permsNote: the size of the dedicated extended storage to support the Bitcoin application should be at least double the current size of the block-chain to provide for more for growth
Format the dedicated MicroSD or SSD Partition using Flash Friendly File System (f2fs)The f2fs file system is crucial for heavy operations. Testing has proven the ext4 file system cannot sustain the heavy load of Bitcoin Core causing corruption of block chain files as they are written. Formatting an SSD with f2fs to support the /.bitcoin folder and files has resolved this corruption issue.
Insert the MicroSD card or SSD USB Flash Drive
$ sudo apt-get install f2fs-tools
$ sudo mke2fs.f2fs -l BTC /dev/sdX
Note: Where X is the actual device letter for the dedicated MicroSD or SSD extended storage
Acquire the Storage UUID$ sudo blkid
Example Results/dev/sda1: LABEL="BTC" UUID="d59ca828-b9d7-47c9-9356-1eb807d61af5" TYPE="f2fs" PARTUUID="b11a0970-01"Edit fstab for auto mount$ sudo nano /etc/fstab
Add the following mount details using the device UUIDUUID=d59ca828-b9d7-47c9-9356-1eb807d61af5 /media//BTC auto acl,rw,user,auto,exec 0 0Note: replace the example UUID shown above with the actual UUID of the device
SSD Performance Tuning – TRIM the SSDIf using an SSD to host ~/.bitcoin, enable TRIM to run as a daily cron job to stop your SSD from slowing down after using it for a while. If you do not enable TRIM the writes may become slower due to the erasing of the deleted blocks.
List Block Devices to Check if TRIM is supported in the SSD hosting ~/.bitcoin$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 119.2G 0 disk
└─sda1 8:1 0 119.2G 0 part /media//BTC
mmcblk0 179:0 0 7.4G 0 disk
├─mmcblk0p1 179:1 0 819M 0 part
├─mmcblk0p2 179:2 0 1K 0 part
├─mmcblk0p3 179:3 0 32M 0 part
├─mmcblk0p5 179:5 0 60M 0 part /boot
└─mmcblk0p6 179:6 0 6.5G 0 part /$ sudo hdparm -I /dev/
sda | grep "TRIM supported"
* Data Set Management
TRIM supported (limit 8 blocks)
Run fstrim to confirm no errors are presented$ sudo /sbin/fstrim --all -v || true
Example Result
/: 4 MiB (4206592 bytes) trimmedIf TRIM is Supported on the SSD TRIM it daily (or weekly)$ sudo nano /etc/cron.daily/fstrim
#!/bin/sh
# trim all mounted file systems which support it
/sbin/fstrim --all || trueConfigure Cron job for Execution$ sudo chmod +x /etc/cron.daily/fstrim
SSD Performance Tuning – Disable SSD 'noatime'Configure SSD for PerformanceDisable SSD writes for last modified time: 'noatime'. Modify the fstab device entry just added previously
Note: Keep in mind that some applications (like mail) may use last modified time to function.
UUID=d59ca828-b9d7-47c9-9356-1eb807d61af5 /media/
/BTC auto acl,rw,user,auto,exec,noatime 0 0
Reboot and Confirm the Device Mounts without Error
$ sudo reboot
Configure the Pi for Bitcoin
Allocated more RAM (Bitcoin Core Only (headless))
$ sudo raspi-config
Select "8 Advanced Options" then select "Memory Split"
Change 64 to 16, save and boot
Enlarge Swap Space
A swap file allows the microSD card to be used as extra memory if needed. Raspbian defaults to a 100Mb swap file. If the the block-chain gets significantly behind, the downloading of extra blocks to catch up can exceed the built in memory and cause Bitcoin core to crash. Enlarging the swap file by a little bit protects against this possibility.
Edit the the swap file configuration
$ sudo nano /etc/dphys-swapfile
Change the default size, save and exit
CONF_SWAPSIZE=1000
Setup the Swap File
$ sudo dphys-swapfile setup
Modify (harden) the extended storage perms
Note: sets the extended storage ownership to the current Pi userid; sets perms to the Pi user and group only; Sub-folders inherit the root folder perms; Sets the Execute bit on all files with inheritance
$ sudo chmod 770 /media//BTC
$ sudo chown : /media//BTC
$ sudo chmod g+s /media//BTC
$ setfacl -d -m u::rwX,g::rwX,o::- /media//BTC
Create work and .bitcoin folders
$ mkdir /media//.bitcoin
$ mkdir /media//work
Check the folder perms. They should look like this
$ ls -an /media//BTC
Example Result
drwxrws---+ : .bitcoin
drwxrws---+ : work
Establish a Symbolic Link from the Home ~/.bitcoin folder to the BTC Storage partition
$ ln -s /media//BTC/.bitcoin /home//.bitcoin
Install Bitcoin Package Dependencies
Installing Bitcoin Core Dependencies
$ sudo apt-get update
$ sudo apt-get install build-essential autoconf git libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev -y
Installing bitcoin-Qt (GUI) Dependencies (optional if headless)
$ sudo apt-get install qt4-dev-tools libprotobuf-dev protobuf-compiler libqrencode-dev
-y
Intelligently Upgrade Packages to the Latest Version
$ sudo apt-get install dist-upgrade
Compile, Make and Install Bitcoin
Download, Compile, Make and Install Berkley DB (bitcoin-Qt only)
Note: Skip this section if installing Bitcoin Core (headless).
$ cd /media//BTC/work
$ wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
$ tar -xzvf db-4.8.30.NC.tar.gz
$ cd db-4.8.30.NC/build_unix/
$ ../dist/configure --enable-cxx
$ make -j 2
$ sudo make install
Download and Prepare Bitcoin Core
$ cd /media//BTC/work
$ git clone -b 0.11 https://github.com/bitcoin/bitcoin.git bitcoin-0.11
$ cd bitcoin-0.11
$ ./autogen.sh
Compile leveldb Library
Note: The following error was produced when the Make was performed without this step. It is not known if this error happens to others but there is a solution if it does, thanks to 'tspacepilot' on another thread: https://bitcointalk.org/index.php?topic=1107660.new#new
./leveldb/libleveldb.a: error adding symbols: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:2746: recipe for target 'test/test_bitcoin' failed
make[2]: *** [test/test_bitcoin] Error 1
make[2]: Leaving directory '/media//BTC/work/bitcoin-0.11/src'
Makefile:6459: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/media//BTC/work/bitcoin-0.11/src'
Makefile:622: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
$ cd src/leveldb
$ make clean
$ make -j 2
Compile and Make Bitcoin Core (headless)
Note: Skip this section if installing Bitcoin-Qt (GUI)
$ cd /media//BTC/work/bitcoin-0.11
$ ./configure --without-gui --disable-wallet --with-cli
$ make -j 2
$ make check
$ sudo make install
Compile and Make bitcoin-Qt (GUI) with Wallet Disabled
Compile, Make and Install bitcoin-Qt (GUI)
Note: Skip this section if installing Bitcoin Core (headless)
$ cd /media//BTC/work/bitcoin-0.11
$ ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --disable-wallet --with-gui
$ make -j 2
$ make check
$ sudo make install
Temporarily launch bitcoind to establish the ~/.bitcoin files
$ bitcoind
The process will fail the first time and this is expected. The file structure under ~/.bitcoind will be created. The following result will be presented:
Error: To use bitcoind, or the -server option to bitcoin-qt, you must set an rpcpassword in the configuration file: /home//.bitcoin/bitcoin.conf
It is recommended you use the following random password:
rpcuser=bitcoinrpc
rpcpassword=83kdib8FLxrF45nUGdTGhffRauem7nq9pXAwqS7a948W
(you do not need to remember this password)
The username and password MUST NOT be the same. If the file does not exist, create it with owner-readable-only file permissions. It is also recommended to set alertnotify so you are notified of problems; for example: alertnotify=echo %s | mail -s "Bitcoin Alert" [email protected]
Create ~/bitcoin/bitcoin.conf, paste in the recommended userid and password and save the file
$ nano ~/.bitcoin/bitcoin.conf
Execute Bitcoin Core (headless)
$ bitcoind
Confirm no errors are presented
Execute Bitcoin Core (bitcoin-qt (GUI))
$ bitcoin-qt
Confirm no errors are presented
Shutdown Bitcoin Core
Side load an Existing Bitcoin Core (.bitcoin) Instance - Direct MicroSD or SSD Transfer
Option: If an up to date Bitcoin Core block-chain is already downloaded and available on another Linux system, this procedure will directly transfer an up to date Bitcoin Core (~/.bitcoin) folder (the blockchain) from the other bitcoin instance. This process will avoid downloading the entire block-chain potentially saving days of time. At the time of the writing of this procedure, downloading the entire block-chain on a Raspberry Pi 2 B has yet to be successful producing an error about 24 hours in. This procedure mitigates this problem.
If the Symbolic Link is Identical to the Raspberry Pi Symbolic Link
Note: If the system where the current copy of the bock-chain is hosted has the exact same symbolic link and destination folder as the Raspberry Pi, remove the symbolic link before inserting the storage device to prevent data corruption. Once the extended storage is mounted back into the Raspberry Pi, reestablish the symbolic link.
$ rm /home//.bitcoin
$ ln -s /media//BTC/.bitcoin /home//.bitcoin
Exit Bitcoin on the source computer for the copy
$ bitcoind stop
Make a copy of ~/.bitcoin/bitcoin.conf
$ cp ~/.bitcoin/bitcoin.conf ~/.bitcoin/bitcoin.conf.sav
Shutdown the Pi
$ sudo halt
Remove the Extended storage from the Pi
Insert the Extended Storage into the system hosting the block-chain to copy from
Side load a copy a current Bitcoin Core folder to the MicroSD or SSD
$ cp -r ~/.bitcoin /media//BTC
Restore the saved Bitcoin configuration file
$ cp /media//BTC/.bitcoin/bitcoin.conf.sav /media//BTC/.bitcoin/bitcoin.conf
Eject the media, install it in the Raspberry Pi and boot it up
Optional Automated Sideload Script
To run this script, edit as necessary and place the file in the path to /usr/local/bin. Insert the SSD into a client Linux system that hosts bitcoind and a current copy of the blockchain. Open a Terminal window and execute 'sideload'. The blockchain will be copied to the SSD, typically within 30 minutes. Gracefully dismount the SSD and insert it into the Pi, boot it up and run bitcoind or bitcoin-qt.
#!/bin/bash
# Filename: sideload
# Description: Side loads (copies) the Bitcoin Core Blockchain to an SSD
# Supported Langauge(s): Bash 3.2.x
# Time-stamp: <2015-10-31>
# -------------------------------------------------------
# Should be run with sudo. Tested on Ubuntu 15.04
# Place script in the path: /usr/local/bin and run it from Terminal
# -------------------------------------------------------
clear
src=/media/[color=blue][/color]/Virtual\ Currency
dst=/media/[color=blue][/color]i/BTC
ps cax | grep bitcoind > /dev/null
if [ $? -eq 0 ]; then
echo Bitcoin Core is running
echo Shutdown Bitcoin Core and try again
echo Bitcoin Blockchain Sideload aborted!
else
if mount | grep -q "$dst" ; then
echo The destination SSD is Mounted...
if [ -e "$src/.bitcoin" ] && [ -d "$dst" ] ; then
echo " Source exists: $src"/.bitcoin""
echo " Destination exists: $dst"
if [ -e "$dst/.bitcoin/bitcoin.conf" ] ; then
echo Saving the destination bitcoin.conf file to: bitcoin.conf.sav
sleep 10
cp $dst"/.bitcoin/bitcoin.conf" $dst"/.bitcoin/bitcoin.conf.sav"
fi
echo Side Loading the Bitcoin Blockchain to $dst will begin in 30 seconds
x=10
while [ $x -ge 0 ]
do
clear
echo Side Loading the Bitcoin Blockchain to $dst will begin in $x seconds...
sleep 1
x=$(( $x - 1 ))
done
cp -r -v "$src"/.bitcoin"" "$dst"
chown -R [color=blue]1001:1001[/color] "$dst/.bitcoin"
if [ -e "$dst/.bitcoin/wallet.dat" ] ; then
echo Removing the source copied wallet.dat from destination for security...
rm $dst"/.bitcoin/wallet.dat"
fi
if [ -e "$dst/.bitcoin/bitcoin.conf.sav" ] ; then
echo Restoring original destination bitcoin.conf...
cp $dst"/.bitcoin/bitcoin.conf.sav" $dst"/.bitcoin/bitcoin.conf"
fi
echo Bitcoin Core Blockchain Sideload complete!
else
echo A Bitcoin Core Source or Destination folder is not accessible
echo Source: $src"/.bitcoin"
echo Destination: $dst
echo Bitcoin Blockchain Sideload aborted!
fi
else
echo Destination SSD is not mounted: $dst
echo Bitcoin Blockchain Sideload aborted!
fi
fi
Side load an Existing Bitcoin Core (.bitcoin) Instance - SSH Transfer
Option: If an up to date Bitcoin Core block-chain is already downloaded and available on another Linux system, this procedure will perform an SSH transfer over the network an up to date Bitcoin Core (~/.bitcoin) folder (the blockchain) from another bitcoin instance. This process will avoid downloading the entire block-chain potentially saving several days of time. This procedure assumes FileZilla is installed. Another SSH application or via command line are other viable options.
$ filezilla
Establish an SSH connection from the source computer hosting an up to date copy of the block-chain to the Raspberri Pi MicroSD or SSD.
Configure FileZilla to change the 'Default file exists action' to 'Overwrite if size differs or source file is newer'. Select Transfer, Default file exists action.
SFTP the entire source ~/.bitcoind folder to the Raspberry Pi MicroSD or SSD /media//BTC .bitcoin folder.
Start the Bitcoin daemon at Boot
$ sudo crontab -e
Scroll to the bottom of the file displayed and add the following line:
@reboot sudo -u /usr/bin/bitcoind -daemon -dbcache=50 -disablewallet 2>&1 >/tmp/bitcoind.cron-out
Note: The start-up may take up to 10 minutes to load the database chains
Start Bitcoin Core, confirm a synchronized block-chain (headless)
$ bitcoind
Start Bitcoin Core, confirm a synchronized block-chain (GUI)
$ bitcoin-qt
Congratulations, Bitcoin Core has successfully been installed!
Other General Bitcoin Instructions that may be helpful
Start Bitcoin-Qt (GUI)
$ bitcoin-qt
Manual Start of the Bitcoin daemon (headless)
$ bitcoind -daemon
Manual Stop of the Bitcoin daemon (headless)
$ bitcoind stop
Confirm the Node is reachable by the network
To confirm that you are seeding the bitcoin network you can either check and see if you have more than 8 connections to bitcoin core by running:
$ bitcoind getinfo
An alternative method: Go to the http://bitnodes.io website and verify the connection
Validate the bitcoind process is running
$ ps aux | grep bitcoind
Clean up After a Compile Failure
Note: If the MAKE Compile errors out, clean out the environment and try again?
$ make distclean
$ ./autogen.sh
The Bitcoind API Command List and other Commands
Reference: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list