Partition class
- class diskinfo.Partition(name, dev_id)[source]
This class is the implementation of a partition entry. It is created by the
get_partition_list()
method. All partition attributes are collected at class creation time and these attributes can be accessed through get functions of the class later.Note
The class creation and the get functions will not generate disk operations and will not change the power state of the disk.
The class uses the df command to find the mounting point and available space of a file system.
- Parameters:
- Raises:
ValueError – in case of invalid input parameters
FileNotFoundError – if the df command cannot be executed
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 on 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 GTP 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 GTP 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_fs_free_size()[source]
Returns the free size of the file system in 512-byte blocks. The result could be 0 if the partition does not contain 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_fs_free_size()) ... nvme0n1p1 - 971968 nvme0n1p2 - 0 nvme0n1p3 - 214591944 nvme0n1p4 - 0 nvme0n1p5 - 141095712 nvme0n1p6 - 114470872
- Return type:
- get_fs_free_size_in_hrf(units=0)[source]
Returns the free size of the file system in human-readable form. The result could be 0 if the partition does not contain a file system.
- 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 = Disk("nvme0n1") >>> plist = disk.get_partition_list() >>> for item in plist: ... s, u = size_in_hrf(item.get_fs_free_size()*512) ... print(item.get_name(), "-", f"{s:.1f} {u}") ... nvme0n1p1 - 497.6 MB nvme0n1p2 - 0.0 B nvme0n1p3 - 109.9 GB nvme0n1p4 - 0.0 B nvme0n1p5 - 72.2 GB nvme0n1p6 - 58.6 GB
- get_fs_label()[source]
Returns the label of the file system. The result could be empty if the file system 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_fs_label()) ... nvme0n1p1 - SYSTEM nvme0n1p2 - nvme0n1p3 - Windows nvme0n1p4 - Recovery tools nvme0n1p5 - Debian nvme0n1p6 - Arch Linux
- Return type:
- get_fs_mounting_point()[source]
Returns the mounting point of the file system. The result could be empty if the partition does not contain any file system, or it is not mounted.
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_fs_mounting_point()) ... nvme0n1p1 - /boot/efi nvme0n1p2 - nvme0n1p3 - /mnt/win11 nvme0n1p4 - nvme0n1p5 - / nvme0n1p6 - /mnt/arch
- Return type:
- get_fs_type()[source]
Returns the type of the file system. The result could be empty if the partition does not contain 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_fs_type()) ... nvme0n1p1 - vfat nvme0n1p2 - nvme0n1p3 - ntfs nvme0n1p4 - ntfs nvme0n1p5 - ext4 nvme0n1p6 - ext4
- Return type:
- get_fs_usage()[source]
Returns the usage of the file system. The result could be empty if the partition does not contain a file system. Vlaid values are`filesystem` or other for special partitions (e.g. for a swap 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_fs_usage()) ... nvme0n1p1 - filesystem nvme0n1p2 - nvme0n1p3 - filesystem nvme0n1p4 - filesystem nvme0n1p5 - filesystem nvme0n1p6 - filesystem
- Return type:
- get_fs_uuid()[source]
Returns the UUID of the file system. The result could be empty if the partition does not contain 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_fs_uuid()) ... nvme0n1p1 - 6432-935A nvme0n1p2 - nvme0n1p3 - 0CA833E3A833CA4A nvme0n1p4 - 784034274033EB10 nvme0n1p5 - d54d33ea-d892-44d9-ae24-e3c6216d7a32 nvme0n1p6 - a0b1c6e7-2541-4e89-93eb-898f6d544a1e
- Return type:
- get_fs_version()[source]
Returns the version of the file system. The result could be empty if the partition does not contain a file system or does not have a version.
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_fs_version()) ... nvme0n1p1 - FAT32 nvme0n1p2 - nvme0n1p3 - nvme0n1p4 - nvme0n1p5 - 1.0 nvme0n1p6 - 1.0
- 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 GTP 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 gtp 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 GTP partition types listed on wikipedia.
Note
This is a GTP 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 GTP 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: