Tutorials, Guides, Tips, and Tricks from Everyday Experiences

A handy trick for always making sure that a particular device is assigned a particular node in /dev is to use local udev rules. This way, you’ll always know that the device you plug in will always be at the same spot (ie. your USB thumb drive will always mount to /dev/thumb instead of /dev/sdxx). Some folks may refer to this as static assignment or forcing a /dev node. I took advantage of udev local.rules so that my 160GB external HDD with media will always mount to /dev/media and my 500GB external HDD with video will always mount to /dev/video. This way, I can edit my fstab rules to always mount /dev/media to /mnt/media and /dev/video to /mnt/video and I don’t have to guess which HDD belongs to /dev/sdb or /dev/sdc. Here are the steps I took:

1.) Plug in your device and find out which /dev node it was assigned by using “dmesg” output or “fdisk -l”. Then, get a unique piece of information about it. As long as it is unique, it should work. In my case, each HDD has a different model number, so I used the ATTRS{vendor} attribute as a unique identifier. Use the following command to view device information:

udevinfo -a -p $(udevinfo -q path -n /dev/sdb)

2.) You’ll need to create a local.rules file and fill it with the unique information from the above command (see my example below).

touch /etc/udev/rules.d/10-local.rules

My example:
This tells udev to create a symlink to /dev/video when a device with a vendor attribute of ST350032 is detected and the same applies for line two.