Skip to content

Instantly share code, notes, and snippets.

@peterVG
Last active January 29, 2024 08:26
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save peterVG/92c03ebef00575f14b2c051942d8ea09 to your computer and use it in GitHub Desktop.
Save peterVG/92c03ebef00575f14b2c051942d8ea09 to your computer and use it in GitHub Desktop.
Put IPFS decentralized storage on your Raspberry Pi with USB storage

I put IPFS on a Raspberry Pi and so should you!

Total cost of joining the decentralized storage revolution with your own lo-fi node: $124 USD

raspberry-ipfs

Here's how I did it:

1. Get an OS

  • Load an operating system image onto a micro SD card using Raspberry Pi Imager
  • I'm using Ubuntu 20.04 Server and will run it headless to save on the already limited RAM and Wattage needed to run a desktop and GUI.
  • I have the older Raspberry Pi 3 Model B which has an ARMv7 Processor so I need the 32 bit version.

2. Prepare initial boot to connect to wifi

  • With the SD card still inserted in your laptop, open a file manager and locate the system-boot partition on the card. It contains initial configuration files that will be loaded during the first boot.

  • We're going to edit two files so that Rapsberry Pi's onboard wifi chip will automatically connect to your wifi network.

  • Edit the network-config file so that it contains only the items in the example below. Comment out with #, or remove, all other settings including the LAN ones. Enter any missing items. Be certain to maintain only the indentations shown. Use two spaces for each indentation. Remove all tab characters.

# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#

version: 2
renderer: networkd
wifis:
  wlan0:
    dhcp4: true
    dhcp6: true
    optional: true
    access-points:
      "SSID":
         password: "PassPhrase"
  • Edit the user-data file appending the additional lines shown below. Again, use spaces, not tabs and mind the indentation.
# Reboot after cloud-init completes
power_state:
  mode: reboot

3. Fire up the Pi

  • Insert the micro SD card into Raspberry Pi and plug in its micro USB charger
  • Allow Ubuntu to boot; DO NOT try to log into Ubuntu as soon as possible. Wait until Cloud-Init runs (although it appears to be doing nothing - in about two minutes it will show SSH info when done). If you don't wait you may not be able to logon with the default user and passwd. At the end of the cloud-init, Ubuntu will be rebooted. Wait a couple of minutes for the server to boot.
  • Find Raspberry Pi's IP address on your wifi network by logging in to your router and looking for an ubuntu device. My router is located at "http://10.0.0.1/". Check here for help finding yours: http://whatsmyrouterip.com/
  • NOTE: On my glorious wifi network, the Raspbery Pi's IP address is sometimes mysteriously different than the one reported on the router, but is connected nonetheless. Then I have to log into the Raspberry Pi board by plugging in a monitor and USB keyboard. Installing sudo apt get net-tools (which is possible because it is now actually connected to wifi) and running ifconfig to get its IP address.
  • Open a terminal on your laptop and ssh ubuntu@<Raspberry Pi’s IP address>
  • Change the ubuntu user password and reconnect

Raspberry Pi 3

4. Prepare the USB Hard Disk

  • Reformat your USB Hard Disk to EXFAT (GUID) format. On a Mac you can use Disk Utility.

  • Plug the USB drive into Raspberry Pi USB port

  • get disk name: sudo fdisk -l

  • Get USB device info: lsusb

  • see also:

    • Get system info: sudo lshw
    • Get storage device info: lsblk
    • See how much space is available and used: df -h
    • See hidden files ls -ld .?*

Install EXFAT packages on Ubuntu

  • sudo add-apt-repository universe
  • sudo apt update
  • sudo apt install exfat-fuse exfat-utils
  • If you get the error "Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2668 (unattended-upgr)" Then: sudo kill -9 <process#>

Mount USB drive

  • Make a directory for USB device to use (e.g. "usb0")
  • sudo mkdir /media/usb0
  • Find name of USB storage device (e.g. "/dev/sda1")
  • sudo fdisk -l
  • mount USB drive using exfat format:
  • sudo mount -t exfat /dev/sda1 /media/usb0
  • make ubuntu user the owner of the USB drive
  • sudo chown -R ubuntu:ubuntu /media/usb0
  • double-check that ubuntu user has write permission on the USB drive, otherwise this won't work:
  • (without sudo) touch /media/usb0/test.txt
  • ls /media/usb0/
  • assuming your test file appeared, clean it up: rm -f /media/usb0/text.txt

5. Install IPFS

  • Install the go-ipfs client, see https://ipfs.io/ipns/dist.ipfs.io/#go-ipfs

  • If you have a Raspberry Pi 4 you can install the Linux 64-bit ARM version, otherwise use the Linux ARM version.

  • Linux ARM (32 bit): sudo wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v0.6.0/go-ipfs_v0.6.0_linux-arm.tar.gz

  • sudo tar -xvzf go-ipfs_v0.6.0_linux-arm.tar.gz

  • cd go-ipfs

  • sudo bash install.sh

  • ipfs --version

  • change ipfs repo location to USB drive:

  • sudo nano /etc/environment

  • IPFS_PATH="/media/usb1"

  • sudo reboot

  • check that IPFS is going to use your USB drive as its repo (not your tiny micro SD card)

  • echo $IPFS_PATH

  • ipfs init

  • echo 'Hello IPFS!' > test.txt

  • ipfs add test.txt

  • note the Content ID (CID) it reports back, e.g "QmYWAifyw2V5dEq7c5GgdSPffeKoYXQZggnYzw5RbXpig4"

  • ipfs cat QmYWAifyw2V5dEq7c5GgdSPffeKoYXQZggnYzw5RbXpig4

  • Welcome to decentralized storage on Raspberry Pi!

  • Go to https://docs.ipfs.io/how-to/ and start IPFS-ing with your Raspberry Pi.

@kvutien
Copy link

kvutien commented Sep 14, 2021

BTW, you may also want to explain in user-data that we need to reboot because of a bug in netplan? See https://bugs.launchpad.net/ubuntu/+source/netplan.io/+bug/1874377.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment