Adam Richardson's Site

udev Notes

Table of Contents

<2022-08-03 Wed>

Resources

Getting Info About a Device

  • To see info about /dev/foo run udevadm info /dev/foo

Rules

Naming Rules

  • They must have the file extension .rules
  • The files must be prefixed with a two digit number
  • The number specifies the order that the rule will be applied
  • Typically user rules are between 61 and less than 99

Locations

  • udev rules reside in the /etc/udev/rules.d folder
  • Packages include udev rules and are in /usr/lib/udev/rules.d
  • The rules inside /etc take precedence over the /usr/lib rules

Example USB TTY Rule

  • This example rule should set a USB TTY device that matches the vendor ID and product ID to have the permissions 0666 or read and write for all users
  • This rule could be named 61-usb-serial-read-write.rules
SUBSYSTEM=="tty", ATTRS{idVendor}=="dead", ATTRS{idProduct}=="beef", MODE="0666"

Testing Rules

  • If you want to test newly created rules before applying them you can use udevadm test
  • You will need to use the /devices/ path of the device to test the rules
  • For example, sudo udevadm test /devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/ttyUSB0/tty/ttyUSB0

Reloading Rules

  • To reload the current rules run sudo udevadm control --reload-rules then sudo udevadm trigger