Setup and run a Sia host on a Raspberry Pi 3/4

Thu, May 21, 2020

Operating System

Install Ubuntu 64-bit 20.04 LTS release

If you own a Raspberry Pi you probably know how to do this. If not, the easiest way is probably to download the Raspberry Pi Imager and use it to prepare a sdcard. Your storage device should have at least 64 GB. This guide will not work with a 32 GB sdcard.

Make sure to select the 20.04 64bit long term support version.

Ubuntu 20.04 / Raspberry Pi Imager.

Install Ubuntu 20.04 LTS 64bit using the Raspberry Pi Imager

Login and set a password

Login into Ubuntu with your favorite SSH client. The default username and password is ubuntu. You are promted to change your password on first login. Once you’ve changed your password you have to login again with the new password.

We now switch to the root user for the following commands using

sudo su -

Create an ZRAM Partitions and a Swapfile

If you use a Raspberry Pi 3 you are limited to 1 GB of RAM. The memory consumption for some tasks might be higher.We therefore use a 256 MB sized RAM based block storage where we compress data and in addition a 1.5 GB swapfile within the filesystem. First we install the ZRAM tools using the following command:

apt install zram-tools

We than edit /etc/default/zramswap using

nano /etc/default/zramswap

and uncomment and set the allocation setting:

ALLOCATION=256

To save your changes use Ctrl + O followed by Enter. To quit, use Ctrl + X.

We than edit and enable kernel parameters to make better use of ZRAM by adding some lines to /etc/sysctl.conf. Those lines force the Raspberry Pi to do agressive swapping even before running out of memory.

echo "vm.vfs_cache_pressure=500" >> /etc/sysctl.conf
echo "vm.swappiness=100" >> /etc/sysctl.conf
echo "vm.dirty_background_ratio=1" >> /etc/sysctl.conf
echo "vm.dirty_ratio=50" >> /etc/sysctl.conf
sysctl --system

In addition to the ZRAM we create a swapfile and add a line to fstab so the swapfile is automatically mounted on next boot. If you use a Raspberry Pi 4 with 2 GB or 4 GB or RAM you can probably skip this step and probably even the whole ZRAM part as well.

fallocate -l 1.5G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

Enable automatic updates

A Sia storage node will usually run for a long time and you probably rarely interact with it. It therefore is a good idea to configure and enable unattended upgrades for the OS:

nano /etc/apt/apt.conf.d/50unattended-upgrades

Uncomment (removing the two slashes in front of the lines) and edit the following settings:

"${distro_id}:${distro_codename}-updates";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "false";

To save your changes use Ctrl + O followed by Enter. To quit, use Ctrl + X.

Sia Node

Install Docker

To keep everything easy we want to use a Docker container to run our Sia node.

apt install docker.io

Make a decision about data storage

The first thing you have to know is that it is a bad idea to store the data (node data, blockchain and hosted files) on an SDcard. There will be a lot of writes and the card will probably die quite fast. Instead you should place the data on more durable storage devices like e.g. a HDD or SSD and probably even a RAID to protect the data against disk failure. For my Raspberry Pi node I store the node data including the blockchain on a small SSD and the hosted files on larger HDDs.

For setting up the data storage with docker you have a couple option:

  • Store data in a mounted docker volume
  • Store data in a mounted local filesystem path
  • Store some data in a docker volume and some in the local file system

Using a docker volume is probably the way to go if you only plan this as a test setup. Mounting filesystem paths is the way to go if you want to add storage from multiple drives / file system paths. I strongly suggest to go with a filesystem path from the start, however if you want to go with a docker colume create a volume for the Sia container like this:

docker volume create sia-data

Skip the volume creation if you want to use filesystem paths.

Bootstrap Sia

Normally we would now be able to start our Sia node, however the initial sync of the node would take a very long time. We can bootstrap this process by downloading data that would otherwise be downloaded and verified from other nodes. Even this takes quite some time but is still way faster than the normal sync.

wget --tries=inf -O blank-siad-260k.tar.gz "https://skyportal.xyz/file/LAD8TZnESG27UlZGsmsxG36a6Kx7akNxJD3b7iRjT5OzNg"

