I am trying to acquaint myself with udev, under Ubuntu 13.10.

Here is my first simple 95.usbbackup.rules rule:

ACTION=="add", SUBSYSTEMS="usb", RUN+="/usr/local/bin/my_backup.sh"

and here is the script (which has been chmodded +x) my_backup.sh :

touch /tmp/test

Nothing at all happens when I plug in external drives. How can I check (a log, a command, anything) if the rule fired?

Thanks a lot

  • 2
    I think you mean SUBSYSTEMS=="usb". I.e. double == which tests for equality rather than single = which assigns a value to a key. – Lqueryvg Sep 26 '15 at 13:31

I'm pretty sure this should work. Did you reload your udev rules after editing your rules?

udevadm control --reload-rules && udevadm trigger as root.

  • I made a narrower rule : KERNEL=="sdb", which works. Does udev only treats rules that identify some hardware uniquely? – pouzzler Nov 30 '13 at 14:29
  • No, try KERNEL!="sdz*" and you should get everything (except sdz[1-9]) – Redsandro Nov 30 '13 at 23:39
  • 4
    This doesn't really answer the question. How do you know if the rules triggered? – DanielSank Apr 6 '18 at 23:40
  • 1
    You know because the script is run. You can make it write to a logfile. Also udevadm monitor – Redsandro Apr 7 '18 at 14:15

You can give a command as root like this:

udevadm monitor

It will show when a rule has fired.

  • 9
    udevadm monitor just shows the udev events, but not if a corresponding rule was fired. However, you can look for the event which should trigger the rule, but then you do not know if your rule works. – F.Raab Jun 20 '18 at 14:18

I'm running kernel 3.0.35, but the following works for me.

To get the path for the device you can do something like this:

udevadm info --name /dev/sda1 --query all

You will get more information than you need but you're interested in the DEVPATH. Then to see what udev rules are executed you run this:

udevadm test DEVPATH

I don't think this actually executes the rules, the documentation says this 'simulates' the events for the given device. To get more information, check out this man page: https://www.freedesktop.org/software/systemd/man/udevadm.html


I was having the same problem with Raspberry Pi 3 B+. I was trying to invoke a script on inserting a USB storage device. The rules do not get logged in syslog, so it becomes very difficult to understand which rule worked or which rule failed.

So I did the following:

  1. I made my rule file in /etc/udev/rules.d/100-myrule.rules
  2. Then I ran the command sudo /etc/init.d/udev restart

and when I checked, it worked.

A piece of information, that may or may not be useful, is that the filesystems are readonly for udev until the command in step 2 is executed.


With udev / systemd version 241 and similar, as root:

udevadm control --log-priority=debug
journalctl -f

Or to make it permanent, again as root:

vi /etc/udev/udevd.conf
systemctl restart systemd-udevd
journalctl -f

PS: the most frequent answer looks like:

udevadm -d test /devices/where/is/my/device |& less

... but this has a number of issues. The main ones:

  • where/is/my/device ? Tedious, complicated and error-prone.

  • Comparing old answers to recent udev version 241 output, udevadm test seems to show less information that it used to.

  • It's only a simulation!

Every time it warns:

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.

udevadm test is for developing a new rule, it's not for troubleshooting broken, missing or overridden rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.