The Do-It-Yourself 21 Bitcoin Computer - Raspberry Pi 3 Edition

Posted by Tyler Pate

The Do-It-Yourself 21 Bitcoin Computer: Raspberry Pi 3 Edition

Overview

21 enables users to create and sell machine-payable APIs on the 21 Marketplace from any Debian or OSX based system. But often you don't want to host these kinds of APIs on your primary laptop. A laptop is built for mobility, and intermittently connects and disconnects from the internet; this is convenient for you as a user, but bad for someone who wants to buy from you. In addition, any server on the internet is typically subject to more attacks than a client, and you might not want to take that risk with your primary computer.

As an alternative to serving APIs off your laptop, Raspberry Pi single board computers make great standalone servers for home users to host data and services for sale. This tutorial will guide you through the steps necessary to build your own do-it-yourself (DIY Bitcoin Computer capable of hosting machine-payable apis.

The steps you will take are as follows:

  • First, download and flash the image to an SD card with an OSX or Linux host computer
  • Next, assemble the board
  • Then boot the single board computer and configure the system
  • Finally, install 21

Prerequisites

You will need the following items:

Number Item Price
1 Raspberry Pi 3 $41.48
2 Class 10+ MicroSD Card (16GB+ recommended) $19.99
3 5V 2.5A Power Supply $8.99
4 HDMI Monitor
5 HDMI Cable
6 USB Keyboard & Mouse
7 MicroSD Card Reader
8 Enclosure
Total $70.46

Note: A Raspberry Pi 2 will also work, however this tutorial only focuses on the Raspberry Pi 3.

You should have all of the items in this picture before continuing.

Complete Kit

Enclosures

We've created a customized 21 enclosure designed for 3D printing. You can print the STL file on your own printer. Alternatively, you can order the official enclosure or one of numerous after market enclosures available.

3d Printed 21 Enclosure

Building your DIY 21 Bitcoin Computer

Now that we have all the requirements ready, we can start to build our DIY 21 Bitcoin Computer.

Linux Image - OSX Host System

Let's get the operating system image and prepare it for flashing. We are using Raspbian Jessie Linux, provided by the Raspberry Pi Foundation. Open a terminal on your host OSX machine and run the following commands:

cd
curl -L https://downloads.raspberrypi.org/raspbian_latest -o raspbian.zip

# Verify file integrity

# Visit https://www.raspberrypi.org/downloads/raspbian/ to get the SHA-1 hash of
# the Raspbian Jessie image.
# The output of the shasum command should match the SHA-1 hash seen on the website. 
shasum raspbian.zip

# If the image SHA-1 matches the download, unzip raspbian.zip. 
unzip raspbian.zip

# Set the image file name variable for use in the flashing step.
IMAGE_NAME=$(ls | grep raspbian-jessie)

Insert the SD card into the SD card reader and connect it to your host machine. We will identify the disk and unmount any mounted partitions.

diskutil list

Look for a SD Card. You can match the size output from diskutil list with the size of your SD Card. You will see output similar to the following image. Here, the disk we are looking for is disk3.

OSX diskutil output

Warning: later in this tutorial you will be overwriting all data on whatever device you choose, so it's absolutely critical that you choose the correct device. In the following code, fill in the number of the device you found using diskutil above:

# IMPORTANT: Replace the "#" with your disk number
DEVICE=/dev/disk#

Now, unmount any mounted SD card partitions.

# This command will unmount any mounted SD card partitions on your system.
test -b $DEVICE && sudo diskutil unmountDisk $DEVICE || echo "ERROR with ${DEVICE:-device}"

If you run the command above and it doesn't print any output, it was successful. If it prints an error message, please check to see that you followed the instructions above; if you did and it still prints an error, please send a copy of the error message to support@21.co so we can investigate.

Linux Image - Ubuntu Host System

Let's get the operating system image and prepare it for flashing. We are using Raspbian Jessie Linux, provided by the Raspberry Pi Foundation. Open a terminal on your host Ubuntu machine and run the following commands:

cd
curl -L https://downloads.raspberrypi.org/raspbian_latest > raspbian.zip

# Verify file integrity

# Visit https://www.raspberrypi.org/downloads/raspbian/ to get the SHA-1 hash of
# the Raspbian Jessie image.
# The output of the shasum command should match the SHA-1 hash seen on the website. 
sha1sum raspbian.zip

# Linux: Run apt-get if you do not have unzip installed.
sudo apt-get install -y unzip

# If the image SHA-1 matches the download, unzip raspbian.zip. 
unzip raspbian.zip

# Set the image file name variable for use in the flashing step.
IMAGE_NAME=$(ls | grep raspbian-jessie)

Insert the SD card into the SD card reader and connect it to your host machine. We will identify the disk and unmount any mounted partitions.

lsblk

Look for a SD Card. You may see multiple partitions as /dev/mmcblk* or /dev/sd*. You will see output similar to the following. Here, the disk we are looking for is mmcblk0.

Ubuntu diskutil output

# Unmount any mounted SD card partitions on your system.
# Replace "mmcblk0p1" and "mmcblk0p2" with the partitions you found above
sudo umount /dev/mmcblk0p1
sudo umount /dev/mmcblk0p2

Warning: later in this tutorial you will be overwriting all data on whatever device you choose, so it's absolutely critical that you choose the correct device. In the following code, fill in the base name of the device you found using lsblk above:

# If you found a device starting with /dev/mmcblk you want to provide
#   everything up to and including the number that comes after "blk"
# For example, /dev/mmcblk0
# DO NOT add the parts starting with "p"
#
# If you found a device starting with /dev/sd you want to provide
#   everything up to and including the letter immediatly after the "sd"
# For example, /dev/sdc
# DO NOT add any numbers from the name
DEVICE=/dev/

The following command will ensure the device you chose exists

test -b $DEVICE || echo "ERROR with ${DEVICE:-device}"

If you run the command above and it doesn't print any output, it was successful. If it prints an error message, please check to see that you followed the instructions above; if you did and it still prints an error, please send a copy of the error message to support@21.co so we can investigate.

Flashing your SD Card

Now, it is time to flash the image. First let's perform some checks to make sure we have the correct data.

# Verify IMAGE_NAME is set.  This should print out a name such as
# "2016-05-27-raspbian-jessie.img"
echo $IMAGE_NAME

# Verify DEVICE is set.  This should print out a name such a /dev/disk3,
# /dev/mmcblk2, or /dev/sdc
echo $DEVICE

Double or triple check the disk identifier from above before executing the dd command in the next segment. You can cause damage to your partitions if you incorrectly specify input and output paths.

Flash the image:

DEV=${DEVICE/disk/rdisk} ; test -b $DEV && sudo dd if=$IMAGE_NAME of=$DEV || echo "ERROR writing $DEV"

Note: You will not see progress updates during the operation, until dd exits.

If you run the command above and it prints an error message, please check to see that you followed the instructions above; if you did and it still prints an error, please send a copy of the error message to support@21.co so we can investigate.

First boot

If you have an enclosure, go ahead and put your Raspberry Pi in the case.

Insert your flashed SD card, connect the HDMI cable, keyboard, mouse, and finally the power supply.

You should see four raspberries on the top of your screen and scrolling kernel messages. Then, a graphical desktop environment (GDE) will appear.

Now, open a terminal window to configure your installation. Enter keystroke Ctrl-Alt-F1 to open one of 6 terminals (F1-F6) from a GDE or terminal. To return to the GDE Desktop, enter Ctrl-Alt-F7.

Securing your system

Let's take a few basic security precautions for your system. Change the default and root user passwords:

# As pi user
passwd pi
# enter old password: raspberry
# enter new challenging password
# re-enter password

# As Root user
sudo passwd
# enter new challenging password
# re-enter password

Configuring Keyboard Layout

The Raspbian image comes with a default keyboard layout set for Great Britain. If you use a US keyboard, you will find that the @ character is mapped to the " character. To fix, open the default keyboard configuration file and change XKBLAYOUT="gb" to XKBLAYOUT="us".

Use your keyboard to navigate to the gb characters, delete them, and replace with us. Then, hit Ctrl-X to close the file, and hit y followed by return to save the file.

You may also need to change XKBMODEL to XKBMODEL="logitech_base" if keymappings do not respond as expected after changing XKBLAYOUT. Note that keyboard layout changes will not update until a system reboot.

# Open the keyboard config file with console text editor Nano
sudo nano /etc/default/keyboard

# This will open the default configuration file. It looks like this:

# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="logitech_base"

XKBLAYOUT="gb" # Change this line!
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"

Configuring internet access

Now, let's configure the wireless settings. We are going to use the graphical desktop environment to edit the wireless settings. Return to the GDE with Ctrl-Alt-F7. Now, click on the network connection icon in the upper menu bar.

RPi 3 Connectivity Screenshot

If you are using a wireless connection, enter your network details through the prompts. If you are wired ethernet, you should already be connected. You will see two arrows pointing up and down if you are already connected to wired LAN.

Verify your internet connectivity with a ping operation. Return to a terminal with Ctrl-Alt-F1, and enter:

ping google.com

You should see ping statistics returned if you are connected. Hit keystroke Ctrl-C to stop the ping process.

Configure system options

Now we are going to expand the SD card filesystem and set the timezone according to your location.

The default filesystem size is determined by the size of the image you burned earlier, which was around 4GB. If you burned this to a 128GB SD Card, there would be 124GB of unparitioned and unusable space. It's important to resize any flashed image in order to be able to use the full amount of free space.

Open a terminal and run the following:

sudo raspi-config

The tool will look like this when you open it:

RPi 3 Filesystem Expansion Image

Execute the following steps:

  • Highlight Expand Filesystem and hit enter
  • Highlight Internationalization Options and hit enter
  • Then hit Change Timezone and select your location, and hit enter
  • Exit raspi-config by navigating to Finish and hit enter
  • Choose to reboot your system now, and hit enter

On reboot, the system will run resize2fs, which will expand your filesystem's image to fill the full size of your SD Card. When your system reboots and opens the Desktop, hit Ctrl-Alt-F1 again to return to a terminal.

Updating your system

Now, let's update package sources and upgrade your packages to the latest versions. These two commands may take some time, and require internet connectivity.

# Respond yes to the prompts
sudo apt-get update
sudo apt-get -y upgrade

Linux Safe Shutdown

To keep the integrity of your filesystem, it is important to issue a shutdown or restart command before removing power from your RPi. Execute a safe shutdown or restart as needed with the following commands. Note, you do not need to run these commands now. They are included for your reference.

# Shutdown
sudo shutdown now

# Reboot
sudo reboot now

Installing 21

Now, install 21 by running the following command:

curl https://21.co | sh

Register for an account

Click here to register for an account. You will need to validate your email.

Log into your 21 account and run 21 status

21 login
# Enter your username & password

21 status

21 login

You should see output from the 21 status command.

21 status

21 sell

(available now on OSX; coming soon to other distributions)

On supported devices, install and publish bundled 21 apps with the 21 sell command.

21 sell start --all

This will join the 21market ZeroTier network, permitting network access to other machines running 21.

Verify your ping21 installation with the following:

curl -g -6 'http://[::1]/ping21'

You should see "Payment Required" in response to this command.

Developing your own applications

Congrats! If you have made it this far, you now have your own DIY 21 Bitcoin Computer! A standalone machine is perfect for running always-on applications like ping21 and others. Now it's time to develop your own applications!

The Raspberry Pi platform is well developed and there are a host of software and hardware applications that can be developed into 21 marketplace applications. Here are a few example projects to get you thinking about your own ideas: