Zen and the art of udev configuration

If you have a pen drive and use it on your Linux system, no doubt you have experienced the problem where it seems to get assigned a different device ID every time you plug it in. Whilst only a minor inconvenience in some respects, it’s a pain in the rear when you want to automount devices and assign user rights to them. The problem actually extends to many USB devices, such as card readers and usb hard disks; read on for those too.

There is lots of really great advise out there on how to use udev, but it’s often so comprehensive that it takes me a while to decipher it. There’s also an issue with Kernel releases that seemingly results in different configs for different versions. All the following stuff only works on a 2.6.x kernel. In fact all udev stuff only works on 2.6 kernels: It wasn’t in previous versions.

Install required packages

  • apt-get update
  • apt-get install udev hotplug

Identify the device

  • cd /sys/block
  • Do an ‘ls’ and take note of what’s there.
  • Plug the USB device in.
  • Do another ‘ls’ and take note of what’s new in there.

Get the device details

  • Issue a ‘udevinfo -a -p /sys/block/identified_device
  • Take note of two items from the response ‘Bus’ and one of the SYSFS lines that best identifies the device to you, (Vendor or Model are usually good).

Edit the configuration

  • Create ‘/etc/udev/rules.d/010_usbstuff.rules’
  • Insert: BUS=”scsi”, SYSFS{vendor}=”Foo”, NAME=”usb/flash%n”
  • The above line assumes your devices’ Bus was ‘scsi’, you chose to use the SYSFS vendor parameter and you want the device registered as /dev/usb/flash. The %n on the end adds the kernel number to devices such as partitioned disks (sda1, sda2, etc.).

Test it

  • Issue a ‘udevstart’ command
  • ‘ls /dev/usb’
  • If the ‘flash’ device is listed, then it worked.

Mounting it for users

  • Edit /etc/fstab
  • /dev/usb/flash1 /mnt/flash auto rw,user,noauto,umask=000 0 0
  • This assumes you want the device ‘flash1’ writable by users and mounted as /mnt/flash.

This entry was posted in Debian. Bookmark the permalink.

Leave a Reply