Home file Server with your Preferred SBC!
BOARDS
Home file Server with your Preferred SBC!
2015-10-13
By
David "DeMO" Martínez Oliveira

Everybody needs somebody and everybody also needs a file server at home. For some years, I was using a Fiono box but it was not really fulfilling my needs. The fan in the box was very noisy and I had to run over maintenance cycles very often.
UPDATED:16 Nov 2015
Besides that, as a matter of fact, every two years I had to replace the hard drive in the machine. I do not know if that was because some misconfiguration, because of those Western Digital hard drives (that's the only brand I ever had issues with) or because of the Fiono box itself. Anyhow, after the death of the second hard drive, I started to look for alternatives.

Using a Small ARM Board as Home Server

I was running a home file server years ago using a quite modest machine. Something like a Pentium 150MHz with 4MB of RAM (my first machine running GNU/Linux back in the late 90s). That machine was OK running a NFS server and sharing a drive among a couple of other machines in my home local network. Nowadays, any of those SBCs out there are way better than that.

I tried a bunch of those. The Rpi was a bit on the edge but it was working Ok. I do not have strong performance requirements, the most demanding function I need is to access my holiday movies from my living room TV (you know to bother unexpected visits :).

The BeagleBone Black was also OK (with better performance actually) but that is a monster for interfacing to external stuff so I keep it for other projects.

So I got an Olinuxino, I had talked about this some weeks ago. This one also works great, and it provides a SATA interface to directly connect a external hardrive. Despite of leaving the USB ports free, HD performance is better than SD-card.

Just a picture of how is it looking right now.

Olinuxino Lime 2 home server
My Olinuxino Lime 2 Home Server Running full speed

Yes, I need a box to put everything in.... that will come later.

Even when this is damn simple, just in case you haven't hear before how to run your SBC on a external hard drive, I'll give you some advice.

The first thing you have to note down is that, what we are describing here works with your Olinuxino, BeagleBone Black, Raspberry Pi, Arrieta G25,... Any SBC.

BOOTING YOUR BOARD FROM A HD

The process is really simple:

1. Format your hard-drive as per your needs. I usually just create one big partition plus a swap partition. Depending on the usage you will give to the server, the swap might not be needed. Anyhow, a swap partition on a hard drive wouldn't hurt.

2. Install your favorite Linux distribution on your SBC normally (on a SD-Card). Follow the process for your specific board. Eventually, you will have a running system, typically on an SD-Card. In general, you will need the SD-Card to boot up the board in any case as most of these boards cannot boot directly from any other device.

3. Copy the root filesystem from your system sdcard into the hard drive and update configuration.

4. Update the kernel command line in your booting environment.

Yes, it is that easy... well, maybe some of you would appreciate a bit more details for steps 3 and 4.

COPYING THE ROOT FILESYSTEM

Most of the SBCs boot up from a SD card. Also, most of them use two partitions on the SD card. Actually, all the SBCs I have ever worked with have these two partitions. However, it might be some other boards out there providing other options.

Anyhow, the first partition is the so-called boot partition. It is usually small and contains 4 or 5 files, the minimal information to actually boot up the board. The second partition contains the root filesystem. This one should contain a lot of files and should look like a standard Linux filesystem (you know, /etc, /usr, etc...).

The first thing we have to do is to mount the partitions. If you are copying the files in your usual Linux Box, the hard drive and SDcard will probably get automatically mounted somewhere under /media. In case you want to copy the files live on your board, there are many chances you have to mount them manually.

# mkdir /mnt/sdcard
# mkdir /mnt/hd
# mount /dev/sda1 /mnt/hdd
# mount /dev/mmcblk0p2 /mnt/sdcard

Double check that you are mounted the right partition before you start copying data.

So, as mentioned before, usually the second partition on our sdcard is the one we are interested on. Should be mmcblk0p2, but better you check before starting copying (use for instance the command mount to check where is your root filesystem mounted). For this copy, either use the tar tool, rsync or add the -a flag on the cp command:

# cp -a /mnt/sdcard /mnt/hdd

When copying the files we have to take care of file attributes, specifically the owner and the symbolic links. That's why a simple copy may produce us a terrible headache. If you are copying the files from a live system, (for instance because you are copying your files using your SBC booted from the sdcard you want to copy into the external HD), remember to empty the tmpfs... usually /dev, /proc and /sys. Check your mount points with the mount command to get the full list.

When you are done copying the files into the hard-drive you will have to update your /etc/fstab to let your system know where your root file system is now. Mine looks like this:

/dev/sda1 /    ext4  defaults, noatime, nodiratime, data=writeback, commit=600, errors=remount-ro  0 0
/dev/sda2 none swap  sw 0 0 

The first line indicates where my root filesystem is. This is the one you have to change. It would be pointing to your sdcard. The second one is needed in case you want to use a swap partition on your hard-drive.

Do not forget to unmount your partitions before disconnection your devices.

CHANGING THE BOOTING PARAMETERS

This part might change a little bit between the different SBC, but not much. Basically you need to find the file where the kernel command line is specified. It should look like this:

console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait=2

Those parameters may vary slightly between different Linux systems but, for us the important parameter is root. This parameter tells the Linux kernel which device contains the actual root filesystem. That /dev/mmcblk0 in the example above, is actually how Linux names the SD Cards. We want to use a external disk, either a SATA or a USB one. In any case, the disk will be recognised as /dev/sda1, and that is the value we have to give to the root parameter to the kernel.

The table below indicates which file contains the line to change for different boards:

Rpicmdline.txt
change root parameter
BBBuEnv.txt
Standard UBoot stuff. Look for partition name /dev/mmcblk0p2
OlinuxinouEnv.txt
Uboot based
Arrieta Seems like you have to recompile at91bootstrap configure normally... then add these parameters to kernel
mem=128M console=ttyS0,115200 root=/dev/mmcblk0p2 rootdelay=2.
Not tested.

Then you just have to edit the appropriate file for your SBC and make it point to your external hardrive partition. As mentioned above, this partition is usually /dev/sda1 but note that you may want to have multiple partitions to boot different systems and in that case the last number will change.

Colofon

Basically this is it. Overall, you will notice an improvement on responsiveness, specially for boards in the low range of the spectrum (i.e. the original Rpi) and the life of your system should be longer... you know, sdcards use to die, even when you do all well-known configuration gymnastics :)
Just in case: SBC stands for Single Board Computer