Udev: Assign unique names to your devices

From Bitpost wiki
Jump to: navigation, search

[udev] was born for this job. This is fun stuff! (I'm a sick geek.)

  1. Make sure you've emerged [sys-fs/udev] and [sys-apps/baselayout].
  2. Put [/etc/udev/rules.d/10-local.rules] under version control, you're going to put your rules there.
  3. Make sure the kernel has the following enabled:
    File systems --->
      Pseudo filesystems --->
        [*] /proc file system support
        [*] Virtual memory file system support (former shm fs)
  4. Run [lsusb], plug your device in, run it again and compare. This will show you the bus+device+deviceid. For USB devices, you can use the Device ID as a unique identifier.
  5. If needed, run [lsusb -D /proc/bus/usb/#bus#/#device#] to find out everything about your device.
  6. If you still want more help, plug in your device while watching /var/log/messages to get the dev path, then use this to get more udev identifiers:
    udevinfo -a -p `udevinfo -q path -n /dev/sda`
  7. Write a rule using the selected identifier. Add it to [/etc/udev/rules.d/10-local.rules]. Here's one using a device with ID [090c:6000]:
    BUS=="usb", SYSFS{idVendor}=="090c", SYSFS{idProduct}=="6000", NAME="sdhc_via_usb"
  8. Tell udev to reload rules, and wait for it to finish:
    udevadm control --reload_rules
    udevadm trigger
    udevadm settle
  9. Remove and re-plugin your device. It should now show up at [/dev/your_name]!
  10. If it's a drive, add a mount rule to [/etc/fstab] like this:
    /dev/sdhc_via_usb /mnt/8gb_sdhc vfat
  11. Now you can mount your device reliably, using the mount path, no matter where you plug in your device, or what order you plug it in.
    mount /mnt/8gb_sdhc
    Pretty cool, eh?

Next, we'll work on automounting your device when it is inserted...