What are UDEV rules?

by / Tuesday, 20 October 2015 / Published in Linux, Technical

Generally there are many devices connected to a system through external ports. Many of the devices are connected through USB ports. Whenever a USB device is connected to a system you can see the port it is connected through the dmesg command, which shows the device name under which the USB device got connected.

You can also use the lsusb command to figure out the vendor information of the connected device.

When there are multiple devices, the order in which they are deducted by the system decides the name of the device. For example, if I take two USB Storage devices, one would connect as /dev/ttyUSB0 and the other would connect as /dev/ttyUSB1. Which USB Storage devices joins under what name depends in the order in which they are inserted.

There are multiple programs which need a constant name for their operations. It could create a problem similar to that of having a dynamic IP instead of a static IP. The solution to this is to use UDEV rules. We can write rules based on the vendor, manufacturer, subsystem, serial number etc. These rules help us to define a unique name to a mounted device. They actually don’t change the name of the mount instead they provide a soft link from the name mentioned to the dynamic name assigned at the time of mounting.

UDEV rules are more powerful than that, they even allow you to run a script when a certain device is mounted. They also allow to change the permission of the mounted device.

You need to update the UDEV rules in a system file ( /etc/udev/rules.d/10-user-defined.rules ). We prefer giving a number at the start of the name of the file because the rules are checked in all the files in the directory in alphabetical order.

Leave a Reply

TOP