Add an external hard drive to a Subsonic Raspberry Pi server

Now that my Subsonic Raspberry Pi server is up and running, I wanted to add some media. My Pi is running with an 8Gb SD card but this is only enough for a few songs and ideally I would like my entire media collection available through Subsonic.

I had an old Terabyte external hard drive lying around which hasn’t worked for a while. A common cause of malfunction with an external hard drive is not with the hard drive itself but with the electronics in the caddy which communicate between the drive and the USB port.

I tested if this was what was going on with my drive by removing the hard drive from the case (read “smashed the case to bits, but gently”) and connected it to my desktop PC with a spare SATA cable. I fired up GParted (I’m running Ubuntu 12.04) and, luckily for me, I was able to see the drive as available. I was even able to get the old files off the drive which proved to me that the issue was with the caddy.

I decided that to get the best performance from my Subsonic Pi I should format the hard drive in one of the native Linux formats. I quickly decided on ext3 as it seems to give the best balance between stability and performance. (I decided this based pretty much on one blog post so I could well be completely wrong. All I know is that it is working well for me.)

To format the drive I used the mke2fs utility.

sudo mke2fs -L subsonic media -t ext3 /dev/sda1

The command above says “format the hard drive partition found at /dev/sda1. Use ext3 as the type of file system (-t) and give the new format the label of ‘subsonic media’ (-L)”. You will need to check the name of the partition you want to format first as it could be different from /dev/sda1.

The next job is to create a mount point so that we can easily access the files on the external hard drive once we’ve told the system where to find it.

sudo mkdir /media/subsonic

We also need to make sure that the mount point is owned by the user that the subsonic process is run by (in the first post I talked about creating a user to run subsonic for security).

sudo chown [subsonic user] /media/subsonic
sudo chgrp [subsonic user] /media/subsonic

Next we need to edit the fstab file. This file lists the devices which the system can mount. It is read at boot so by adding to it we can make the external drive accessible every time the Pi boots.
First of all I need to know the unique ID of the hard drive. To find this out I ran this command

sudo blkid

This will give an output similar to this

/dev/mmcblk0p1: SEC_TYPE="msdos" UUID="9DCF-4197" TYPE="vfat"
/dev/mmcblk0p2: UUID="f10ba0bd-17e0-4800-b0af-19bb2ed45acd" TYPE="ext4"
/dev/sda1: LABEL="subsonic media" UUID="8accdf5d-476-a240-1f4f645cc" TYPE="ext3"

The first two lines reference the Raspberry Pi’s SD Card so the one I’m after is the third. It should refer to the same partition you used in the mke2fs command as well as the label you set with it. The unique identifier is the long number after “UUID=”. If you highlight everything from “UUID=” to the end of the number and then right-click the ssh window, you can select ‘copy’ to save the number to the clipboard.

We then need to edit the fstab file. (I’m using vim as my editor here but you can use whatever is installed, which is nano by default)

sudo vim /etc/fstab

At the end of this file we need to add a new entry. The line should look like this

UUID="8accdf5d-476-a240-1f4f645cc"  /media/subsonic  ext3   defaults  0  0

The first part is the unique ID of the hard drive and the second is the mount point we set up just now. The third entry is the type of file system (as mentioned I used ext3) and the fourth, fifth and sixth entries should stay as ‘defaults’, ‘0’ and ‘0’. The entries should be separated by tabs so don’t copy the line above directly as I used two spaces.

Once you’ve edited and saved your fstab file you can ask the system to mount everything with this command

sudo mount -a

You won’t see a message to say that it’s worked but if you don’t see an error message it’s safe to say that it has. You now have a mounted hard drive which Subsonic can access and on which you can start to add your media.