Sunday, September 06, 2009

mount usb disks using by-label

When the screen on my old family laptop died a few years ago, I found the perfect use for it: as a headless server on the family network. Running Ubuntu 9.04 Server, this laptop primarily acts as a file server on the network, dishing out bits to a wide variety of clients (Mac, PC, iPod Touch and an Xbox 360). The internal hard drive is relatively small, and pretty much used only as the system drive; an external 500 GB USB drive holds data, and I recently added a second 1 TB USB drive to give the growing bit collection some much needed breathing room.

The addition of the second USB drive, however, has exacerbated an annoyance that I've suffered since setting this system up: the challenge of configuring consistent mount points. The USB drives appear as SCSI drives to Ubuntu, and therefore show up as /dev/sd* in the /dev hierarchy. Although Ubuntu magically handles recognition of the drives as they are plugged in or unplugged from the server, the drives don't consistently show up as a particular sd* device. I don't often unplug these drives, but when I do and then plug them back in (or when the system has been restarted), I have to hunt around the /dev directory, find the correct sd* device, and then manually mount the drive. With one drive, I could easily tell which sd* device had just been added to the system: with two, it became troublesome enough that I searched for some better way to handle my USB drives.

Luckily, I quickly stumbled on this howto article describing a hierarchy under /dev that I've never explored before: /dev/disk (argh!). In a nutshell, labels and other identifiers associated with filesystems on attached drives can be used to consistently reference those drive and mount them. Better yet, I discovered that the volume label on my FAT32 drives was automatically recognized, making the mounting operation as simple as shown by the example below:
Since the drives can be referenced in a consistent manner, I've *finally* been able to add them in fstab, making mount and umount operations *much* easier to deal with! 


  1. After you told me about this I was trying to find out if my box had the by-disk devices and came across a posting claiming that by-label was 'broken by design'. Instead, they suggested using LABEL=mylabel in fstab instead of /dev/sd??.

  2. Link:

  3. Interesting... I like the simpler LABEL syntax, but was worried that it may not be supported in Ubuntu (the post discusses a Debian system). I know Ubuntu is based on Debian, and a quick search turned up this Ubuntu help page for fstab:

    Looks like Ubuntu does support the LABEL syntax in fstab, and I've tweaked my fstab file to use LABEL. Thanks, Jeff!