Giter VIP home page Giter VIP logo

ipfs-rpi-zero's Introduction

IPFS Installer for RaspberryPi Zero W

Bash script that installs and setups IPFS for RaspberryPi OS Lite on RaspberryPi Zero W.

How To Install

  1. Get a brand new installed Raspberry Pi OS Lite (with no GUI) micro SD card.
    1. See the prerequisites below.
  2. Update, upgrade apk packages and upgrade kernel to the latest as well.
  3. SSH to your RaspberryPi Zero W.
  4. Go home.
  5. Create a file, copy and paste the script.
  6. Give access to the script. (chmod +x ipfs-rpizero.sh)
  7. Run the script. (./ipfs-rpizero.sh)
  8. Reboot now. (sudo reboot now)

Prerequisites

  1. Do not use desktop version of RaspberryPi OS.
  2. Set display resolution to 800 x 600 or lower.
  3. Change host name from raspberrypi to other, if necessary. (Recommended though)
  4. Set disk swap size to 2GB.
  5. Change your pi user password.
  6. Set SSH settings to login with private key. (Send your public key to ~/.ssh/known_hosts)
  7. Disable SSH pasword login and root user login.
  8. Disable all exposed ports except: SSH(22) and IPFS(4001).

How To Run IPFS Daemon

  • ./ipfs-rpizero.sh run

To run the IPFS daemon background:

  • nohup ./ipfs-rpizero.sh run

How To Uninstall

  • ./ipfs-rpizero.sh uninstall

How To Check Status of IPFS Daemon (Access to IPFS Web UI)

  • ./run-webui.sh

IPFS Daemon contains a built-in Web server to monitor the status from the Web browser.

You can monitor file trafic, peers connected and post or mange a file to IPFS.

Though, this script does not allow Web access from other client. (Only http://localhost:5001/ or http://127.0.0.1:5001 request are allowed)

We recommend to SSH port forward the 127.0.0.0:5001 access of your rpi to your local.

# In your local, run the below to begin port forward/tunnel the SSH access.
ssh -N [email protected] -L 5001:127.0.0.1:5001

# Note that the above login user is `pi` and the host is `raspberrypi.local`.
# Change it to your settings.

Then from your browser, access: http://localhost:5001/webui

How To Contribute

  • Request, enhancement, ideas, etc. -> Go to the discussions
  • Bug report -> Go to the issues
  • PR -> Welcome!!
    • We recommend to draft a PR first, before implementing anything. So the others would know what you are dealing with.

Resources

Tested Environments

$ # OS
$ cat /etc/os-release | grep PRETTY_NAME
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"

$ # Hardware Revision
$ cat /proc/device-tree/model
Raspberry Pi Zero W Rev 1.1

$ # Kernel version
$ cat /proc/version
Linux version 5.10.31+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1412 Wed Apr 21 15:43:03 BST 2021

$ # IPFS version
$ sudo -u ipfs ipfs --version
ipfs version 0.8.0

ToDo

  • Create systemd service template
  • Create tests for script setup_ipfs.sh (Lint and static analysis check)
  • Include basic security checker.
    • pi user password is not default (not raspberry)
    • ssh: pasword login is disabled
    • ssh: root uer login is disabled
  • Reboot machine periodically (cron once a nth day)
  • Check IPFS latest stable version on boot

ipfs-rpi-zero's People

Contributors

keinos avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

ipfs-rpi-zero's Issues

"failed to sufficiently increase receive buffer size" on daemon up

When nohup ./ipfs-rpizero.sh run, it launches the IPFS Daemon but there's an error:

failed to sufficiently increase receive buffer size (was: 176 kiB, wanted: 2048 kiB, got: 352 kiB).
See https://github.com/lucas-clemente/quic-go/wiki/UDP-Receive-Buffer-Size for details.`

$ ps aux | grep ipfs | grep daemon | grep -v avahi
root       573  0.0  0.6   8512  3228 pts/0    S    17:08   0:00 sudo -u ipfs IPFS_PATH=/ipfs_data IPFS_FD_MAX=8192 ipfs daemon --migrate --enable-gc
ipfs       574 43.0 15.2 825460 74660 pts/0    Sl   17:08   1:43 ipfs daemon --migrate --enable-gc

$ cat nohup.out
IPFS Version: Error: error loading plugins: open /ipfs_data/config: permission denied
Setup IPFS ...
Installation and setup for IPFS done.
IPFS Version: Error: error loading plugins: open /ipfs_data/config: permission denied
Setup IPFS ...
Installation and setup for IPFS done.
Running IPFS daemon ...
Initializing daemon...
go-ipfs version: 0.8.0
Repo version: 11
System version: arm/linux
Golang version: go1.15.8
2021/05/11 17:08:10 failed to sufficiently increase receive buffer size (was: 176 kiB, wanted: 2048 kiB, got: 352 kiB). See https://github.com/lucas-clemente/quic-go/wiki/UDP-Receive-Buffer-Size for details.
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/127.0.0.1/udp/4001/quic
Swarm listening on /ip4/192.168.10.102/tcp/4001
Swarm listening on /ip4/192.168.10.102/udp/4001/quic
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /ip6/::1/udp/4001/quic
Swarm listening on /p2p-circuit
Swarm announcing /ip4/122.219.245.20/udp/49021/quic
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/127.0.0.1/udp/4001/quic
Swarm announcing /ip4/192.168.10.102/tcp/4001
Swarm announcing /ip4/192.168.10.102/udp/4001/quic
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/::1/udp/4001/quic
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

The current buffer (default) size was:

$ sudo sysctl -a | grep rmem_max
net.core.rmem_max = 180224

Include the "MUST" configuration in the setup script

To let RPi-Zero run IPFS as stable as possible and to ease setup, it is convenient to include the configuration setup in the script.


  • NOTE raspi-config nonint functions obey sh return codes
    • 0 is in general success / yes / selected
    • 1 is failed / no / not selected

Detect RPi Zero

is_pizero() {
   grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo
   return $?
}

Expand Root Disk Size

sudo raspi-config nonint get_can_expand 1>/dev/null 2>/dev/null && {
    raspi-config nonint do_expand_rootfs
}

Expand Swap Size

# Re-write swap size to 2GB
sudo sed -i -e "s/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=2048/g" /etc/dphys-swapfile

# Check the size
cat /etc/dphys-swapfile | grep CONF_SWAPSIZE

# Reboot the swapfile service
sudo service dphys-swapfile restart

Conserving VRAM

# Check current size
sudo raspi-config nonint get_config_var gpu_mem /boot/config.txt

# Set VRAM memory from 64 MB(default) to 16 MB
sudo raspi-config nonint do_memory_split 16

Disable X Window System (if found)

systemctl list-units | grep lightdm 1>/dev/null 2>/dev/null && {
    sudo systemctl stop lightdm
    sudo systemctl disable lightdm
}

Set Power LED as "heartbeat" Mode

This will set the Green LED in RPi-Zero to blink when functioning. It will not blink if it's hunging.

sudo bash -c "echo dtparam=act_led_trigger=heartbeat >> /boot/config.txt"

Boot Into the Text-Based Console with Automatic Login

sudo raspi-config nonint do_boot_behaviour B2

Disable BlueTooth

All we need is Wi-Fi, so disable BlueTooth to save energy.

sudo systemctl stop hciuart.service
sudo systemctl stop bluealsa.service
sudo systemctl stop bluetooth.service

Wait For Network At Boot

sudo raspi-config nonint do_boot_wait 30

Disable The Splash Screen on Boot

#sudo bash -c "echo disable_splash=1 >> /boot/config.txt"
if [ "$(sudo raspi-config nonint get_boot_splash)" = "0" ]; then
    raspi-config nonint do_boot_splash 1
fi

Defer Boot

Waits for the network at boot. This will pause LED heartbeat until the network is ready.

sudo raspi-config nonint do_boot_wait 30

References

"Error: error loading plugins: open ... /config: permission denied" on version print

Since IPFS daemon aims to run as user ipfs, an error occurs while printing the IPFS version when nohup ./ipfs_rpizero.sh run.

See the 1st line of the log:

$ cat nohup.out
IPFS Version: Error: error loading plugins: open /ipfs_data/config: permission denied
Setup IPFS ...
Installation and setup for IPFS done.
Set max buffer to 1024 MB
net.core.rmem_max = 2097152
Running IPFS daemon ...
Initializing daemon...
go-ipfs version: 0.8.0
Repo version: 11
System version: arm/linux
Golang version: go1.15.8
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/127.0.0.1/udp/4001/quic
Swarm listening on /ip4/192.168.10.102/tcp/4001
Swarm listening on /ip4/192.168.10.102/udp/4001/quic
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /ip6/::1/udp/4001/quic
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/127.0.0.1/udp/4001/quic
Swarm announcing /ip4/192.168.10.102/tcp/4001
Swarm announcing /ip4/192.168.10.102/udp/4001/quic
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/::1/udp/4001/quic
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (reason

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.