udevadm is the udev management tool, it expects a command and command specific options, it also controls the runtime behavior of udev, requests kernel events, manages the event queue, and provides simple debugging machanisms.

In this article, I'm going to show you some udevadm useful command examples. Udevadm doesn't have many options, let's go through them one by one.

The examples below tested on both RHEL6 and RHEL7, should also work on CentOS/SL etc..

 

udevadm info options
udevadm trigger [options]
udevadm settle [options]
udevadm control command
udevadm monitor [options]
udevadm test [options] devpath

Info

Info, Property query
# udevadm info --query=property --name /dev/sdd
UDEV_LOG=3
DEVPATH=/devices/pci0000:00/0000:00:06.0/0000:07:00.1/host4/rport-4:0-5/target4:0:0/4:0:0:5/block/sdd
...
ID_TYPE=disk
ID_SERIAL_RAW=360001ff00d606eca050008000082fe45
ID_SERIAL=360001ff00d606eca050008000082fe45
ID_SERIAL_SHORT=60001ff00d606eca050008000082fe45
...
DEVLINKS=/dev/block/8:48 /dev/disk/by-id/scsi-360001ff00d606eca050008000082fe45 /dev/disk/by-path/pci-0000:07:00.1-fc-0x28000001ff0414e2-lun-5 /dev/disk/by-uuid/ec5eb4a9-7189-4dba-939a-776f6b49748d /dev/disk/by-id/wwn-0x60001ff00d606eca050008000082fe45
Info, path query
# udevadm info --query=path --name /dev/sdd
/devices/pci0000:00/0000:00:06.0/0000:07:00.1/host4/rport-4:0-5/target4:0:0/4:0:0:5/block/sdd
symlink query
# udevadm info --query=symlink --name /dev/sdd
block/8:48 disk/by-id/scsi-360001ff00d606eca050008000082fe45 disk/by-path/pci-0000:07:00.1-fc-0x28000001ff0414e2-lun-5 disk/by-uuid/ec5eb4a9-7189-4dba-939a-776f6b49748d disk/by-id/wwn-0x60001ff00d606eca050008000082fe45
Info, All info query
# udevadm info --a --name=/dev/sdd
P: /devices/pci0000:00/0000:00:06.0/0000:07:00.1/host4/rport-4:0-5/target4:0:0/4:0:0:5/block/sdd
N: sdd
W: 8
S: block/8:48
S: disk/by-id/scsi-360001ff00d606eca050008000082fe45
S: disk/by-path/pci-0000:07:00.1-fc-0x28000001ff0414e2-lun-5
S: disk/by-uuid/ec5eb4a9-7189-4dba-939a-776f6b49748d
S: disk/by-id/wwn-0x60001ff00d606eca050008000082fe45
E: UDEV_LOG=3
E: DEVPATH=/devices/pci0000:00/0000:00:06.0/0000:07:00.1/host4/rport-4:0-5/target4:0:0/4:0:0:5/block/sdd
E: MAJOR=8
E: MINOR=48
...
Info, attribute-walk
# udevadm info --attribute-walk --name /dev/sdd

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:06.0/0000:07:00.1/host4/rport-4:0-5/target4:0:0/4:0:0:5/block/sdd':
    KERNEL=="sdd"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{range}=="16"
    ATTR{ext_range}=="256"
    ATTR{removable}=="0"
    ATTR{ro}=="0"
    ATTR{size}=="35163230208"
    ATTR{alignment_offset}=="0"
    ATTR{discard_alignment}=="0"
    ATTR{capability}=="52"
    ATTR{stat}=="     758        0     6080     2798        0        0        0        0        0     2234     2798"
    ATTR{inflight}=="       0        0"
...
--export-db                export the content of the udev database
This option could be useful if you are debuging udev issue

Trigger

Note:, remember to have --dry-run option if you run it on production node.

Trigger, dry-run, scsi_host device
# udevadm trigger --verbose --dry-run --type=devices --subsystem-match=scsi_host
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host5/scsi_host/host5
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.1/host6/scsi_host/host6
/sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0/host0/scsi_host/host0
/sys/devices/pci0000:00/0000:00:1f.2/host1/scsi_host/host1
/sys/devices/pci0000:00/0000:00:1f.2/host2/scsi_host/host2
/sys/devices/pci0000:00/0000:00:1f.5/host3/scsi_host/host3
/sys/devices/pci0000:00/0000:00:1f.5/host4/scsi_host/host4
Trigger, dry-run, scsi_disk device
# udevadm trigger --verbose --dry-run --type=devices --subsystem-match=scsi_disk
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host5/rport-5:0-0/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0
...
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.1/host6/rport-6:0-8/target6:0:5/6:0:5:9/scsi_disk/6:0:5:9
/sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0/host0/target0:1:0/0:1:0:0/scsi_disk/0:1:0:0
Trigger, dry-run, scsi_tape and fc_host devices
# udevadm trigger --verbose --dry-run --type=devices --subsystem-match=scsi_tape
# udevadm trigger --verbose --dry-run --type=devices --subsystem-match=fc_host
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host5/fc_host/host5
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.1/host6/fc_host/host6

