As per struct usb_device
:
urbnum
number of URBs submitted for the whole device
where URB
stands for USB Request Block
. An URB
consists of all relevant information to execute any USB transaction and deliver the data and status back.
See also:
Kernel Documentation
USB Urbs
A storage device is in the block
subsystem, so you'll want SUBSYSTEM=="block"
in your rule, like this:
ACTION=="add", KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", \
RUN+="/path/to/script"
If you're using systemd
, you could run a systemd
unit each time a USB storage device is added. Create the unit file, e.g. /etc/systemd/system/my-usb-rule.service
:
[Service]
Type=oneshot
ExecStart=/path/to/script
and the rule, e.g. /etc/udev/rules.d/85-my-usb-rule.rules
:
ACTION=="add", KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", \
ENV{SYSTEMD_WANTS}="my-usb-rule.service"
Now udev
will trigger my-usb-rule.service
(which in turn will execute your script) on any usb storage device add event.
Don't forget to reload the configuration after you edit the rules/units:
udevadm control --reload
systemctl daemon-reload
Best Answer
Unfortunately, this information is missing on manpages and even knowing how to read them(see below) you will find trouble on trying to find that info.
However, the beauty of the opensource relies on having the power to read the sources. If you take a look at the
udev-builtin.c
source file insidesystemd
/udev
repository and have basic C language knowledge, you will find the following snippet of code: A structure that maps all existing builtin types.This
struct
holds all built-in types, and they map source files depending on what type it is. Example:udev-builtin-kmod.c
- A Kernel Module loader.udev-builtin-keyboard.c
- A keyboard handler.udev-builtin-usb_id.c
- A USB handler that will set the usb type and initialize the device.Related: