Skip to content

Instantly share code, notes, and snippets.

@cyberang3l
Last active January 23, 2021 20:44
Show Gist options
  • Save cyberang3l/a4bc2d6d23d004a45ab6cf4055dd69c7 to your computer and use it in GitHub Desktop.
Save cyberang3l/a4bc2d6d23d004a45ab6cf4055dd69c7 to your computer and use it in GitHub Desktop.
udevadm device info and DBus UDI of devices

The get the freedesktop UDI (Unique Device Identifier) of a device, forget about hal, lshal, hal-find-by-property etc, as HAL is long deprecated!

Use the DBus instead. The easiest way to use DBus without having to type a gazillion of commands is to use the qdbus command (or qdbusviewer for a GUI, but a gui won't make things any easier unless you want to navigate through different options):

To get a list of the available freedesktop (because we grep for it) system services (i.e. services provided by the operating system and also by any system daemons):

$ qdbus --system | grep freedesktop
 org.freedesktop.systemd1
 org.freedesktop.Avahi
 org.freedesktop.NetworkManager
 org.freedesktop.PolicyKit1
 org.freedesktop.DisplayManager
 org.freedesktop.UDisks2
 org.freedesktop.UPower
 org.freedesktop.NetworkManager.dnsmasq
 org.freedesktop.RealtimeKit1
 org.freedesktop.ModemManager1
 org.freedesktop.Accounts
 org.freedesktop.login1
 org.freedesktop.PackageKit
org.freedesktop.DBus

To get a list of UDI's for the org.freedesktop.UPower service:

$ qdbus --system org.freedesktop.UPower 
/
/org
/org/freedesktop
/org/freedesktop/UPower
/org/freedesktop/UPower/devices
/org/freedesktop/UPower/devices/mouse_0003o046Do1024x0004
/org/freedesktop/UPower/devices/keyboard_0003o046Do2011x0005
/org/freedesktop/UPower/devices/DisplayDevice
/org/freedesktop/UPower/devices/line_power_ADP1
/org/freedesktop/UPower/Wakeups

To get a list of the disk UDIs use the command qdbus --system org.freedesktop.UDisks2.

Another way to get this kind of information specifically for the disks is by using the udisksctl utility (check the Drive and Table lines below:

$ udisksctl info -b /dev/sdb1
/org/freedesktop/UDisks2/block_devices/sdb1:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sdb1
    DeviceNumber:               2065
    Drive:                      '/org/freedesktop/UDisks2/drives/Generic_USB__CF_Reader_00000000000006'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 false
    Id:                         by-uuid-9818-F67D
    IdLabel:                    NIKON D300
    IdType:                     vfat
    IdUUID:                     9818-F67D
    IdUsage:                    filesystem
    IdVersion:                  FAT32
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sdb1
    ReadOnly:                   false
    Size:                       16022097920
    Symlinks:                   /dev/disk/by-id/usb-Generic_USB_CF_Reader_00000000000006-0:0-part1
                                /dev/disk/by-label/NIKON\x20D300
                                /dev/disk/by-path/pci-0000:00:1d.0-usb-0:1.2:1.0-scsi-0:0:0:0-part1
                                /dev/disk/by-uuid/9818-F67D
  org.freedesktop.UDisks2.Filesystem:
    MountPoints:        /media/user/NIKON D300
  org.freedesktop.UDisks2.Partition:
    Flags:              128
    IsContained:        false
    IsContainer:        false
    Name:               
    Number:             1
    Offset:             102400
    Size:               16022097920
    Table:              '/org/freedesktop/UDisks2/block_devices/sdb'
    Type:               0x0c
    UUID:

To get the sys path of device (partitions as well):

udevadm info -q path -n /dev/sdb1

To get all the symlinks of a device:

udevadm info -q symlink -n /dev/sdb

To get the name of a device:

udevadm info -q name -n /dev/disk/by-id/usb-Generic_USB_CF_Reader_00000000000006-0:0-part1

To get the properties of device:

udevadm info -q property -n /dev/disk/by-id/usb-Generic_USB_CF_Reader_00000000000006-0:0-part1

To get all of the above information:

udevadm info -q all -n /dev/disk/by-id/usb-Generic_USB_CF_Reader_00000000000006-0:0-part1

To get lots of information about a device and its parents:

udevadm info -a -n /dev/disk/by-id/usb-Generic_USB_CF_Reader_00000000000006-0:0-part1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment