I have long wanted a fileserver in my home. Until the raspberry pi came along
the power consumption was more than I felt reasonable.
The aim was to have a server
that consumes less than 10 watts, thats 2Amps at 5Volts. My other main
requirement was not having to open up a remote shell session for some common actions.
So this is my solution, based on a raspberry pi and a
humble pi prototype board (http://shop.ciseco.co.uk/k001-humble-pi/).
The aim is to be able to unplug a hard disk to take with me when out of the house and then
sync the two disks when I return, so instead of using a RAID setup I am going to use rsync to copy
files back and forth.
I have used the humble pi to add 4 switches and four leds to a basic raspberry pi.
the great thing about the humble pi is that it's profile is such that it will mount in an off the
shelf pi case with a few holes drilled in the top.
Hardware
I have two USB 2.5" hard drives, 1TB each. They need a powered hub, I found one in my bits boxes
that was a travel hub but also had a power input.
On investigation this was wired to all downstream ports with a blocker diode upstream.
The humble pi and its bits and pieces, as you may see I chopped the board slightly as my case has a
viewing hole for the on board LEDs.
And here it is attached to a piece of plywood using a mixture of screws, velcro and double
sided mounting tape. The velcro for the disk that are currently on top of each other. Just
some labels needed for the buttons.
Software
Bespoke
I created a small python program to monitor the switches and control the LEDs using the rpi-gpio module.
This uses some external scripts to do the grunt work using rsync.
Two of the LEDs show the status of the hard disks, LED off no disk attached,
LED on disk attached and mounted, LED flashing disk being unmounted. There are two switches that are used
to initiate unmounting the relevnt hard disk.
One of the LEDs is switched on when the python script starts and switched off when the script exits. The associated switch initiates a halt of the server.
The final switch and LED are used to show the status of the rsync operations and to initiate an rsync. The
LED flashes when an rsync is running, the switch will trigger rsync to run now.
The software monitors the configured disk device names, if a disk is plugged into the USB port this is
then mounted. If after mounting a disk both disks are present rsync is initiated immediatly.
Source code on github https://github.com/LawrenceK/fs_monitor .
Standard packages
Samba is installed with a couple of samba users created, I share the complete disk to one of the users
and user specific home directories to other users.
hdparm is installed so we can configure disk power down.
supervisor is installed to manage the bespoke software.
sudo apt-get hdparm samba supervisor
Configuration
mountpoints
Create the dirctories /mnt/diskA and /mnt/diskB as mount points for the two hard disks.
fstab
Add entries to /etc/fstab for /dev/sda1 and /dev/sdb1.
hdparm.conf
Add the following to hdparm.conf to enable disk spindown, this may not be supported by your usb drives.
/dev/sda {
spindown_time = 241
}
/dev/sdb {
spindown_time = 241
}
After thoughts
I tried using udev rules to handle mounting but found that it ended up mounting the drives to early
in the boot process such that the file system check did not get run. This was for drives that where
allready plugged in at boot.
The supervisor package appears to be a dream of a package to handle daemonizing
small python scripts such as this.
It is always tempting just to hack an init.d script that kind of works, but is always platform
specific, with supervisor the conf file is platform neutral.
Further enhancments
Use external scripts to handle mount so that a file system check can be run first.