udev

udev is a userspace tool that is used for managing device files. udevd is the daemon that is responsible for settings up a device after it has been discovered. To manage and debug the behavior of udevd we have a utility command, udevadm. udevd gets its information on devices from sysfs.

sysfs

sysfs is a virtual filesystem that is implemented by the kernel and provides information of all of its connected devices. It follows a certain standard, that all of the information about a device has to broken up into attributes, which are each stored as a seperate file. We can explore sysfs at /sys where it is typically mounted.

Managing udevd with udevadm

All the paths that udevadm lists are relative to /sys. udevd's rules lie in /etc/udev/rules.d. udevadm comes with useful subcommands. Some of the important ones are

info

Outputs the info of a device, that is all of its attributes. Often used with these flags

  • -a for attribute walk. Traverses up the tree till /sys and outputs attributes of everything encountered.
  • -p for path. Used to target a device by giving a specific path (relative to sysfs)
  • -q <query>, where query if =path, we can find info on a device by giving its path as -n name