user496894
user496894

Reputation: 51

how to get uuid of a device using udev

I want get the mount node of an usb mass-storage device, like /media/its-uuid in pyudev, class Device has some general attributes, but not uuid or mount node.

how to do it

thanks help

Upvotes: 0

Views: 3070

Answers (2)

jemiah
jemiah

Reputation: 63

This will print the UUID of every USB flash disk currently plugged in along with its device node:

import pyudev

context = pyudev.Context()

for device in context.list_devices(subsystem='block', DEVTYPE='partition'):
    if (device.get('ID_USB_DRIVER') == 'usb-storage'):
        print '{0} {1}'.format(device.device_node, device.get('ID_FS_UUID'))

Upvotes: 0

abbot
abbot

Reputation: 27850

With pyudev, each device object provides a dictionary-like interface for its attributes. You can list them all with device.keys(), e.g. UUID is for block devices is dev['ID_FS_UUID'].

Upvotes: 2

Related Questions