For example, I have device /dev/sdb. How do I find out it's udev subsystem?
3 Answers
$ udevadm info -q all -a /dev/sdb
NOTE: the above queries the UDEV database for device information, info
, we're querying for all information, -q all
, and we're walking all the attributes under /sys
pertaining to this device label.
excerpt
--attribute-walk|-a
Print all sysfs properties of the specified device that can be used
in udev rules to match the specified device. It prints all devices
along the chain, up to the root of sysfs that can be used in udev
rules.
Example
Here's my /dev/sda
device.
$ udevadm info -q all -a /dev/sda | grep parent
walks up the chain of parent devices. It prints for every device
and the attributes from one single parent device.
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0':
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0':
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1/host0':
looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata1':
looking at parent device '/devices/pci0000:00/0000:00:1f.2':
looking at parent device '/devices/pci0000:00':
Differences between these 2 commands
@sepero's answer is showing information just pertaining to the UDEV device at the leaf node.
Sepero's answer
$ udevadm info -q all -n /dev/sda > udevadm_info_1.txt
slm's answer
My answer shows the attributes as it walks the entire /sys
chain hierarchy of devices.
$ udevadm info -q all -a /dev/sda > udevadm_info_2.txt
You can see the difference between these two.
$ diff -y udevadm_info_1.txt udevadm_info_2.txt \
> udevadm_info_diff.txt
NOTE: I'm running on Fedora 19, using version 204 of udevadm
:
$ udevadm --version
204

- 369,824
udevadm info
provides this kind of information.
If you specifically want the subsystem:
udevadm info -n /dev/sdb -q property | sed -n 's/SUBSYSTEM=//p'
When you're writing udev rules, the most useful command is
udevadm info -a -n /dev/sdb
This prints out rules that you can use to match the device in udev rules. The first block is about the device itself, and the subsequent blocks are about its ancestors in the device tree. The only caveat is that you cannot mix keys that correspond to different ancestors. For example, given this excerpt
KERNEL=="sdb"
SUBSYSTEM=="block"
…
KERNELS=="5:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{model}=="Yoyodyne Diskinator"
…
KERNELS=="0000:00:1f.2"
SUBSYSTEMS=="pci"
DRIVERS=="ahci"
then you can match this device with SUBSYSTEM=="block", SUBSYSTEMS=="scsi", ATTRS{model}="Yoyodyne Diskinator"
or with SUBSYSTEM=="block", SUBSYSTEMS=="pci", DRIVERS="ahci"
but not with SUBSYSTEM=="block", SUBSYSTEMS=="scsi", ATTRS{model}="Yoyodyne Diskinator", DRIVERS="ahci"
.
Another way to obtain information for use in rules is with
udevadm info -q property -n /dev/sdb --export
This prints device property values of the form KEY=VALUE
which you can use as ENV{KEY}=="VALUE"
in udev rules.
If your device doesn't have a /dev
entry, you can refer to it with a path under /sys
instead, e.g.
udevadm info -a -p /sys/block/sdb
(not a useful example in this case — this is useful for devices whose category isn't common and don't have an entry under /dev
yet).
When you change udev rules, they are read automatically; however, they are only applied to devices that are subsequently plugged into the system. To apply the new rules to an already-connected device, use udevadm trigger
(with options to restrict the application to certain devices).

- 82,805

- 829,060
$ udevadm info -q all -n /dev/sdb

- 50,249

- 1,599
-
The difference b/w this approach and mine is that this shows just the leaf node in
/sys
for/dev/sdb
. The other approach shows the entire tree hierarchy of the leaf node along with the branches. – slm Apr 15 '14 at 14:51
udevadm info -a -n /dev/sdb
? – Gilles 'SO- stop being evil' Apr 15 '14 at 22:35udevadm info -q all
, not fromudevadm info -a
. I think-a
is a shortcut for-q all --attribute-walk
. Or is this different on your version? I don't remember this changing, but then I haven't used Fedora in years (but why would a distribution patch this?). – Gilles 'SO- stop being evil' Apr 16 '14 at 00:26udevadm info -q all -a /dev/sda
is equivalent to what I showed with the nested commands. I'll modify my A to reflect this abbreviated version vs. my monstrosity. – slm Apr 16 '14 at 00:37