udevadm
Learn how to use udevadm to inspect device properties, explore sysfs paths, monitor udev events, test udev rules, and debug hardware on Linux systems.
Find the sysfs path for our bluetooth interface
udevadm info -q path -p /sys/class/bluetooth/hci0
Show full dump of hci0 interface
udevadm info -a -p /sys/class/bluetooth/hci0
If you want properties (ENV style) rather than the attribute-walk
udevadm info -p /sys/class/bluetooth/hci0 --query=property
To find the underlying parent device (USB device path), do
udevadm info -a -p /sys/class/bluetooth/hci0 | less
Setting headphones to on/off and following will show up
udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[114270.712195] remove /devices/virtual/input/input36/event20 (input)
UDEV [114270.723087] remove /devices/virtual/input/input36/event20 (input)
KERNEL[114270.750362] remove /devices/virtual/input/input36 (input)
UDEV [114270.750918] remove /devices/virtual/input/input36 (input)
KERNEL[114271.022271] remove /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3.3/1-3.3:1.0/bluetooth/hci0/hci0:69 (bluetooth)
UDEV [114271.024572] remove /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3.3/1-3.3:1.0/bluetooth/hci0/hci0:69 (bluetooth)
KERNEL[114276.446328] add /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3.3/1-3.3:1.0/bluetooth/hci0/hci0:71 (bluetooth)
UDEV [114276.454486] add /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3.3/1-3.3:1.0/bluetooth/hci0/hci0:71 (bluetooth)
KERNEL[114277.949132] add /devices/virtual/input/input37 (input)
KERNEL[114277.949530] add /devices/virtual/input/input37/event20 (input)
UDEV [114277.951557] add /devices/virtual/input/input37 (input)
UDEV [114277.988819] add /devices/virtual/input/input37/event20 (input)
Simulating udev rule execution for hci0
udevadm test /sys/class/bluetooth/hci0
Identify the PCI controller backing /dev/sda
udevadm info -q property -n /dev/sdb \
| awk -F= '$1=="ID_PATH"{ sub(/^pci-/,"",$2); sub(/-.*/,"",$2); sub(/^0000:/,"",$2); print $2 }' \
| xargs -r -n1 lspci -s
Dump info about our harddrive
udevadm info --query=property --name=/dev/sda
See if a drive is luks protected by udevadm
$ udevadm info --query=property --name=/dev/sdb|grep 'ID_FS_TYPE'
ID_FS_TYPE=crypto_LUKS
If rules fail to reload automatically
udevadm control --reload
To manually force udev to trigger your rules
udevadm trigger
Extract the group names referenced in udev rules and the group names actually present on the system
grep -Fr GROUP /etc/udev/rules.d/ /usr/lib/udev/rules.d/ | sed 's:.*GROUP="\([-a-z_]\{1,\}\)".*:\1:' | sort -u
Dump serial number for disk drive of sdc
udevadm info --query=property --property=ID_SERIAL,ID_SERIAL_SHORT --name=/dev/sdc