Build Your Own Raspberry Pi Bitcoin Full Node [Bitcoin Core]
Click Here for building Bitcoin XT
LAST UPDATED OCTOBER 8, 2016
Disclaimer: I cannot guarantee these steps will work 100% of the time. Like all DIY tutorials they make assumptions about things and are subject to external libraries and software being updated or changed. I periodically test and update these steps for changes or additions, but I can't guarantee that some troubleshooting won't be needed to get your node up and running.
PRELIMINARIES
This tutorial is to install Bitcoin Core v0.13.0 (or possibly higher) on a Raspberry Pi 2 or 3. Options are given to install the GUI and wallet or not. We'll store the blockchain on an external USB flash drive (or hard drive), as that is more modular and better than storing it on a large microSD card with the OS.
If you run into any Raspberry Pi problems while going through these steps, the Raspberry Pi Docs are a good source for help:
http://www.raspberrypi.org/documentation/
FULL STEPS
- Assembling the Raspberry Pi
- Download and Install Raspbian on the microSD card
- Configuring Raspbian
- Configuring the USB drive and setting to automount on boot
- Enlarge Swap File
- Configure networking on the Raspberry Pi
- Downloading and installing Bitcoin Core and dependencies
- Configure and run bitcoin
- Configure home network to sync up with the bitcoin network
- Confirm your node is reachable by the network
EQUIPMENT FOR NODE
- Raspberry Pi 2 or 3
- Case fitting Raspberry Pi B+ form
- Power supply (micro USB, 5V, at least 2A)
- USB wifi adapter if using a Raspberry Pi 2 (Raspberry Pi 3 has wifi built in) -or- Ethernet cable for direct connect to your router
- 8GB MicroSD card (class 10) -or- optional (128GB minimum) microSD card and no USB storage
- USB Flash drive (at least 128GB, USB 2.0 or higher) or USB external hard drive
If you wish to run a testnet node, the testnet blockchain is only around 8GB so keeping that on a 16GB microSD card with the OS will work well.
PURCHASE OPTIONS
You can find what is needed to build a Bitcoin raspnode for around $100.
The CanaKit Raspberry Pi 3 Complete Starter Kit costs $75 (plus tax and shipping) and comes with everything you need minus the USB drive and Ethernet cable (if you wish to cable directly to your router).
With enough exploring, reasonably priced 128GB USB drives can be found, some in the $35 to $40 range. Some 500GB external HDs can be found in the $40 to $60 range.
EQUIPMENT FOR SETUP
- HDMI cable
- Monitor with HDMI in or adapters to convert HDMI to your monitor
- USB keyboard
- Router and a connection to the Internet
- Separate PC which needs to be able to read a microSD card
ASSEMBLY
How to assemble your Raspberry Pi will depend on the case purchased. Once assembled, plug in your USB stick, HDMI cable to your monitor, USB keyboard, and either your USB Wifi adapter or an Ethernet cable going to your router.
The device will automatically power on once you plug in the micro USB power cable.
INSTALLING THE RASPBIAN OS
If your Raspberry Pi came with a microSD card preloaded with NOOBS you can insert the microSD card into your Raspberry Pi, plug in your power cable and it will walk you through your setup. Make sure you select Raspbian as your OS choice, which should be the first on the list. It will take a few minutes to install. Once that is finished, reboot and jump to Raspbian config options.
If you have a brand new microSD card, you will need to download a Raspbian image to your PC and image your microSD card. This tutorial will assume you are using a PC running Microsoft Windows. Instructions for imaging using Mac or Linux can be found in the Raspberry Pi documents:
http://www.raspberrypi.org/documentation/installation/installing-images/README.md
You can find the latest on the Raspberry Pi downloads page:
http://www.raspberrypi.org/downloads/
Or directly download the latest here:
http://downloads.raspberrypi.org/raspbian_latest
If you are not going to use the GUI you should download and use Raspbian Jessie Lite, which comes without the desktop software and so is more streamlined (but you will need to install one more dependency, git).
Once downloaded, unzip the file. If you don't have an application installed for unzipping files, you can use the open source 7zip:
The unzipped folder will have a large .img file. In order to put this image on your microSD card we'll need to use the open source Win32DiskImager which can be found on sourceforge:
http://sourceforge.net/projects/win32diskimager/
Or directly download the latest here:
http://sourceforge.net/projects/win32diskimager/files/latest/download
Once downloaded run the installer, this will install Win32DiskImager.
Insert your microSD card into your PC. Launch Win32DiskImager. Select the Raspbian .img file as the 'image file' and select your microSD card as your 'device'. Make sure what is selected is your microSD card and nothing else, especially your hard drive. Click 'write'. This will take a few minutes.
Once finished, eject your microSD card. Insert your microSD card into your Raspberry Pi and plug in the power cable and wait while it boots up.
RASPBIAN (OPTIONAL) CONFIG OPTIONS
When you first boot the latest Raspbian it will resize the image and reboot. If you want do some more customizations and fine tuning you can follow these optional steps below:
First launch the raspberry pi config menu with:
pi@raspnode~$ raspi-config
And you'll see the menu below:
If you won't be using Bitcoin-Qt (the GUI) then you can run it 'headless' and we can allocate a little more RAM to the CPU.
Select "8 Advanced Options" then select "Memory Split"
Change 64 to 16
Select "OK"
If you want to be able to SSH into your Raspnode, you can enable the SSH server here.
Select "8 Advanced Options" then select "SSH"
Select "Enable"
Change hostname. The default hostname is set to "raspberry". We'll change ours to "raspnode" and the rest of the tutorial will assume this. If you leave yours as "raspberry" or change it to something else, anytime you see the hostname mentioned, use that instead of "raspnode".
Select "8 Advanced Options" then select "Hostname"
Edit the hostname to “raspnode" without quotes (or to your desired hostname)
Select "OK"
Here you can also change the default user (which is "pi") and password (which is "raspberry"). We'll leave these as is for the tutorial. If you change your username, make sure to use that instead of "pi" when it shows up in this tutorial.
You can overclock your Raspberry Pi in order to give it a little more processing power. This may make the initial verification of the blockchain quicker, but is not needed for normal full node operations as the CPU generally sits around 10% and only jumps up to 30% or so when a new block is received.
Select "7 Overclock"
Choose the desired level of overclocking
Select "OK"
To set your timezone:
Select "4 Internationalisation Options"
Select "Change Timezone"
Go through the selection process to select your timezone, then select "OK"
Once done, select "Finished" and your Raspberry Pi will reboot.
When you get the "login" prompt, enter your username "pi" and it will prompt you for your password. Enter your password (which won't show up) and hit <enter> to log in (the password will be "raspberry" if you didn't change it in the raspi-config).
EDITING FILES
We'll be using the command line to edit files. If you are not familiar with a command line this may be a little tricky. Raspbian comes with a few editors. Nano is a relatively friendly editor and this tutorial will use that, but Raspbian also has vi for users who prefer it and can be used instead. If you have not used vi before, you should stick with nano.
For those not familiar with Linux, some actions we take will require root privileges. We get that by using the command “sudo" before our desired command. This will only work if you are logged in as a user with sudo rights, which the default Raspbian user (“pi" in our case) has. Sudo can be set to require a password, but the default Raspbian user should be set to not need one.
You may want to change the default keyboard layout. Edit /etc/default/keyboard
pi@raspnode~$ sudo nano /etc/default/keyboard
Change the line
XKBLAYOUT="gb"
to equal your desired country code, so for US keyboard layout change it to
XKBLAYOUT="us"
Then save and exit. Reboot to have it take effect. Reboot with
pi@raspnode~$ sudo shutdown -r now
CONFIGURE USB AND SET AUTOMOUNT
If you are using a 128GB or larger microSD and wish to put everything on that including the blockchain, you can skip this section and go to networking.
Make sure your USB stick is empty and using a file format that works natively with Linux (e.g. not NTFS). FAT32 is a good option. You can do this by plugging your USB stick into your Windows PC and checking it's properties. If it isn't empty, format it as FAT32. Here you can also change the label. Make a note of the label, it will be helpful later (but not necessary).
Windows may not give the option to format a drive that is very large as FAT32, in which case you will need to use some third party software, or format it in Linux. Also, note that Raspbian will most likely see FAT32 as VFAT which is what we'll see below.
Create a directory that will act as a mount point for the USB stick, we'll call it bitcoinData and put it in the home directory (full path will be /home/pi/bitcoinData/:
pi@raspnode~$ mkdir ~/bitcoinData
Plug your USB stick into your Raspberry Pi and wait a few seconds. In order to see where it is located, issue the command:
pi@raspnode~$ sudo blkid
You can issue the blkid command without sudo, but if you run it without root privileges you won't get any information back. What you should see is a few lines that look something like this:
/dev/mmcblk0p1: LABEL="root" UUID="1460456c-eadd-49a9-e2ab-a0fe18df0d3a" TYPE="ext4"
Which are specific to your OS. What you are looking for is a line like:
/dev/sda1: LABEL="<your usb label>" UUID="<some id>" TYPE="vfat"
This is where knowing your label can help. The type should be “vfat" and you are looking to see what the /dev/sdxx is (it could be sda1, sdb1, or something similar, but most probably sda1). Write that down. You don't actually need the label or uuid written down, just the location. If you are using an external hard drive there may be multiple partitions that show up like a boot partition and a data one. Make sure you mount a partition large enough to store the blockchain (not a boot partition).
In order to tell your Raspberry Pi to mount your USB stick automatically so that anything we put in the bitcoinData directory will be going onto the USB and vice versa we need to edit the /etc/fstab file.
pi@raspnode~$ sudo nano /etc/fstab
It should have a few lines of information, at the end of the file add this, all as one line, starting with the location of your USB drive that you wrote down. If it is /dev/sda1, then what you add would be this:
/dev/sda1 /home/pi/bitcoinData vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0 0
If you changed your username to something else, replace “pi" with that username above in all areas it shows up. There are no spaces in that line, only a single tab between each chunk of data. There are other options that you could use if you wanted more or less restrictions on your drive, but this will work. You should only alter this setup if you know what you are doing. Basically this will automatically mount the USB drive on boot to our desired location, allow the pi (or substituted user) to read and write data to the drive, and a few other things beyond the scope of this tutorial.
Save the file and exit. Reboot your Raspberry Pi:
pi@raspnode ~ $ sudo shutdown -r now
ENLARGE SWAP FILE
A swap file allows the microCD card to be used as extra memory if needed. It is slower and heavy use will shorten the life of a microSD card. Raspbian defaults to a 100Mb swap file which is not actually needed to build and run Bitcoin core under normal operating conditions. However if you are expecting to download the whole blockchain on the raspnode or the blockchain 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 /etc/dphys-swap:
pi@raspnode~$ sudo nano /etc/dphys-swapfile
And change the default size of 100
CONF_SWAPSIZE=100
To 1000
CONF_SWAPSIZE=1000
Save and exit. Then run:
pi@raspnode~$ sudo dphys-swapfile setup
pi@raspnode~$ sudo dphys-swapfile swapon
NETWORKING ON THE RASPBERRY PI
If you are using an Ethernet cable and plugging directly into your router and DHCP is turned on, you can plug that in and you should have access to the Internet. You can check by pinging out:
pi@raspnode~$ ping google.com
If you start to see pings you are good. Hit <ctrl> + c to stop the pings. If you are using a wifi adapter and have a password set for your router, there are a few more steps to take. Setting up and troubleshooting wifi on the Raspberry Pi is beyond the scope of this tutorial, so if the basic setup shown here doesn't work, you can reference the Raspberry Pi documentation for help:
http://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
To setup your wifi, edit the file /etc/wpa_supplicant/wpa_supplicant.conf:
pi@raspnode~$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add this to the bottom of the file:
network={
ssid="<your wifi ssid here>"
psk="<your wifi password here>"
}
For example, if your wifi network is named myHomeWifi and your wifi password is mySuperSecret then wpa_supplicant.conf should look something like:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="myHomeWifi"
psk="mySuperSecret"
}
Then restart your wifi interface:
pi@raspnode~$ sudo ifdown wlan0
pi@raspnode~$ sudo ifup wlan0
If you need to set a static IP, that is currently out of the scope of this tutorial.
DOWNLOADING BITCOIN CORE DEPENDENCIES
In order to install Bitcoin Core we need to install a few tools and software packages. First let's make sure everything is up to date and update it if it isn't:
pi@raspnode~$ sudo apt-get update
pi@raspnode~$ sudo apt-get upgrade -y
This one liner will download and install the packages we will need for Bitcoin Core 0.13.0:
pi@raspnode~$ sudo apt-get install autoconf libevent-dev libtool libssl-dev libboost-all-dev libminiupnpc-dev -y
If you installed Raspbian Jessie Lite you'll also need to install git:
pi@raspnode~$ sudo apt-get install git -y
That should take just a couple minutes. If you plan on using bitcoin-qt (the GUI and wallet) then you'll have to install additional dependencies:
pi@raspnode~$ sudo apt-get install qt4-dev-tools libprotobuf-dev protobuf-compiler libqrencode-dev -y
Make a directory to download required files:
pi@raspnode~$ mkdir ~/bin
pi@raspnode~$ cd ~/bin
Bitcoin Core 0.11.2 uses version 4.8 of the Berkeley database so we'll need to download, build, and install that. If you wish to run your Bitcoin node without a wallet, you can skip to Installing Bitcoin.
Download the Berkeley database source code, unzip it, then build the BerkeleyDB.
pi@raspnode~/bin$ wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
pi@raspnode~/bin$ tar -xzvf db-4.8.30.NC.tar.gz
pi@raspnode~/bin$ cd db-4.8.30.NC/build_unix/
pi@raspnode~/bin/db-4.8.30.NC/build_unix$ ../dist/configure --enable-cxx
pi@raspnode~/bin/db-4.8.30.NC/build_unix$ make -j4
The "make -j4" command should take around 5 minutes to complete. If you get errors, then remove the "-j4" and just execute "make". This will take around 20 minutes.
pi@raspnode~/bin/db-4.8.30.NC/build_unix$ sudo make install
INSTALLING BITCOIN
Download the Bitcoin Core 0.13.x (0.13.0 as of Oct 8, 2016) source code from github and build it. This command should download and install the latest 0.13.x version based on how Bitcoin Core organizes their repo, but that could change at any point. So if you wish to upgrade from 0.13.0 to 0.13.1, you would just need to use the same command, but updating to something like 0.14.x would require switching branches. Leaving the -b argument out will grab the latest development version which may or may not be stable and will not have been officially released yet.
pi@raspnode~/bin/db-4.8.30.NC/build_unix$ cd ~/bin
pi@raspnode~/bin$ git clone -b 0.13 https://github.com/bitcoin/bitcoin.git
pi@raspnode~/bin$ cd bitcoin/
pi@raspnode~/bin/bitcoin$ ./autogen.sh
If you plan on using bitcoin-Qt (the GUI and wallet) then use this command:
pi@raspnode~/bin/bitcoin$ ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default --with-gui
If you don't need the bitcoin-Qt (GUI) and will run your raspnode 'headless', then use this command instead:
pi@raspnode~/bin/bitcoin$ ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default
If you don't need the bitcoin-Qt (GUI) and don't need wallet functionality (and so you didn't install the Berkeley DB) then use:
pi@raspnode~/bin/bitcoin$ ./configure --enable-upnp-default --disable-wallet
The '-O2' arguments above are a capital letter O, not the number zero. Make sure there is a space after /include and -O2.. If you don't want to use UPnP, which automatically tries to open a port on your router for incoming Bitcoin connections on 8333, then remove '--enable-upnp-default'.
Once that completes, then run:
pi@raspnode~/bin/bitcoin$ make -j2
The "make -j2" command should take about 2.5 hours to complete if running without including the GUI, and many hours if being run with the GUI. Don't use "-j4" for this build. If you get errors using "-j2", then just run "make" but it will take around twice as long to build.
pi@raspnode~/bin/bitcoin$ sudo make install
CONFIGURE AND RUN BITCOIN CORE
Move into your mounted USB directory. Create the file bitcoin.conf and edit it, adding an rpc user and password. If you try running bitcoind before doing this, it will suggest a user and password, it is recommended you use those.
pi@raspnode~/bin/bitcoin$ cd ~/bitcoinData
pi@raspnode~/bitcoinData$ nano bitcoin.conf
bitcoin.conf should look something like this:
rpcuser=bitcoinrpc
rpcpassword=21Hy2d5kycuoLzWxdJjQoVN1jtL7Q5kzqhHz3ZfuYNCU
THIS IS JUST AN EXAMPLE, DO NOT USE THIS PASSWORD!
NOTE: If you are not using an external USB (or other) drive to store the blockchain then bitcoin.conf needs to go in ~/.bitcoin, not ~/bitcoinData. You also will not need to run bitcoind or bitcoin-qt with the "-datadir=/home/pi/bitcoinData" argument used below.
Launch bitcoind, telling it to use our mounted USB drive for the blockchain data directory.
pi@raspnode~/bin/bitcoin$ bitcoind -datadir=/home/pi/bitcoinData -daemon
If you want to run bitcoin-Qt (the GUI with wallet) then you'll have to first launch the desktop:
pi@raspnode~$ startx
Once the desktop has launched, open a terminal window:
Then run:
pi@raspnode~$ bitcoin-qt -datadir=/home/pi/bitcoinData
in the terminal:
Once the blockchain is synced and verified, you'll see your wallet just as you'd expect:
Downloading and verifying the full Bitcoin blockchain on the raspberry pi will take well over a month at this point and due to some optimizations made, doing so will cause the bitcoin software to crash many times during this period. You need to download the blockchain to another computer and transfer it to the external drive first.
CONFIGURE HOME NETWORK TO SYNC WITH THE BITCOIN NETWORK
If you configured your build with '--enable-upnp-default' then your raspnode with try to open up the ports on your router automatically. Not all routers support UPnP and it may not be enabled on yours even if it does. If this is the case, you will need to configure your home router to forward port 8333 to your raspnode. To do this you'll need your raspnode's IP address which you can get by running ifconfig:
pi@raspnode~$ ifconfig
If you are cabled into your router directly the IP address will be under "eth0", if you are on wifi it will be under "wlan0".
CONFIRM YOUR 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:
pi@raspnode~$ bitcoin-cli -datadir=/home/pi/bitcoinData getinfo
or by going to the bitnodes.21.co website and verifying that you are connected.