I recently developed a web-based slide show system with a simple user interface. When the user inserts a compact flash card containing images from a digital camera into a USB card reader, the system uploads the images to a web server which then displays the images on a number of networked media players.
I built and tested the system using my development machine (Ubuntu Desktop 12.04) and USB Flash drives since I didn’t have any compact flash cards at hand. Since the user interacts with the system only through the card reader, I deployed the system (a Java drive-watcher daemon and a Java web application) on a headless computer running Ubuntu Server and replaced the flash drives with a 7-in-one card reader.
It didn’t work.
Thus began my education in auto-mounting. Here’s what I learned which may help others implement auto-mounting on their own Ubuntu Servers.
Desktop vs. Server
Ubuntu Server is great for old, headless computers as it is very light on resources, boots quickly, and has few frills than can cause problems. Of course, it also lacks the Gnome Desktop, which is unfortunate as that is where the auto-mount magic resides in the Ubuntu Desktop edition. Sure, a trimmed-down version of Ubuntu Desktop could work, but the auto-mount features of the Gnome Desktop will only work when a user is logged on, so that isn’t really a good solution for a headless server.
usbmount is a simply utility that detects and mounts USB flash drives. Install it (sudo apt-get install usbmount), insert a flash drive, and the filesystem is automatically mounted under /media/usbX.
If only things were that simple. While usbmount works well for flash drives, it fails to perform for card readers.
Flash Drives vs. Flash Cards
Since usbmount works for flash drives but not flash cards, there must be a difference between the two.
What I call a flash drive is a USB device and flash storage packaged together into keychain dongle. Mp3 players, iPhones, and external hard drives also fall into this category. The key distinction is that the media cannot be separated from the USB device.
This is contrary to a USB card reader, which is a USB device with removable storage. Typically the USB device remains attached to the computer while the media is inserted and removed. Swapping memory cards doesn’t generate any USB events, so usbmount just sits there oblivious to the fact that new storage is available.
udisks is behind the Gnome Desktop’s automount magic. It generates events when disks change so applications like Gnome can listen and take action. Another application that listens for udisks messages is udisks-glue, which is, “A tool to associate udisks events to user-defined actions”. Install both (sudo apt-get install udisks udisks-glue), edit /etc/udisks-glue.conf to suit, and your Ubuntu Server will now automount.
Configuring Ubuntu Server to automount is actually quite simple:
- sudo apt-get install usbmount udisks udisks-glue
- edit /etc/udisks-glue.conf if necessary. Consult the man page for details. I didn’t need to change anything.
- start udisks-glue at boot by adding “/usr/bin/udisks-glue” to /etc/rc.local or use this init script.
These few steps were all I needed to get my slideshow drive-watcher running with flash drives and flash cards on Ubuntu Server.