Ever wondered why a certain rule doesn’t run? Ever got confused (or disgusted) by udev rules format?
Well, with all the udev badness, there are many useful tools in the udev package, which help to understand how udev works. I’m still far from knowing all the tricks, but here are some things that I’ve learned recently:
Note: the udev tools got changed several times during the last 5 years. I’ll cover here the latest version (149), and the older, RHEL/CENTOS5 version.
1. INFO: get all info available to udev about a certain device (or all devices):
# udevadm info -e (RHEL5: udevinfo -e)
Try it.. amazing, eh? You can use each detail to write udev rules to match these devices.
2. DEBUG: see everything that udev does
a. On demand debugging: udev sends messages to syslog. Easiest way to see what udev does, is by increasing the log level. as easy as a pie:
# udevadm control –log-priority=debug (RHEL5: udevcontrol log_priority=debug)
b. boot in debug mode: most of udev actions are running at boot time, so we need a way to tell udev to start in debug mode. This way /var/log/messages would contain all udev actions messages starting with the very first one. Yes, syslog is down when udev starts.. Any idea how it works?
How to do it?
# edit /etc/udev/udev.conf: set udev_log=”debug”
(RHEL5 has a nice trick: add udevdebug to the kernel boot parameters)
3. TRIGGER – causes something like a udev rescan: all add events are re-sent from the kernel, thus triggering all udev rules.
# udevadm trigger (RHEL5: udevtrigger)
4. SETTLE - blocks until udev has finished working on its queue. Due to the asynchronous nature of modern kernels, commands may return before the real expected action got finished. E.g.: a command for loading a kernel module might finish running before the network interface was really created, so if the next command expects a network interface it should wait until it’s created. Ok, to the business:
# udevadm settle (RHEL5: udevsettle)
5. TEST/MONITOR: sound very useful, although I found debugging (mentioned above) as the better method for most scenarios, so I didn’t dig them much.
I hope this article will be helpful. Do you have a cool udev tip or trick? Be nice and post it as a comment!
Tags: FOSS, kernel, Linux/Unix, udev