4 x 2.5" HDD RAID5 RASPBERRY PI
SIA HOSTING
(low-Intermediate level build)
What is this device: Background...
A company called Nebulous Labs has made a product called Sia. It allows hosts to rent out HDD space to users in exchange for SiaCoin (think of it as an alternative bitcoin) at a price far cheaper than Google drive or Amazon offers. Usually you would run their software to do this on a PC 24/7. I have created this as a more energy efficient option.
The program Sia requires a 64bit OS and that was overcome in this project by using a 64bit version of Gentoo.
When hosting other peoples files, the host (you) also lock a bit of SiaCoin into a contract as an incentive to be a loyal host and stay online. At the end of the storage contract if you have kept the file as promised you receive your collateral back plus the agreed fee as a reward. Because of this collateral I thought it sensible to arrange a RAID5 build, so in the event of a HDD failure, all files can be recovered and so not lose my collateral.
I think this will only interest a few people as a Sia hosting device, but mostly I think the Raspberry Pi community will like it as a low cost (Appox £90) low power (30w) NAS unit.
If your intention is to use it as a NAS I recommend "OpenMediaVault" as the software.
A company called Nebulous Labs has made a product called Sia. It allows hosts to rent out HDD space to users in exchange for SiaCoin (think of it as an alternative bitcoin) at a price far cheaper than Google drive or Amazon offers. Usually you would run their software to do this on a PC 24/7. I have created this as a more energy efficient option.
The program Sia requires a 64bit OS and that was overcome in this project by using a 64bit version of Gentoo.
When hosting other peoples files, the host (you) also lock a bit of SiaCoin into a contract as an incentive to be a loyal host and stay online. At the end of the storage contract if you have kept the file as promised you receive your collateral back plus the agreed fee as a reward. Because of this collateral I thought it sensible to arrange a RAID5 build, so in the event of a HDD failure, all files can be recovered and so not lose my collateral.
I think this will only interest a few people as a Sia hosting device, but mostly I think the Raspberry Pi community will like it as a low cost (Appox £90) low power (30w) NAS unit.
If your intention is to use it as a NAS I recommend "OpenMediaVault" as the software.
The guide is in two parts, a brief hardware overview, and a full software installation guide.
HARDWARE:
So, there are many projects in the crypto-currency scene that either require a large amount of storage for a blockchain or alternatively can rent out storage for income (Sia/Storj). And others like Burst actually mine on HDD. My thinking was that 2nd hand laptop HDD's would be the most compact but most importantly the cheapest method of storage. Also 2.5" SATA only requires a 5v input. (3.5" HDDs require 5v and 12v inputs) making laptop drives readily compatible with USB. If only there were adaptors for this.....There are! and they're very cheap also. |
This prototype is constructed using 4 x 40GB drives. As this is an experiment I wasn't going to go nuts with my overheads. They were £3.50 each from CEX which conveniently gives a 24 month warranty which may come in useful if this is a success and would take most of the risk away from hosting data on 2nd hand drives.
In theory, if it works with the cheap drives, it's just a case of scaling them to 2TB or 4TB drives with no additional software or hardware requirements. Just plug and play.
I've gone back to my trusted rack method of acrylic and motherboard risers, giving good ventilation and aesthetics at low cost. It's also very easy to work with and modular for future expansion, just add another layer.
The 6A power supply provides the 5v through the white wires, and are soldered directly to a USB hub (soldered to the barrel connector pins, with the hub sandwiched between the 4 drives). I show the construction below, layer by layer.
All drives are using the pig-tail type SATA adaptor to get their power from the hub only. The +5v pin on the USB to the Pi has been disconnected to prevent back-feeding. The USB hub is 7 port and so is also powering the Pi through it's micro USB connection.
The power supply is a 5v 6A DC out, 110/220v AC in and should be sufficient to power all drives and the pi. Each drive has a power rating on it's label of approx 0.7A (varied between the brands of drive I have, .7 is an average)
In theory, if it works with the cheap drives, it's just a case of scaling them to 2TB or 4TB drives with no additional software or hardware requirements. Just plug and play.
I've gone back to my trusted rack method of acrylic and motherboard risers, giving good ventilation and aesthetics at low cost. It's also very easy to work with and modular for future expansion, just add another layer.
The 6A power supply provides the 5v through the white wires, and are soldered directly to a USB hub (soldered to the barrel connector pins, with the hub sandwiched between the 4 drives). I show the construction below, layer by layer.
All drives are using the pig-tail type SATA adaptor to get their power from the hub only. The +5v pin on the USB to the Pi has been disconnected to prevent back-feeding. The USB hub is 7 port and so is also powering the Pi through it's micro USB connection.
The power supply is a 5v 6A DC out, 110/220v AC in and should be sufficient to power all drives and the pi. Each drive has a power rating on it's label of approx 0.7A (varied between the brands of drive I have, .7 is an average)
All images are thumbnails. Click to enlarge for detail.
Summary of parts:
4 x 40GB 2.5" HDDs £14 CEX link here
Raspberry Pi 3b £28.79 ebay link here
16Gb SD card (class 10) £5.20 ebay link here
Naked 7 port USB Hub £7 MOD MY PI link here
2 x A3 size, 3mm thick Acrylic £6 ebay link here
15cm USB to micro USB (pi power)£1 ebay link here
4 x Sata -> USB adapters £6.80 ebay link here
5v 6A 30W DC Power Supply £8.50 ebay link here Suitable plug required extra
M3 Nylon spacers/risers sets with screws/nuts. Many used and assembled to get desired height. Multiple kits approx £8 worth. £3.86 Free delivery ebay.
Total cost for this prototype approx £90
Estimated cost for 8TB version £325 (minebox £670)
Estimated cost for 16TB version £420 (minebox £1325)
I was just curious how a home build compared to a commercial build. I'm sure the mine box will be a great unit.
**Note all second hand drives from CEX come with 24 month warranty! (I don't work for them or get commission. It's just hands down the cheapest and most reliable place for components for crypto builds)
SOFTWARE:
Step (1) Preparing the Pi
Once again with this project the preparation steps are the same as for other nodes, I have made a beginner friendly guide with images, step-by-step that shows the basics of formatting the SD card and installing the disk-image. "Getting started" Link opens a new window.
Getting Started
Then continue below...
Once again with this project the preparation steps are the same as for other nodes, I have made a beginner friendly guide with images, step-by-step that shows the basics of formatting the SD card and installing the disk-image. "Getting started" Link opens a new window.
Getting Started
Then continue below...
Step (2) Updates
Once logged in via SSH as in the getting started page you'll be greeted with this screen.
From here we'll give the rest of the commands for the installation. The first thing to type is genup and it processes all the upgrades since the snapshot (disk image) we downloaded was made. This is one of the longest steps in the install. Please be patient. Approx 1 Hour 30mins. |
Step(3) User management
We have so far been using the <root> login.
For improved security we will change the default password for both root and the demouser (only other default account)
First the root password, type
passwd
and enter, then re-enter the new password.
The image we installed already ships with a user called "demouser" we will change it's name, password and permissions to use it.
First we stop any background processes "demouser" is running:
killall -u demouser
Then we change the username
usermod -d /home/putnewusernamehere -m -l putnewusernamehere demouser
We have so far been using the <root> login.
For improved security we will change the default password for both root and the demouser (only other default account)
First the root password, type
passwd
and enter, then re-enter the new password.
The image we installed already ships with a user called "demouser" we will change it's name, password and permissions to use it.
First we stop any background processes "demouser" is running:
killall -u demouser
Then we change the username
usermod -d /home/putnewusernamehere -m -l putnewusernamehere demouser
In my example I have changed "demouser" to my name "dan". Names must be lower case. Choose one you like, (unless you like mine?)
Then we reboot, with
sudo reboot
and login with the new username, the password will be "raspberrypi64".
Once logged in it would be smart to change this default password too with
passwd
The process is the same as before.
And finally we can change all the permissions of the folders so this new username has control of the folders and files with:
sudo chown ${USER} -R /home/${USER}
Then we reboot, with
sudo reboot
and login with the new username, the password will be "raspberrypi64".
Once logged in it would be smart to change this default password too with
passwd
The process is the same as before.
And finally we can change all the permissions of the folders so this new username has control of the folders and files with:
sudo chown ${USER} -R /home/${USER}
Step (4) Configuring the HDDs to RAID5
As this project is entirely storage centered there a quite a few steps, simple steps, to configure it.
First we can install a program called MDADM (Multiple Disk or Device Administration, so the wiki says?).
This will be what manages the 4 drives used here, you can use as many drives as you like if you can find a way to power and connect them!
We install it in 3 parts using "emerge" as our installer.
I think it's because we're forcing a 64bit install it will make an error, then that error can be automatically read and then corrected, (someone please correct me if that's BS) but first:
emerge --autounmask-write mdadm
To give the correction use
dispatch-conf
u
and then the actual install
emerge mdadm
As this project is entirely storage centered there a quite a few steps, simple steps, to configure it.
First we can install a program called MDADM (Multiple Disk or Device Administration, so the wiki says?).
This will be what manages the 4 drives used here, you can use as many drives as you like if you can find a way to power and connect them!
We install it in 3 parts using "emerge" as our installer.
I think it's because we're forcing a 64bit install it will make an error, then that error can be automatically read and then corrected, (someone please correct me if that's BS) but first:
emerge --autounmask-write mdadm
To give the correction use
dispatch-conf
u
and then the actual install
emerge mdadm
Now we have mdadm installed we can make the RAID. There are 3 commands shown to the left, first lsblk shows what USB devices are connected and recognized. Here listed as sda, sdb, sdc and sdd. (The mmcblk0 and its partitions are the SD card) Your Pi will 99% of the time list USB devices as shown to the left. Make a note of the letters a,b,c,d etc it has assigned. The next command builds the RAID drive: |
mdadm --create /dev/md0 --level=5 --raid-devices=4 /dev/sda /dev/sdb /dev/sdc /dev/sdd
Here, customize as you see fit. I'll explain:
"/dev/md0" is what the cluster of drives will be labeled as once the RAID is built. You can change this if you have another preference.
"--level=5" is the level of RAID that will be built, look at Standard RAID levels, WIKI for other options, simply change the number.
"--raid-devices=4" is the number of HDDs you want mdadm to use to create your RAID. (usually all of them)
and after that, separated by spaces, is the current label of every drive you want mdadm to use. If your Pi has labelled them something different this is where you would your specific drive labels.
Once you enter your command the HDD activity lights should flicker manically as it builds the drive. It does this in the background.
To check on it's build progress before progressing to the next step we use :
cat /proc/mdstat
As shown at the bottom of that last screenshot, devices used, a % progress of the build and an estimated time of completion.
**Note this prototype is 4x40GB drives, making /dev/md0 120GB usable storage and 40GB as unusable parity. It estimates 1 Hr for the build. This setup in theory will work exactly the same if four 500GB or 2TB drives were used, but expect the build time to rise accordingly.
Next, now that we have our RAID, we should create a partition and format it. The reason for this is that we can then get a PARTUUID (partition unique identification number) which is permanant and will allow for more stable and permanant mounting later.
Here, customize as you see fit. I'll explain:
"/dev/md0" is what the cluster of drives will be labeled as once the RAID is built. You can change this if you have another preference.
"--level=5" is the level of RAID that will be built, look at Standard RAID levels, WIKI for other options, simply change the number.
"--raid-devices=4" is the number of HDDs you want mdadm to use to create your RAID. (usually all of them)
and after that, separated by spaces, is the current label of every drive you want mdadm to use. If your Pi has labelled them something different this is where you would your specific drive labels.
Once you enter your command the HDD activity lights should flicker manically as it builds the drive. It does this in the background.
To check on it's build progress before progressing to the next step we use :
cat /proc/mdstat
As shown at the bottom of that last screenshot, devices used, a % progress of the build and an estimated time of completion.
**Note this prototype is 4x40GB drives, making /dev/md0 120GB usable storage and 40GB as unusable parity. It estimates 1 Hr for the build. This setup in theory will work exactly the same if four 500GB or 2TB drives were used, but expect the build time to rise accordingly.
Next, now that we have our RAID, we should create a partition and format it. The reason for this is that we can then get a PARTUUID (partition unique identification number) which is permanant and will allow for more stable and permanant mounting later.
This then adds the partition layer (p1) to each drive when lsblk is used again.
Use:
sudo mkfs.ext4 /dev/md127p1
To format the new partition to ext4.
Use:
sudo mkfs.ext4 /dev/md127p1
To format the new partition to ext4.
You'll notce the MOUNTPOINT column is empty.
Mount the partition for our use by entering sudo mount -o rw,auto /dev/md127p1 /home/${USER}/sia An explanation: -o rw,auto (-o,gives options, rw means read/write permissions, auto should automount) /dev/md127p1 (what to mount) /home/${USER}/sia (where to mount it) To be safe and avoid any problems we can also change the owner to "dan" or whatever your username is with. sudo chown ${USER} -R /home/${USER}/sia |
Our drive is completly good to go! MOUNTPOINT lists the partition as mounted to our desired destination!
Step(5) Installing "Screen"
Screen is a very useful program. It allows for multiple instances of terminal to be run, disconnected from the Pc they were started on and re-joined later. This will allow you to start the synchronization process of the blockchain for example, turn off or close the terminal window, and the sync process will continue on the Pi. Without it when you close the terminal window the process stops.
To install screen:
sudo emerge --ask app-misc/screen
It will ask if you want to merge packages. I used yes, assuming the command I just gave is a more up-to-date version.
Using screen is very easy.
The program is started using:
screen
This opens a new terminal window. It gives this window an ID number so we can find it later.
** For info, don't do this yet, but, to issue commands to "screen" press ctrl+a together. This enters command mode. Then pressing "d" detaches the screen to come back to later. I'll tell you when to do this further down the guide.
Screen is a very useful program. It allows for multiple instances of terminal to be run, disconnected from the Pc they were started on and re-joined later. This will allow you to start the synchronization process of the blockchain for example, turn off or close the terminal window, and the sync process will continue on the Pi. Without it when you close the terminal window the process stops.
To install screen:
sudo emerge --ask app-misc/screen
It will ask if you want to merge packages. I used yes, assuming the command I just gave is a more up-to-date version.
Using screen is very easy.
The program is started using:
screen
This opens a new terminal window. It gives this window an ID number so we can find it later.
** For info, don't do this yet, but, to issue commands to "screen" press ctrl+a together. This enters command mode. Then pressing "d" detaches the screen to come back to later. I'll tell you when to do this further down the guide.
Step(5) Install Sia
sudo emerge go
Is the first command for this very simple step.
Once "Go" is installed we use it to get the latest version of Sia
go get -u github.com/NebulousLabs/Sia/...
That command installs siad and siac into my /home/dan/go/bin directory.
Navigate to that directory...
cd $GOPATH/bin
Siad is run with
./siad -d --sia-directory
The -d flag specifies a directory which is /home/dan/sia for me.
The should place the wallet files and blockchain on the RAID to keep it safe and reduce read/write cycles on the SD card. Also if the blockchain becomes large the HDD array will deal with it better than the SD card size.
sudo emerge go
Is the first command for this very simple step.
Once "Go" is installed we use it to get the latest version of Sia
go get -u github.com/NebulousLabs/Sia/...
That command installs siad and siac into my /home/dan/go/bin directory.
Navigate to that directory...
cd $GOPATH/bin
Siad is run with
./siad -d --sia-directory
The -d flag specifies a directory which is /home/dan/sia for me.
The should place the wallet files and blockchain on the RAID to keep it safe and reduce read/write cycles on the SD card. Also if the blockchain becomes large the HDD array will deal with it better than the SD card size.
siad is now downloading the blockchain. On my build this took 56hours start to finish.
siad can be stopped by pressing ctrl+c. It will take a couple of minutes to shutdown the process in reverse order from (6/6) to (0/0).
With siad running, we can start siac to make our wallet and configure the hosting.
We want this to run in the background, and whilst it is we need to give commands to another program called "siac". This is why we installed screen.
Press ctrl+a together, release the a and press d
This detaches that instance of PUTTY/terminal and keeps siad that we just started running in the background.
You are free to shutdown your Pc or close the PUTTY window without siad ending.
**again for your information only to re-join the window we just detached from (if you want to close siad pehaps with ctrl+c) use
screen -ls
siad can be stopped by pressing ctrl+c. It will take a couple of minutes to shutdown the process in reverse order from (6/6) to (0/0).
With siad running, we can start siac to make our wallet and configure the hosting.
We want this to run in the background, and whilst it is we need to give commands to another program called "siac". This is why we installed screen.
Press ctrl+a together, release the a and press d
This detaches that instance of PUTTY/terminal and keeps siad that we just started running in the background.
You are free to shutdown your Pc or close the PUTTY window without siad ending.
**again for your information only to re-join the window we just detached from (if you want to close siad pehaps with ctrl+c) use
screen -ls
You then re-join the siad window by typing (in my case):
screen -r 6747.pts-1.pi64
In your version substitute the ID number used here for yours, obtained with screen -ls.
screen -r 6747.pts-1.pi64
In your version substitute the ID number used here for yours, obtained with screen -ls.
Step(6) Configure Sia hosting
Most of this information now comes from the official Sia Blog
https://blog.sia.tech/how-to-run-a-host-on-sia-2159ebc4725
Their blog is simple to follow.
I've continued this guide to add screenshots and as proof it works on the raspberry pi.
Most of this information now comes from the official Sia Blog
https://blog.sia.tech/how-to-run-a-host-on-sia-2159ebc4725
Their blog is simple to follow.
I've continued this guide to add screenshots and as proof it works on the raspberry pi.
It doesn't have to be completely synced in order to continue some of the setup...
To create a new wallet use: ./siac wallet init It will look similar to what's on the left. Obviously I've changed my seed to protect my funds used in this project. However I cannot stress enough how important it is to keep the seed it displays safe. If you loose it you will never get your funds back. Ever. No one can help you. Back the seed up. |
The next command is:
./siac wallet unlock
Where you will be promoted to enter the big long string you've just backed up. The unlock process took less than 5 mins.
./siac wallet unlock
Where you will be promoted to enter the big long string you've just backed up. The unlock process took less than 5 mins.
And for this new wallet we need a new address with:
./siac wallet address
./siac wallet address
In order to host files, I'm sure you're aware (if you've go to this point) you need Sia coins in this wallet. Use the address your Pi gives you to load some funds to continue with the next steps hosting.
I wouldn't recommend going crazy with funds just yet. As I said in the introduction this is a new method (using a Pi) and it would be wise to allow other users to look over this guide and highlight any security issues before committing a large amount of funds. In my project I'm going to experiment with 750sc to start.
With funds in the wallet we are nearly ready to start hosting.
First find out how much room is left on the drive to share.
df -h
I wouldn't recommend going crazy with funds just yet. As I said in the introduction this is a new method (using a Pi) and it would be wise to allow other users to look over this guide and highlight any security issues before committing a large amount of funds. In my project I'm going to experiment with 750sc to start.
With funds in the wallet we are nearly ready to start hosting.
First find out how much room is left on the drive to share.
df -h
Once again I'll say this is a prototype, but I see no reason why the 4 x 40Gb drives used in this array can't be swapped for 500Gb drives or larger. The configuration will be exactly the same.
I will allow 8Gb for the blockchain. This is more than sufficient to allow plenty of room for future growth. In May it was only 4Gb (approx). I'll round down and allocate 95Gb for hosting as a test. But ensure you allow enough spare room for the blockchain.
Siad has already created the folder /home/${USER}/sia/host for us.
So...
I will allow 8Gb for the blockchain. This is more than sufficient to allow plenty of room for future growth. In May it was only 4Gb (approx). I'll round down and allocate 95Gb for hosting as a test. But ensure you allow enough spare room for the blockchain.
Siad has already created the folder /home/${USER}/sia/host for us.
So...
Next we give Sia some more instructions on how much we wish to charge renters for storage:
./siac host config minstorageprice [price]
./siac host config mindownloadbandwidthprice [price]
./siac host config minuploadbandwidthprice [price]
./siac host config collateral [value]
./siac host config collateralbudget [value]
./siac host config maxcollateral [value]
These are the settings I used.
./siac host config minstorageprice 50SC
./siac host config mindownloadbandwidthprice 50SC
./siac host config minuploadbandwidthprice 10SC
./siac host config collateral 400SC
./siac host config collateralbudget 400SC
./siac host config maxcollateral 10000SC
Once these settings have been entered, line by line, the whole config package can be checked using:
./siac host -v
This displays:
./siac host config minstorageprice [price]
./siac host config mindownloadbandwidthprice [price]
./siac host config minuploadbandwidthprice [price]
./siac host config collateral [value]
./siac host config collateralbudget [value]
./siac host config maxcollateral [value]
These are the settings I used.
./siac host config minstorageprice 50SC
./siac host config mindownloadbandwidthprice 50SC
./siac host config minuploadbandwidthprice 10SC
./siac host config collateral 400SC
./siac host config collateralbudget 400SC
./siac host config maxcollateral 10000SC
Once these settings have been entered, line by line, the whole config package can be checked using:
./siac host -v
This displays:
This point now is as far as you can get until the blockchain has fully synchronized. Unfortunately it is a slow process, 56Hours at present (August '17). Please be patient, it's only a Pi!
That's it! Your device will broadcast it's contract fee's and conditions to the network and wait for someone to want its services.
The following commands may be useful:
./siac host -v Shows host financials, (number of contracts you hold and associated fees/revenue)
./siac Shows block height and synchronization status
./siac stop Sends the stop signal to siad to safely terminate.
./siac version Shows the current version number of siac and siad
./siac update Checks the server for updates.
The following commands may be useful:
./siac host -v Shows host financials, (number of contracts you hold and associated fees/revenue)
./siac Shows block height and synchronization status
./siac stop Sends the stop signal to siad to safely terminate.
./siac version Shows the current version number of siac and siad
./siac update Checks the server for updates.
System resources (info only):
With everything underway I was curious how the Pi was holding up to the requirements of Sia.
To check system resource use I typed the simple command
top
To display this:
With everything underway I was curious how the Pi was holding up to the requirements of Sia.
To check system resource use I typed the simple command
top
To display this:
This shows Siad using only 2% of the CPU available at idle, and low 40%s for the Memory usage of the 1Gb available. You can also see here there is a 1.5Gb extra RAM available as a swap file, unused.
These are currently a very rough guide only and I'll update this if necessary to show more representative figures once contracts are gained. I may have to change my fees/collateral to get contracts from the market.
Good luck with your device.
These are currently a very rough guide only and I'll update this if necessary to show more representative figures once contracts are gained. I may have to change my fees/collateral to get contracts from the market.
Good luck with your device.