Open nicolargo opened 5 years ago
Note that the pyudev
library can help a lot here, though it naturally only helps on Linux systems with udev
which, notably, excludes most SystemV-based systems:
Disk:
>>> import pyudev
>>> context = pyudev.Context()
>>> device = pyudev.Devices.from_name(context, 'block', 'sda')
>>> device
Device('/sys/devices/pci0000:00/0000:00:17.0/ata5/host4/target4:0:0/4:0:0:0/block/sda')
>>> device.get('DEVTYPE')
'disk'
>>> device.get('ID_MODEL')
'Samsung_SSD_870_EVO_1TB'
>>> device.get('ID_SERIAL')
'Samsung_SSD_870_EVO_1TB_SERIAL000000000'
>>> device.get('ID_SERIAL_SHORT')
'SERIAL000000000'
Formatted partition on same disk:
>>> device = pyudev.Devices.from_name(context, 'block', 'sda3')
>>> device
Device('/sys/devices/pci0000:00/0000:00:17.0/ata5/host4/target4:0:0/4:0:0:0/block/sda/sda3')
>>> device.get('DEVTYPE')
'partition'
>>> device.get('PARTN')
'3'
>>> device.get('ID_SERIAL')
'Samsung_SSD_870_EVO_1TB_SERIAL000000000'
>>> device.get('ID_FS_LABEL')
'fedora_hostname'
>>> device.get('ID_FS_TYPE')
'btrfs'
>>> device.get('ID_FS_UUID')
'fakeuuid-aaaa-bbbb-cccc-dddddddddddd'
>>>
Note that partitions share the ID_SERIAL
with the "parent" disk - the differentiation is the DEVTYPE
and PARTN
attributes.
To get a list of potential Device.get() query parameters, run the following from a shell:
# udevadm info --query=all --name=/dev/sda
# udevadm info --query=all --name=/dev/sda3
It would be fine if PsUtil could return the disk id.
The information is available in the /dev/disk/by-id/ folder.
Example on my Ubuntu system:
It will be useful to sort diskio per id in the Glances software (see attached git issue).
Thanks !