6 November 2004

Using udev for Static Device Naming

Posted under: at 01:44

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).

BUS="scsi", ID="*:0", SYSFS{model}="STORAGE DEVICE  ", 
    SYSFS{vendor}="Generic ", KERNEL="sd?1",
BUS="scsi", ID="*:1", SYSFS{model}="STORAGE DEVICE  ",
    SYSFS{vendor}="Generic ", KERNEL="sd?1",
BUS="scsi", ID="*:2", SYSFS{model}="STORAGE DEVICE  ",
    SYSFS{vendor}="Generic ", KERNEL="sd?1",
BUS="scsi", ID="*:3", SYSFS{model}="STORAGE DEVICE  ",
    SYSFS{vendor}="Generic ", KERNEL="sd?1",

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.

BUS="usb", SYSFS{serial}="11100E000059CD7D",

The above is for naming my USB hard drive as /dev/usbhd. The parameter ‘all_partitions’ means it will also create all possible partitions from /dev/usbhd1 to /dev/usbhd16.

BUS="usb", SYSFS{serial}="K509501827090315AA",
    KERNEL="sd?1", NAME="lexar64mb"

The above is for naming my 64 MB Lexar USB flash disk.

BUS="usb", SYSFS{product}="SEMC DSS-20 SyncStation",
    SYSFS{serial}="0000A6UR", NAME="p900"

This is for my P900 cradle, nothing special there.

BUS="usb", SYSFS{serial}="3030563541384A333244414E",
    SYSFS{manufacturer}="Palm,Inc.", NAME="tungsten%e"

The above is for my Palm Tungsten T3. It will create two device nodes /dev/tungsten and /dev/tungsten1 when the Hotsync button is pressed. One node is for Hotsync, the other is for PPP networking.

BUS="usb", SYSFS{manufacturer}="OLYMPUS",
    SYSFS{product}="C4100Z/C4000Z", SYSFS{serial}="000237628898",
    KERNEL="sd?1", NAME="c4000"

The above is for my Olympus C4000z digital camera. Nothing special there.

For more information on how to set up udev, refer to these excellent guide: Decibel’s UDEV Setup, Gentoo udev Guide, and Howto Migrate to UDEV. Most of them are Gentoo specific, but should also applicable to other distribution. For information on how to set up udev rules, see the excellen guide ‘Writing udev rules‘.

2 Responses

Trackback: Use this URI to trackback this entry. Use your web browser's function to copy it to your blog posting.

Comment RSS: You can track conversation in this page by using this page's Comments RSS (XML)

Gravatar: You can have a picture next to each of your comments by getting a Gravatar.

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Warning: Comments carrying links to questionable sites will be removed!