Other options are similar

Settle

No example here to share, usually if you see udevadm settle timeout issue, more likely you are having device problem or bug.

After the kernel boots, udevd is used to create device nodes for all detected devices.udevadm settle waits for udevd to process the device creation events for all hardware devices, thus ensuring that any device nodes have been created successfully before proceeding.

Control

# udevadm control --help
Usage: udevadm control COMMAND
  --log-priority=<level>   set the udev log level for the daemon
  --stop-exec-queue        keep udevd from executing events, queue only
  --start-exec-queue       execute events, flush queue
  --reload-rules           reloads the rules files
  --property=<KEY>=<value> set a global property for all events
  --max-childs=<N>         maximum number of childs
  --help                   print this help text

The following options are more useful to me.

--log-priority=value
    Set the internal log level of udevd. Valid values are the numerical syslog priorities or their textual representations: err, info and debug.
--reload-rules
    Signal udevd to reload the rules files. The udev daemon detects changes automatically, this option is usually not needed. Reloading rules does not apply any changes to already existing devices.

monitor

# udevadm monitor --help
Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]
  --property                    print the event properties
  --kernel                      print kernel uevents
  --udev                        print udev events
  --subsystem-match=<subsystem> filter events
  --help

To me, I use it to debug udev configuration for particular device, for example, I start udevadm monitor

Debuging monitoring
# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

From another session, I ran

# echo 1 > /sys/class/scsi_device/6:0:5:11/device/delete
# echo "0 5 11" >  /sys/class/scsi_host/host6/scan
KERNEL[1378104532.953656] remove   /devices/pci0000:00/0000:00:03.0/0000:15:00.1/host6/rport-6:0-8/target6:0:5/6:0:5:11/bsg/6:0:5:11 (bsg)
....
KERNEL[1378104578.007559] add      /devices/pci0000:00/0000:00:03.0/0000:15:00.1/host6/rport-6:0-8/target6:0:5/6:0:5:11/block/sdeo (block)
UDEV  [1378104578.196100] add      /devices/pci0000:00/0000:00:03.0/0000:15:00.1/host6/rport-6:0-8/target6:0:5/6:0:5:11/block/sdeo (block)
KERNEL[1378104578.203955] change   /devices/virtual/block/dm-11 (block)
UDEV  [1378104578.252306] change   /devices/virtual/block/dm-11 (block)

Test

# udevadm test /block/sdd
run_command: calling: test
udevadm_test: version 147
This program is for debugging only, it does not run any program,
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

parse_file: reading '/lib/udev/rules.d/10-console.rules' as rules file
...
udev_rules_apply_to_event: IMPORT 'fstab_import sdd block/8:48 disk/by-id/scsi-360080e50002d26520000067e4f7a3fcc disk/by-path/pci-0000:15:00.0-fc-0x20370080e52d2652-lun-2 disk/by-uuid/d5d8f157-0691-483b-9feb-e86aa99eb138 disk/by-label/\x2fdcs01_lun2 disk/by-id/wwn-0x60080e50002d26520000067e4f7a3fcc mapper/' /lib/udev/rules.d/79-fstab_import.rules:1
...
udev_device_new_from_syspath: device 0x7f80f2df4160 has devpath '/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host5/rport-5:0-0/target5:0:0/5:0:0:2/block/sdd'
udev_device_read_db: device 0x7f80f2df4160 filled with db file data
udev_rules_apply_to_event: PROGRAM '/sbin/multipath -c /dev/sdd' /lib/udev/rules.d/40-multipath.rules:11
util_run_program: '/sbin/multipath -c /dev/sdd' started
util_run_program: '/lib/udev/udisks-part-id' (stderr) 'using device_file=/dev/sdd syspath=/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host5/rport-5:0-0/target5:0:0/5:0:0:2/block/sdd, offset=0 ao=0 and number=0 for /dev/sdd'
udevadm_test: DEVLINKS=/dev/block/8:48 /dev/disk/by-id/scsi-360080e50002d26520000067e4f7a3fcc /dev/disk/by-path/pci-0000:15:00.0-fc-0x20370080e52d2652-lun-2 /dev/disk/by-uuid/d5d8f157-0691-483b-9feb-e86aa99eb138 /dev/disk/by-label/\x2fdcs01_lun2 /dev/disk/by-id/wwn-0x60080e50002d26520000067e4f7a3fcc