Friday, January 04, 2013

Raspberry PI USB automounting

Update May 13: This is no longer necessary - raspbmc does automount the drives now.

Somehow I thought that the Raspbmc OS variant would automount my USB drives, but it didn't. I tried installing usbmount, a Debian package, but didn't get the automount at boot to work.
So I gave autofs a shot, which on Raspbmc, my distro, is already installed.

[Edit: With Raspbmc 1.0, it's no longer there, so I installed it with

sudo apt-get install autofs

Then I found that both drives are already mounted in /media, so the rest here is no longer necessary!!
I am unsure now whether they are now mounted because something else than autofs now ships with raspbmc or whether the default autofs installation took care of it

I took me some reading, but I got both USB drives to automount with autofs. The Multimedia drive is an NTFS file system, whereas I formatted the other one as HFS+ to be used as a Time Machine drive for my wife's Mac.

There are two files that I needed to touch: /etc/auto.master and /etc/

In auto.master, I needed to comment out everything, including


and then added at the end

/mnt/auto /etc/ --timeout=120 --ghost

This last line tells autofs that it should look at the lines in /etc/ and mount those in under /mnt/auto. The --ghost option causes autofs to create the directories there before they are mounted. After 120 seconds inactivity they will be unmounted.

In /etc/, I put

mm      -fstype=ntfs-3g,defaults,noauto,rw,uid=pi,gid=pi          :/dev/disk/by-uuid/844019F84019F222
tm      -fstype=hfsplus,defaults,noauto,rw       :/dev/disk/by-uuid/d5fd173f-c472-3594-8448-e61b466a52a0

This is almost self-explanatory, but it took me a while to get to the disk/by-uuid trick. /dev/sda1 etc would not work if I ever unplugged the drives and reconnected them in a different order as the OS assigns them different letters then (I read this can be fixed with an entry in the udev config, but I didn't go far enough with it). Usage of disk/by-label seems widespread, but my disk labels contain spaces, and I couldn't figure out how to encode this in Ditto with the colons in disk/by-id!

After that I had the ntfs drive under /mnt/auto/mm and the Apple drive under /mnt/auto/tm. Automounting worked after restarting the autofs daemon with

/etc/init.d/autofs restart

I confirmed that this still worked after reboot. Now that I can see my music, on to forked-daapd for serving music with iTunes protocol!

No comments: