How can you assign static device name using udev rules to a USB device? Why do you need it?
Imagine you made a script which refers to a particular device you could plugin trough USB port: sometimes this device could be mounted as /dev/sdb1, sometimes as /dev/sdc1, and so on. You may need a static reference to it because you didn’t know which name it will use.
Another scenario could be a startup mount of a drive as discussed in https://w3ma.com/mount-ntfs-partition-startup/
To achieve this, let first discover some attributes of our device using the command
We will receive an output like this:
Have a look at the Western Digital Technologies row, this is the device we are looking for: 1058 is the Vendor ID and 107c is the Product ID! We will use these information to uniquely identify our device.
Now, let’s create a new udev rule typing
and writing the following into the file
where the ATTRS numbers are the ones we discovered before, while my_wd_usb_hd is the name we choose for our device.
Now let’s reboot our pc! Everytime it reboots this rule will be applied and we will always find our device under /dev/my_wd_usb_hd