Note: You can also choose other Skynet portals from this list if the one listed above does not work. For most portals you need to remove /file/ from the URL. The official portal operated by Nebulous is SiaSky.net.

We can now extract the files, delete the tar.gz and move the extracted files into our docker volume.

mkdir sia-data && tar -xvf blank-siad-260k.tar.gz -C sia-data && rm blank-siad-260k.tar.gz
docker run --rm -v $PWD:/source -v sia-data:/sia-data -w /source alpine mv sia-data/* /sia-data

Run the Sia Docker container

Now is a good time to finally run the Sia Docker container.

If you created a docker volume use the following:

docker run \
  --env SIA_WALLET_PASSWORD="YOUR SEED" \
  --env SIA_API_PASSWORD=apipass1 \
  --detach \
  --restart unless-stopped \
  --mount type=volume,src=sia-data,target=/sia-data \
  --publish 127.0.0.1:9980:9980 \
  --publish 9981:9981 \
  --publish 9982:9982 \
  --publish 9983:9983 \
  --name sia \
   siacentral/sia -c --siamux-addr ":9983" --host-addr ":9982" --rpc-addr ":9981" --api-addr ":9980"

If you want to use file system paths use the following:

docker run \
  --env SIA_WALLET_PASSWORD="YOUR SEED" \
  --env SIA_API_PASSWORD=apipass1 \
  --detach \
  --restart unless-stopped \
  -v /local/path/to/sia-data=/sia-data \
  -v /local/path/to/sia-storage=/sia-storage \
  --publish 127.0.0.1:9980:9980 \
  --publish 9981:9981 \
  --publish 9982:9982 \
  --publish 9983:9983 \
  --name sia \
   siacentral/sia -c --siamux-addr ":9983" --host-addr ":9982" --rpc-addr ":9981" --api-addr ":9980"

If you want to use multiple disks for storage you can mount them into different paths.

  -v /media/disk1=/sia-storage1 \
  -v /media/disk1=/sia-storage2 \

Starting the container for the first time and waiting for a complete sync can take a very long time, even after bootstrapping. You can check the progress using:

docker logs sia
Docker Logs

Show the Docker logs for the Sia container

In my case the initial startup tool 5.3 hours.

If you are on a host with a firewall or behind a router with NAT make sure to whitelist and forward the required TCP ports.

Add watchtower for automated updates

Watchtower is a service that automatically updates Docker containers to the newest version. By adding it, we will always run the latest version of Sia.

docker run -d --restart unless-stopped --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --include-stopped

Add an alias for running siac commands inside the Docker container

echo "alias siac=\"docker exec -it sia ./siac\"" >> ~/.bashrc && source ~/.bashrc

Initialize your wallet, configure and announce your Sia host

Either create a wallet with a new generated seed:

siac wallet init

Or initialize the wallet with an existing seed:

siac wallet init-seed

Generate an address and transfer some funds that will be used as collateral when hosting. Note: Once you initialized your wallet the blockchain will be scanned for transactions which takes quite some time.

siac wallet address

If you don’t have a static IP address for your server make sure to get a dynamic dns host always pointing to your IP and configure it using:

siac host config netaddress siahost.example.com:9982

Configure your pricing:

siac host config mincontractprice 1SC
siac host config minstorageprice 1000SC
siac host config collateral 2000SC
siac host config maxcollateral 1000SC
siac host config mindownloadbandwidthprice 3500SC
siac host config minuploadbandwidthprice 0SC

Set you total collateralbudget and make sure the value is slightly lower than the balance on your wallet (e.g. balance - 1SC). Otherwise you risk that all of your balance will be locked in contracts and there is not enough balance left to submit storage proof and finalize the contracts.

siac host config collateralbudget 100000SC

Assign some diskspace:

siac host folder add /sia-storage 10GB

Note: you might want to mount additional Disks as directories into the container.

Finally announce your host.

siac host announce

Final notes

If you have questions head over to the SIA Discord server and ask them in the hosting channel.