Raspnode & Tutorials & Technicalities - Compile Bitcoin Core on Raspberry Pi and forms part of the Bitcoin Fullnode Project.
- 8Gb Micro SD Card (preferably Class 10 or above with wear protection)
- Download Raspian Jessie https://www.raspberrypi.org/downloads/raspbian / or your favourite distro
The new version of Raspbian Jessie is out: 2016-02-09-raspbian-jessie.img, at the time of writing includes bundled software which takes up extra room on the disk. To remove these packages see instructions on Strip Down Raspian.
Note
At the time of writing 2016-02-26-raspbian-jessie.img released for the latest Raspberry Pi 3 will throw up errors when you reach the Autogen step before compiling Bitcoin. It is recommended that you download the latest version of Raspbian 2016-03-18-raspbian-jessie.img to resolve this issue when compiling for the Raspberry Pi 3.
See Instalation Instructions on the Raspberry Pi website that includes all operating systems.
Insert Micro SD Card & Open up Terminal
List disks:
diskutil list
Be carefull to select the correct disk OR YOU COULD LOSE DATA! If your SD Card is /dev/disk2 for example then:
diskutil umountDisk /dev/disk2
sudo dd if=2016-02-09-raspbian-jessie.img of=/dev/disk2 bs=4096 conv=noerror,sync
This will take some time.
Take the micro SD out of the adapter and over to the Raspberry Pi 2 and connect it up to monitor and screen.
On first boot it will load up the raspi-config console. If this is not your first time then load it using the commmand:
sudo raspi-config
Select:
- Expand File System - click OK
- Enable SSH
- Change hostname to eg "fullnode" (without quotes)
- Reboot either via the config
If you want you can reboot manually like so:
sudo reboot
sudo apt-get update
sudo apt-get upgrade -y
The -y flag tells the OS to answer "yes" to any prompts warning you of extra disk space required, we use this for convenience but it is not essential.
sudo apt-get install build-essential autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev libtool libevent-dev -y
sudo apt-get install libqt4-dev qt4-dev-tools libprotobuf-dev protobuf-compiler libqrencode-dev -y
Make sure you have at least 2Gb free on the card before starting and increase your swap file like so:
sudo nano /etc/dphys-swapfile
Then enter
CONF_SWAPSIZE=1024
Then hit control+X and click Y to save and Enter. Then type the command:
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
mkdir ~/bin
cd ~/bin
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/
Note the -j4 flag installs using all four cores on the Raspberry Pi
../dist/configure --enable-cxx
make -j4
sudo make install
cd ~/bin
git clone -b v0.13.2 https://github.com/bitcoin/bitcoin
cd bitcoin/
./autogen.sh
./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default --with-gui=qt4
In this next step we are going to build the executable files using the Make tool. The -j2
flag tells the computer to use two of the CPU cores. You might find that you get errors, if you do simply drop the flag and use make
on its own instead.
make -j2
sudo make install
Usually the errors will not be apparent until this last step. In addition to the -j2
flag you may also be getting errors if:
- The memory card does not have enough space
- You did not set the swap file size high enough
- You did not install all of the dependencies near the start of the tutorial
You can delete ~/bin folder after the compiling to save space with:
sudo rm -r -f /home/pi/bin
The -r
means recursive (deletes all subfolders) and the -f
means Force delete without prompting.
Remember earlier we increased the swap file size. Some people choose to disable Swapfile altogether by setting CONF_SWAPSIZE=0
however we are going to do it slightly differently see Issue 20.
sudo chmod -x /etc/init.d/dphys-swapfile
sudo swapoff -a
sudo rm /var/swap
Note to re-enable just reverse the process:
sudo chmod +x /etc/init.d/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
Once Bitcoin is installed you will need to create a .bitcoin folder inside of your home directory. This is really only necessary if you want to use Bitcoin Command Line Interface (CLI) and run it headlessly. If you do you need to make sure you have enough space. At the time of writing the Bitcoin Blockchain is around 66Gb which means realistically you will need MicroSD or an external Drive that is at least 128Gb.
mkdir /home/pi/.bitcoin/
If you have an internal MicroSD drive large enough for the whole blockchain you can skip to the section on creating the bitcoin.conf file. Assuming you will be using external media then do the following:
Display information about block devices attached to the Raspberry Pi...
sudo blkid
Make a note of the drive name eg /dev/sda1
. Then format the drive you wish to use if this hasn't been done already. FAT32 is recommended for compatibility with other devices. Skip this step if the device was formatted on your computer.
sudo mkfs.vfat /dev/sda1
Then do the blkid command again:
sudo blkid
Make a note of the new UUID number eg. 8736-1215
sudo nano /etc/fstab
Enter the following:
UUID=8736-1215 /home/pi/.bitcoin vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0 0
Replacing the "8736-1215" with whatever your drive actually is. Then reboot and the external drive will automatically mount to /home/pi/.bitcoin.
sudo reboot
Next let's go in to our Bitcoin data directory:
cd /home/pi/.bitcoin
Using nano text editor we will create the Bitcoin Configuration file bitcoin.conf
nano bitcoin.conf
This will open a blank text editor. Enter the following text as a minimum:
listen=1
server=1
dbcache=50
daemon=1
testnet=0
Press cntr+X
followed by Y
then Enter
to save changes and return back to the command line.
To start Bitcoin Daemon type:
bitcoind -daemon
To check the status run this command:
bitcoin-cli getinfo
While Bitcoin is starting up you will get an error like this one:
error code: -28
error message:
Verifying blocks...
This is normal, be patient and use the up arrow on the keyboard to toggle through the previous used commands. Keep re-entering ```bitcoin-cli getinfo`` and eventually you will see something like this:
{
"version": 120000,
"protocolversion": 70012,
"walletversion": 60000,
"balance": 0.00000000,
"blocks": 96,
"timeoffset": 0,
"connections": 4,
"proxy": "",
"difficulty": 1,
"testnet": false,
"keypoololdest": 1455980870,
"keypoolsize": 101,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"errors": ""
}
Congratulations you are now running Bitcoin Core 0.12!
To get Bitcoin QT running you will first need to make sure that Bitcoin Daemon has been stopped using this command:
bitcoin-cli stop
You will need to load up the Desktop on the Pi with the following command which can only be done if it is attached to a monitor and keyboard directly, this won't work using SSH.
startx
After the desktop has loaded open up a terminal window from the menu bar (it's the little black box icon) and type:
bitcoin-qt
You will now see the Graphical User Interface load up. Remember you cannot run both Bitcoind and Bitcoin QT at the same time.