Sjors / armbian-bitcoin-core

Generates an Armbian image for minicomputers with Bitcoin Core including GUI
MIT License
11 stars 8 forks source link

Use Armbian to (automagically) compile Linux for your device, compile Bitcoin Core, copy the blockchain and create an image for your SD card.

Ingredients

Download and prune blockchain

Download and install Bitcoin Core on your computer and wait for the full blockchain to sync. A few hints, if you open the Preferences (Command + , on macOS):

When it's done, quit bitcoind and change prune=1 to prune=550. Start Bitcoin Core again, wait a minute and quit. This deleted all but the most recent blocks.

Put the blockchain in a shared folder

Create a shared folder somewhere on your computer. Create a directory bitcoin inside of it, copy the blocks and chainstate folders to it. For testnet, create bitcoin/testnet3 and copy testnet3/blocks and testnet3/chainstate.

Virtual Box

Download Virtual Box, install it and when it asks, also install the guest extensions. The latter lets you share a folder between your computer and the VM.

Armbian is picky about which Ubuntu version you use, so we'll use Ubuntu 18.04 Bionic both for the virtual machine as well as the device. If you already use Ubuntu 18.04 then of course you won't need the virtual machine, though if you run into strange errors, it might be worth trying.

Download the Ubuntu Server installer.

Here's a good step by step guide for installing the VM, which some changes:

Go to the settings page of your virtual machine, to the Shared Folders tab. Click the + button, find the folder you just created, enter shared as the name and check the auto mount box.

Once the installation is complete, it should reboot the VM and you should see a login prompt. Use the password you entered earlier.

Prepare and start Armbian build

Click on the VM window and then select Insert Guest Editions CD from the Devices menu.

The prepare-build.sh script in this repository takes care of cross-compiling Bitcoin Core (if you're not using desktop) and starting the Armbian build process.

If needed, it will install the Guest Editions and ask you to reboot: sudo reboot.

$ mkdir src
$ git clone https://github.com/Sjors/armbian-bitcoin-core.git
$ ./armbian-bitcoin-core/prepare-build.sh -h
Usage: ./armbian-bitcoin-core/prepare-build.sh -b 32 [options] tag
  options:
  -h     Print this message
  -b     Bits: 32 or 64 (default)
  -g     Build GUI (QT)
  -j     Number of parallel threads to use during build (each needs ~1.5 GB RAM)
  -l [c] Add lightning: c (c-lightning)
  -p     Use pre-built bitcoin core binaries in src/bitcoin
  -c     Clean
  -u     Ubuntu release: bionic (18.04, default), xenial (16.04)

To build Bitcoin Core 0.17 without GUI, for a 32 bit device and with lightning:

./armbian-bitcoin-core/prepare_build.sh -b 32 -l c v0.17.0
``

After some initial work, it will ask you to select your board. Select
Mainline for the kernel.

Sit back and wait... If all goes well, it should output something like:

[ o.k. ] Writing U-boot bootloader [ /dev/loop1 ] [ o.k. ] Done building [ /home/armbian/build/output/images/Armbian_5.46_Nanopineoplus2_Ubuntu_bionic_next_4.14.48.img ] [ o.k. ] Runtime [ 30 min ]


Move the resulting image to the shared folder so you can access it:

```sh
mv /home/armbian/build/output/images/Armbian*.img ~/shared

You can shut the VM down now.

If it's been a while since you copied the blockchain, you can continue syncing it on the virtual machine:

./armbian-bitcoin-core/sync-chain.sh

Prepare bootable microSD card

Use Etcher to put the resulting .img file on the SD card.

The first time you login your user is bitcoin and your password is bitcoin (you'll be ask to pick a new one).

If everything works, you can delete the VM if you like, but if you keep it around, the second time will be faster.

This is a good time to enable wifi if your device supports it:

nmcli d wifi list
sudo nmcli d wifi connect SSID password PASSWORD
sudo service network-manager start

To connect to it via SSH, first, find the IP address (most likely under wlan, inet 192.168.x.x):

ifconfig

On your computer, edit .ssh/config and add:

Host pi-wifi
    HostName 192.168.x.x
    User pi

Copy microSD card to device eMMC

The device has eMMC storage which is faster than the microSD card, and you may want to be able to use the card.

To copy it over:

sudo nand-sata-install

This powers off the device when its done. Eject the microSD card and start the device.

The emmc-boot service should now kick in and start spinning up Bitcoin, Lightning and the web server. It may take a few minutes.

Check

Congrats

If you pulled this off successfully, you now have the right skills to help the world verify that Bitcoin Core binaries are actually derived from the source code. Consider contributing a Gitian build.