Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, I have device /dev/sdb. How do I find out it's udev subsystem?

share|improve this question
$ 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.


       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 


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
share|improve this answer
Why this complex command rather than udevadm info -a -n /dev/sdb? – Gilles Apr 15 '14 at 22:35
@Gilles - This one dumps all the ATTRS for all the parent nodes. – slm Apr 15 '14 at 23:08
So does mine — the output is identical. – Gilles Apr 16 '14 at 0:14
Gilles - You on Debian? What version of udevadm? When I run the above 2 commands I get these 2 files. single udevadm output vs. nested udevadm output. In looking at the output I think the single command is just combining all the output of all the parents while my version shows which parents the ATTRS are deriving from. – slm Apr 16 '14 at 0:21
pastebin.com/NHg9pydA is the output from udevadm info -q all, not from udevadm 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 Apr 16 '14 at 0:26
$ udevadm info -q all -n /dev/sdb
share|improve this answer
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 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

ATTRS{model}=="Yoyodyne Diskinator"

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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