Raspberry Pi Bitcoin Core 0.10.2 Installation
This weekends project is setting up a Raspberry Pi as an online Bitcoin wallet.
As you might the first step has been installing Bitcoin Core. There is no binary Bitcoin available for the Raspberry Pi’s ARM process so I had to build it from source. Less I Forget here is my step-by-step guide:
- Raspberry Pi 2
- A 2A power supply
- External HD
- Raspbian OS Image Downloaded from here
- The blockchain – Optional but could save days of waiting
Installing a Clean OS
First thing to do now we have a Raspbian install image is copy it to a new microSD card.
Being a Linux user I just copy the image from the command line using
dd bs=1m if=/home/nxad/Downloads/Raspbian.img of=/path/to/sdcard
dd is a Unix command so if your MacOSX user the same command will work for you as well. It takes a few minutes but gets the job done. For Windows users a program like Win32DiskImager can do the install for you – full instructions can be found here.
Raspi-Config / Updating
As normal with a new installation
raspi-config will run during the first boot. What we need to do here is expand the file system to take up the whole sdcard – no point in empty space just sitting around looking prity.
Once that’s done enable the SSH server. The Pi will reboot after your exit
raspi-config so just let it do its thing.
Once the Pi is back up and running you can now keep working working with an attached keyboard a mouse of fire up and SSH connection from another machine and work from there, the choice is yours.
If you do choose the SSH option make sure you start a screen session, since the commands we’re about to run could take a few hours on the Raspberry.
If you need a pointers, the quickest way to get the Raspberry’s IP address is running
ifconfig from the command line. The default username is pi and – if you didn’t already change it – the password will be raspberry, but I would highly recommend changing it as your first step
passwd will do the job.
Now that we have a running Raspberry Pi and we’ve logged into a terminal – ether thru the keyboard and monitor or over SSH – we’re going to quickly run an OS update:
sudo apt-get update sudo apt-get upgrade -y
Getting the dependencies
We’re going to have to build Bitcoin Core from the source code, and for that we need the build tools and dependent libraries installed:
sudo apt-get install autoconf build-essential libboost-chrono-dev libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev libprotobuf-dev libqrencode-dev libqt4-dev libssl-dev libtools protobuf-compiler
We also need to install the BerkeleyDB 4.8, since its not available from apt-get we’ll need to build it from source as well. This will take a while so probably best grab a cup of coffee or something, but if your using a Raspberry Pi2 you can replace the
make command with
make -j4 to spread the load over the extra cores.
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 sudo make install
Getting the source
Now that the system is ready we can finally start on Bitcoin. First get the source code from the GitHub repository:
git clone -b 0.10 https://github.com/bitcoin/bitcoin.git cd bitcoin
Next we’ll configure it for our system and get the build started. Again this will take ages, but you can speed it up on the Raspberry Pi2 by using the
make -j4 command instead of just
make – for reference I just used the make option and it was done in about 3 – 4 hours.
./autogen.sh ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" make sudo make install
Up & running
… and we’re back. We now have Bitcoin Core 0.10.2 installed on our Raspberry. Before we run it for the first time we need to make sure we can download the blockchain. At present the blockchain is over 35Gb. Since we can’t feasible store it on our microSD card we need to put it on an external hard drive.
If you’ve never plug an external drive into a Raspberry Pi before, its worth pointing out the Pi doesn’t have enought power to support the drive directly. You must ether get a drive back with it own power or plug the drive into a powered usb hub.
Once your drive is ready you have a few options for telling Bitcoin Core where to put the blockchain. Ether mount the external drive to
/home/pi/.bitcoin or create a symlink there. The final option is to pass the the new location to bitcoin over the command line
One last thing before we fire up the Core. If you already have a copy of the blockchain copy this to the Raspberry Pi, it will save hours or even days of waiting. However, if like me you don’t you may run into the same problems I have.
When I started running
bitcoin-qt it will crash. After Googling around the error message relates to a lack of memory. The Raspberry Pi2 has 1GB or ram but its appears that isn’t always enough. Since adding more RAM isn’t a practical option I’ve resorted to running this script:
until bitcoin-qt; do echo "Bitcoin Crash: Restarting"; sleep 1; done;
This handy little one-liner will restart
bitcoin-qt every time it closes – in my case crashes – and the download will resume where it left off.
I’m not sure if this problem is histochemic of the Raspberry Pi or just while the blockchain is downloading but once my downloads completed I’ll get a better idea and can give some more feedback.