Statically Assign /dev Nodes to Hardware Devices in Linux

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.

ATTRS{vendor}=="ST350032", SYMLINK+="video"
ATTRS{vendor}=="ST316002", SYMLINK+="media"

3.) Use the following command to restart udev and then unplug and re-plugin the device to verify that you indeed have a new /dev/mydevice node.

/etc/init.d/udev restart

You can then further take advantage of this by editing your /etc/fstab file to automatically mount the drive. Like mine for example:

/dev/video     /mnt/video     ntfs-3g     defaults,locale=en_US.utf8   0    0
/dev/media     /mnt/media     ntfs-3g     defaults,locale=en_US.utf8   0    0

Additional Information:

Additional Guides:

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 1 Comment So Far

  • www.vescomwallcovering.fr
    April 21st, 2016 at 7:10 pm

    Statically Assign /dev Nodes to Hardware Devices in Linux | The Linux Daily. Certainly high resolution film quality includes much memory, that why it provides improved quality.

Share your thoughts, leave a comment!