Partition class
- class diskinfo.Partition(_device)[source]
This class implements a partition entry containing all the relevant information. All partition attributes are collected at class creation time and these attributes can be accessed through get functions of the class.
Note
The class creation and the get functions will not generate disk operations and will not change the power state of the hard disk.
A list of partition classes are created with the creation of
Diskclass and later can be accessed withget_partition_list()method.
- Parameters:
_device (pyudev.Device) – pyudev.Device class
Example
This example shows the basic use of the class:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name()) ... nvme0n1p1 nvme0n1p2 nvme0n1p3 nvme0n1p4 nvme0n1p5 nvme0n1p6
- get_byid_path()[source]
Returns the by-id persistent path of the partition. The result could be one or more path elements.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_byid_path()) ... nvme0n1p1 - ["/dev/disk/by-id/nvme-WDS100T1X0E-00AFY0_2140GF374501-part1", "/dev/disk/by-id/nvme-eui.e8238fa6bf540001001b555a49bfc681-part1"] nvme0n1p2 - ["/dev/disk/by-id/nvme-WDS100T1X0E-00AFY0_2140GF374501-part2", "/dev/disk/by-id/nvme-eui.e8238fa6bf540001001b555a49bfc681-part2"] nvme0n1p3 - ["/dev/disk/by-id/nvme-eui.e8238fa6bf540001001b555a49bfc681-part3", "/dev/disk/by-id/nvme-WDS100T1X0E-00AFY0_2140GF374501-part3"] nvme0n1p4 - ["/dev/disk/by-id/nvme-WDS100T1X0E-00AFY0_2140GF374501-part4", "/dev/disk/by-id/nvme-eui.e8238fa6bf540001001b555a49bfc681-part4"] nvme0n1p5 - ["/dev/disk/by-id/nvme-WDS100T1X0E-00AFY0_2140GF374501-part5", "/dev/disk/by-id/nvme-eui.e8238fa6bf540001001b555a49bfc681-part5"] nvme0n1p6 - ["/dev/disk/by-id/nvme-WDS100T1X0E-00AFY0_2140GF374501-part6", "/dev/disk/by-id/nvme-eui.e8238fa6bf540001001b555a49bfc681-part6"]
- get_bylabel_path()[source]
Returns the by-label persistent path of the partition (see sample value in the example). The result could be empty if the filesystem does not have a label.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_bylabel_path()) ... nvme0n1p1 - /dev/disk/by-label/SYSTEM nvme0n1p2 - nvme0n1p3 - /dev/disk/by-label/Windows nvme0n1p4 - /dev/disk/by-label/Recovery tools nvme0n1p5 - /dev/disk/by-label/Debian nvme0n1p6 - /dev/disk/by-label/Arch Linux
- Return type:
- get_bypartlabel_path()[source]
Returns the by-partlabel persistent path of the partition (see sample value in the example). The result could be empty if the partition does not have a label.
Note
This is a GPT partition-specific value.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_bypartlabel_path()) ... nvme0n1p1 - /dev/disk/by-partlabel/EFI system partition nvme0n1p2 - /dev/disk/by-partlabel/Microsoft reserved partition nvme0n1p3 - /dev/disk/by-partlabel/Basic data partition nvme0n1p4 - /dev/disk/by-partlabel/Basic data partition nvme0n1p5 - nvme0n1p6 -
- Return type:
- get_bypartuuid_path()[source]
Returns the by-partuuid persistent path of the partition (see sample values in the example).
Note
This is a GPT partition-specific value.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_bypartuuid_path()) ... nvme0n1p1 - /dev/disk/by-partuuid/acb8374d-fb60-4cb0-8ac4-273417c6f847 nvme0n1p2 - /dev/disk/by-partuuid/59417232-6e42-4c03-b258-2d20ddb0486a nvme0n1p3 - /dev/disk/by-partuuid/ec51c644-3ad7-44a5-9750-fc577a3d1ccf nvme0n1p4 - /dev/disk/by-partuuid/9192cde2-b90d-4fd1-99ed-a3584f66c87c nvme0n1p5 - /dev/disk/by-partuuid/6fd87857-265c-489c-8401-a47944c940f2 nvme0n1p6 - /dev/disk/by-partuuid/d5e53353-1943-4827-9b46-63459432f51c
- Return type:
- get_bypath_path()[source]
Returns the by-path persistent path of the partition (see sample value in the example).
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_bypath_path()) ... nvme0n1p1 - /dev/disk/by-path/pci-0000:02:00.0-nvme-1-part1 nvme0n1p2 - /dev/disk/by-path/pci-0000:02:00.0-nvme-1-part2 nvme0n1p3 - /dev/disk/by-path/pci-0000:02:00.0-nvme-1-part3 nvme0n1p4 - /dev/disk/by-path/pci-0000:02:00.0-nvme-1-part4 nvme0n1p5 - /dev/disk/by-path/pci-0000:02:00.0-nvme-1-part5 nvme0n1p6 - /dev/disk/by-path/pci-0000:02:00.0-nvme-1-part6
- Return type:
- get_byuuid_path()[source]
Returns the by-uuid persistent path of the partition (see sample value in the example). The result could be empty if the partition does not have a file system.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_byuuid_path()) ... nvme0n1p1 - /dev/disk/by-uuid/6432-935A nvme0n1p2 - nvme0n1p3 - /dev/disk/by-uuid/0CA833E3A833CA4A nvme0n1p4 - /dev/disk/by-uuid/784034274033EB10 nvme0n1p5 - /dev/disk/by-uuid/d54d33ea-d892-44d9-ae24-e3c6216d7a32 nvme0n1p6 - /dev/disk/by-uuid/a0b1c6e7-2541-4e89-93eb-898f6d544a1e
- Return type:
- get_filesystem()[source]
Returns the
FileSystemobject associated with this partition.- Returns:
filesystem information for this partition
- Return type:
- get_name()[source]
Returns the name of the partition (e.g. sda1 or nvme0n1p1).
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name()) ... nvme0n1p1 nvme0n1p2 nvme0n1p3 nvme0n1p4 nvme0n1p5 nvme0n1p6
- Return type:
- get_part_device_id()[source]
Returns the device id of the partition in major:minor form.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_device_id()) ... nvme0n1p1 - 259:1 nvme0n1p2 - 259:2 nvme0n1p3 - 259:3 nvme0n1p4 - 259:4 nvme0n1p5 - 259:5 nvme0n1p6 - 259:6
- Return type:
- get_part_label()[source]
Returns the label of the partition. The result could be empty if the partition does not have a label.
Note
This is a GPT partition-specific value.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_label()) ... nvme0n1p1 - EFI system partition nvme0n1p2 - Microsoft reserved partition nvme0n1p3 - Basic data partition nvme0n1p4 - Basic data partition nvme0n1p5 - nvme0n1p6 -
- Return type:
- get_part_number()[source]
Returns the number of the partition.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_number()) ... nvme0n1p1 - 1 nvme0n1p2 - 2 nvme0n1p3 - 3 nvme0n1p4 - 4 nvme0n1p5 - 5 nvme0n1p6 - 6
- Return type:
- get_part_offset()[source]
Returns the starting offset of the partition in 512-byte blocks.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_offset()) ... nvme0n1p1 - 2048 nvme0n1p2 - 1050624 nvme0n1p3 - 1312768 nvme0n1p4 - 838125568 nvme0n1p5 - 840173568 nvme0n1p6 - 1035485184
- Return type:
- get_part_scheme()[source]
Returns the scheme of the partition. The result could be gpt or mbr.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_scheme()) ... nvme0n1p1 - gpt nvme0n1p2 - gpt nvme0n1p3 - gpt nvme0n1p4 - gpt nvme0n1p5 - gpt nvme0n1p6 - gpt
- Return type:
- get_part_size()[source]
Returns the size of the partition in 512-byte blocks.
Example
An example about use of the function:
>>> from diskinfo import * >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_size()) ... nvme0n1p1 - 1048576 nvme0n1p2 - 262144 nvme0n1p3 - 836812800 nvme0n1p4 - 2048000 nvme0n1p5 - 195311616 nvme0n1p6 - 209715200
- Return type:
- get_part_size_in_hrf(units=0)[source]
Returns the size of the partition in human-readable form.
- Parameters:
units (int) –
unit system will be used for the calculation and in the result:
0 metric units (default)
1 IEC units
2 legacy units
Read more about units here.
- Returns:
size in human-readable form, proper unit
- Return type:
Example
An example about use of the function:
>>> from diskinfo import * >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... s, u = item.get_part_size_in_hrf() ... print(item.get_name(), "-", "{s:.1f} {u}") ... nvme0n1p1 - 536.9 MB nvme0n1p2 - 134.2 MB nvme0n1p3 - 428.4 GB nvme0n1p4 - 1.0 GB nvme0n1p5 - 100.0 GB nvme0n1p6 - 107.4 GB
- get_part_type()[source]
Returns the UUID of the partition type. See available GPT partition types listed on wikipedia.
Note
This is a GPT partition-specific value.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_type()) ... nvme0n1p1 - c12a7328-f81f-11d2-ba4b-00a0c93ec93b nvme0n1p2 - e3c9e316-0b5c-4db8-817d-f92df00215ae nvme0n1p3 - ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 nvme0n1p4 - de94bba4-06d1-4d40-a16a-bfd50179d6ac nvme0n1p5 - 0fc63daf-8483-4772-8e79-3d69d8477de4 nvme0n1p6 - 0fc63daf-8483-4772-8e79-3d69d8477de4
- Return type:
- get_part_uuid()[source]
Returns the UUID of the partition.
Note
This is a GPT partition-specific value.
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_name(), "-", item.get_part_uuid()) ... nvme0n1p1 - acb8374d-fb60-4cb0-8ac4-273417c6f847 nvme0n1p2 - 59417232-6e42-4c03-b258-2d20ddb0486a nvme0n1p3 - ec51c644-3ad7-44a5-9750-fc577a3d1ccf nvme0n1p4 - 9192cde2-b90d-4fd1-99ed-a3584f66c87c nvme0n1p5 - 6fd87857-265c-489c-8401-a47944c940f2 nvme0n1p6 - d5e53353-1943-4827-9b46-63459432f51c
- Return type:
- get_path()[source]
Returns the path of the partition (e.g. /dev/sda1 or /dev/nvme0n1p1).
Note
This is not a persistent path!
Example
An example about use of the function:
>>> from diskinfo import Disk >>> disk = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... print(item.get_path()) ... /dev/nvme0n1p1 /dev/nvme0n1p2 /dev/nvme0n1p3 /dev/nvme0n1p4 /dev/nvme0n1p5 /dev/nvme0n1p6
- Return type: