Changing the world, one person at a time…

6 November 2004

One of the most annoying problem in Linux is dynamic device naming, especially for removable devices. For example, right now, when I push Hotsync button on my Palm Tungsten T3’s cradle, it will show up as /dev/usb/tts/1 and /dev/usb/tts/2. However, when I don’t have my P900’s cradle plugged in, it will show up as /dev/usb/tts/0 and /dev/usb/tts/1 instead. Likewise, whenever I plug in my digital camera, it will show up as either /dev/sde, /dev/sdf or /dev/sdg, depending on whether my USB flash disk and/or my USB hard drive are plugged in. Annoying, isn’t it? If the name changes, I have to modify my /etc/fstab or other configuration. I have to do that practically almost every time I plug in a new device.

udev promises to solve this problem. Udev replaces devfs which didn’t quite make it into most mainstream distributions. Unlike devfs, udev does have the feature to make naming of devices consistent. It does this by matching entries in config file to device properties.

Before static device naming works, I need to define some ‘rules’. Rules are devices definitions and their corresponding device nodes. After an hour fiddling with rules, I finally come up with rules describing all of my removable devices. The following is the rules I have created for my devices (lines are probably truncated).

With the above rules, my 4-in-1 USB card reader will show up as /dev/compactflash, /dev/smartmedia, /dev/securedigital and /dev/memorystick, respectively. Note that I don’t recommend reading Smartmedias with any card reader. I should have commented out the smartmedia line and sealed off the slot itself.