Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

udevadm

Control and query udev, the service that creates device files and runs rules when hardware appears.

Level
Everyday Linux
Group
Kernel and hardware
Needs root
For changes
Package
systemd-udev

What it does

When the kernel finds a device it sends an event; systemd-udevd applies the rules from /usr/lib/udev/rules.d/ and /etc/udev/rules.d/: create /dev names and links (like /dev/disk/by-uuid/), set owners, load modules, run programs. udevadm shows device properties (info), watches events (monitor), replays events (trigger), waits for them (settle) and reloads rules (control).

How to write it

udevadm [-d] COMMAND [OPTION]...

Main parts

info
Show the properties of a device or the udev database.
monitor
Print kernel and udev events live.
trigger
Ask the kernel to send events again (apply new rules).
settle
Wait until all events are handled.
control
Control the udev daemon (reload rules, log level).
test
Simulate an event for a device and show the rules used.
test-builtin
Test a built-in command.
verify
Check rule files for errors (newer systemd).
wait
Wait until a device is ready.
lock
Lock a block device during a command.
cat
Show rule files (newer systemd).

Options 38

Most used

General

-d, --debug
Debug output.
-h, --help
Show help.
-V, --version
Show the version.

info

-q, --query=TYPE
name, symlink, path, property, all.
-n, --name=FILE
The device by /dev name.
-p, --path=DEVPATH
The device by /sys path.
-a, --attribute-walk
All sysfs attributes up the parent chain (for writing rules).
-r, --root
Print /dev paths in full.
-x, --export
Output as shell variables.
-P, --export-prefix=PREFIX
Prefix for exported names.
--property=NAME, --value
Only these properties / only values.
-e, --export-db
Dump the whole database.
-c, --cleanup-db
Clean the database.
-t, --tree
Tree view (newer systemd).

monitor

-k, --kernel
Only kernel events.
-u, --udev
Only udev events.
-p, --property
Show the event properties.
-s, --subsystem-match=SUBSYSTEM[/DEVTYPE]
Only this subsystem, like block.
-t, --tag-match=TAG
Only events with this tag.

trigger

-c, --action=ACTION
add, change (default), remove …
-n, --dry-run
Do not send events.
-v, --verbose
Show the devices.
-t, --type=devices|subsystems
What to trigger.
-s, --subsystem-match=SUBSYSTEM, -S, --subsystem-nomatch=SUBSYSTEM
Filter by subsystem.
-a, --attr-match=ATTR=VALUE, -A, --attr-nomatch=ATTR=VALUE
Filter by attribute.
-p, --property-match=KEY=VALUE, -g, --tag-match=TAG, -y, --sysname-match=NAME, --name-match=NAME, -b, --parent-match=SYSPATH
More filters.
-w, --settle
Wait until the events are handled.
--uuid
Mark events with a UUID.

settle

-t, --timeout=SECONDS
Maximum wait (default 120).
-E, --exit-if-exists=FILE
Stop waiting when the file exists.

control

-R, --reload
Reload rules and databases.
-l, --log-level=LEVEL
Set the log level of udevd.
-s, --stop-exec-queue, -S, --start-exec-queue
Pause / continue handling events.
-p, --property=KEY=VALUE
Set a global property.
-m, --children-max=N
Maximum parallel workers.
-e, --exit
Tell udevd to exit.
--ping
Check that udevd answers.
-t, --timeout=SECONDS
Timeout for the request.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Properties of a disk

    udevadm info /dev/vdb

    ID_SERIAL, ID_PATH, DEVLINKS (by-id, by-path …).

  2. 2Watch events while plugging in

    udevadm monitor -p

    Kernel events (KERNEL) and udev events (UDEV) with all properties.

  3. 3Only block devices

    udevadm monitor -s block

    Disks and partitions.

  4. 4Attributes for a rule

    udevadm info -a -n /dev/sdc | less

    Use ATTRS{serial}=="…" in your rule.

  5. 5A rule for a fixed name

    echo 'SUBSYSTEM=="block", ENV{ID_SERIAL}=="SanDisk_Ultra_Fit_4C53…", SYMLINK+="backupdisk"' > /etc/udev/rules.d/90-backup.rules

    /dev/backupdisk appears for that stick.

  6. 6Reload and apply rules

    udevadm control --reload
    udevadm trigger -s block

    New rules work without a reboot.

  7. 7Wait for devices in scripts

    partprobe /dev/vdb; udevadm settle

    Partition devices exist after settle.

  8. 8Test which rules apply

    udevadm test $(udevadm info -q path -n /dev/vdb) 2>&1 | tail

    Debug a rule that does not work.

  9. 9Find the stable names of a disk

    udevadm info -q symlink -n /dev/vdb

    by-id and by-path names for fstab or LVM filters.

  10. 10Block rogue USB devices with a rule (security)

    echo 'ACTION=="add", SUBSYSTEMS=="usb", ATTR{authorized}="0"' > /etc/udev/rules.d/99-usb-deny.rules

    New USB devices are not authorized (keyboards too! use USBGuard in production).

Files

/usr/lib/udev/rules.d/
Rules from packages.
/etc/udev/rules.d/
Your rules (win over the same name).
/run/udev/data/
udev database.

Exit codes

0Done.
1Error.