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:
/dev/ttyACM0
is the connected device you want to query for hardware details.
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:
idProduct
of 0723
,idVendor
of 05e3
,/dev/
as /dev/mydevice
,echo boo >/dev/null
Remember that issuing:
udevadm control --reload-rules
is insufficient and that you have to issue:
systemctl restart udev.service
to make the rules effective.
To trigger the net
subsystem rules that bind to the add
action, issue:
udevadm trigger --attr-match=subsystem=net --action="add"