First off, any adventure into a project, you need a purpose. The purpose of this project is to create a computer serving a variety of uses for the household; network storage, wiki server. The network drive will be used for backup, transfer. The secondary goal is to make it as energy efficient as possible. Let’s get started.
The brains of the outfit will be a raspberry pi 2. (Pi3 About £35)
(rpi3 for illustration only)
- The rpi 2 shares usb bus with the network. This means the transfer speed from network to usb or vice versa will be limited to eachother; slow IO.
- The rpi *might* have enough usb power to spin up a portable 2.5″ harddrive but finding one proves difficult, and with little success. For this reason, I went for a 3.5″ powered caddy. This allows me to change the drive as I want, and also eliminates power issues. (I also like to believe 3.5″ disks are more hardy)
External Harddrive caddy
The caddy is a generic usb3 enabled unit that came with data and power cables.
- There is no active cooling, so heavy usage could bring temperatures up and put increased wear on the disk
- USB3 is not available on rpi (you will barely use USB bandwidth). **some people claim usb3 caddies/drives do not work with the pi2. In this case, I got lucky.
- Holds a single disk so unable to set up raid redundancy (unless you buy another)
The harddrive is one that I have decommissioned but used in this project for testing purposes. A 320gb Seagate SATA2 drive.
(Notice the “drive is almost dead” labelling; sad times)
The pi is booted by a 16gb class10 Kingston sd card and running a decluttered Raspbian Jessie image (uninstalling most of the bundled software still left files on the disk and in hindsight, I should have used a pre-uncluttered image)
As the Pi2 does not have built in WiFi, I will be using the ethernet port for network connectivity.
The external disk was formatted to NTFS. The reason for this is for compatibility with Windows machines, adding the ability to directly copy files to the drive. Raspbian supports NFTS partitions, however, I’m having some issues with Apache2 serving files from it. (It is defiantly a permissions issue and if I find a solution, I will document it here)
I set up samba on the rpi2 to share files from the external harddrive to my (predominantly) Windows network. Samba is a widely used and documented server application for linux, to serve files or devices within a Windows workgroup. It works seamlessly with Windows and linux clients, allowing the connecting OS to also map the partition as a network drive. (Due to the next section, I would refrain from mapping the drive)
hdparm is a useful application to manipulate harddrive functions (widely used to set power-saving attributes). I have set the rpi to spin-down the external harddrive, after 30 minutes of inactivity with this utility.
I had some trouble initially, as I wanted the settings to persist through reboot. There are several ways to do this, but to make sure the .conf settings worked, I set the drive to spin down after 5 seconds. Reboot the pi and if the drive spins down almost immediately, its working.
Some users have experienced incompatibilities with some disks on rpi, but there are alternatives available.
mysql & apache2
My MediaWiki site is run off of a simple mysql and apache2 pairing. I’m not a big fan of lamp stacks, but they will work just fine also.
After tinkering around with the configuration, I have a fairly cheap, complete and fully customisable NAS server. Not only being cheap, but cheaper still by powering down the disks and saving on electricity. It’s not as fast as a dedicated commercial unit, but I think a bit of patience is outweighed by the overall benefits. And if things don’t work out, you can re-use the parts individually too!
It’s probably not a good idea to have a growing database or even a swap file on the SD memory (because of wear) but regular backups should help towards mitigating against failure. I may create a bash script to automatically backup the SD contents to the external drive regularly. It’s also a good idea to backup separately a mysql dump too.