Table of Contents

Creating Specific Rules for Devices

Usually, rules are placed in files under the /etc/udev/rules.d directory where each rule performs some action depending on some user-specified criteria that matches a connected devices. For instance, a modem may be connected to a computer and the kernel will assign via udev a device node under /dev/ - however, in most cases, the actual name is chosen by the kernel (conventionally incrementally, depending on the number of already connected devices). Unfortunately, one cannot know beforehand if, following the example, a modem device will be assigned to /dev/ttyACM0 or /dev/ttyACM1, etc…

To make sure that a device gets the same node under devfs via udev, rules can be added under /etc/udev/rules.d and those rules can match hardware criteria such as vendor ID, revision, etc… The first step is to issue the command:

udevadm info -q all -n /dev/ttyACM0 --attribute-walk

where:

The command will output attributes, such as ATTRS{idProduct}, ATTRS{idVendor}, etc… Information that can then be used to construct an udev rule.

For instance, to match and USB device with an idProduct attribute of 0723 and an idVendor of 05e3, one could create a file at /etc/udev.d/rules/80-mydevice.rules containing:

SUBSYSTEM=="usb",ATTRS{idProduct}=="0723",ATTRS{idVendor}=="05e3",SYMLINK+="mydevice",RUN+="echo boo >/dev/null"

which will:

Reloading Udev Rules

Remember that issuing:

udevadm control --reload-rules

is insufficient and that you have to issue:

systemctl restart udev.service

to make the rules effective.

Trigger Action for Particular Set of Rules

To trigger the net subsystem rules that bind to the add action, issue:

udevadm trigger --attr-match=subsystem=net --action="add"