Disks or any other block devices with partition tables have their LMI_StorageExtent or its subclass associated to LMI_DiskPartitionConfigurationCapabilities using LMI_InstalledPartitionTable.
A GPT partition present on a block device are represented as LMI_GenericDiskPartition.
A MS-DOS partition present on a block device are represented as LMI_DiskPartition.
Both MS-DOS and GPT partitions are associated to the parent device using LMI_PartitionBasedOn. This BasedOn association contains also start and end sectors of the partitions. Note that logical partitions are associated with the extended partition where they are located, see the diagram below.
Following instance diagram shows /dev/sda disk with MS-DOS partition table and:
Especially note that the extended partition /dev/sda4 contains an extended partition table and all logical partitions are based on this extended partition. This is for compatibility with SMI-S and also it better illustrates physical composition of the partitions on the disk.
However, to create a partition on the device, applications can use both /dev/sda or /dev/sda4 as value of Extent parameter in LMI_CreateOrModifyPartition, call.
The partitioning support is basic and has several limitations. Currently it is not possible to explicitly set partition position. OpenLMI chooses the best available free space for requested partitions. Typically, on empty disks, the partitions are created one after another.
Currently it is not possible to explicitly create extended or logical partitions, these are created automatically when there are too much primary partitions:
Currently GPT and MS-DOS partition tables are supported. More types can be added later. Enumerate instances of LMI_DiskPartitionConfigurationCapabilities class to get list of all of them, together with their basic properties like partition table size and maximum number of partitions:
part_styles = root.LMI_DiskPartitionConfigurationCapabilities.instances()
for style in part_styles:
print style.Caption
print "Partition table size:", style.PartitionTableSize, "block(s)"
Use SetPartitionStyle method.
Sample code to create GPT partition table on /dev/sda:
# Find the disk
sda = root.LMI_StorageExtent.first_instance(
Key="DeviceID",
Value="/dev/sda")
# Find the partition table style we want to create there
gpt_caps = root.LMI_DiskPartitionConfigurationCapabilities.first_instance(
Key="InstanceID",
Value="LMI:LMI_DiskPartitionConfigurationCapabilities:GPT")
# Create the partition table
partitioning_service.SetPartitionStyle(
Extent=sda,
PartitionStyle = gpt_caps)
MS-DOS partition tables are created with the same code, just using different LMI_DiskPartitionConfigurationCapabilities instance.
Use LMI_CreateOrModifyPartition method.
Following code creates several partitions on /dev/sda. The code is the same for GPT and MS-DOS partitions:
# Define helper function
def print_partition(partition_name):
partition = partition_name.to_instance()
print("Created partition", partition.DeviceID,
"with", partition.NumberOfBlocks * partition.BlockSize, "bytes.")
# Find the disk
sda = root.LMI_StorageExtent.first_instance(
Key="DeviceID",
Value="/dev/sda")
# create 4 partitions with 100 MB each
for i in range(4):
(ret, outparams, err) = partitioning_service.LMI_CreateOrModifyPartition(
Extent=sda,
Size = 100 * MEGABYTE)
print_partition(outparams['partition'])
# Create partition with the whole remaining space - just omit 'Size' parameter
(ret, outparams, err) = partitioning_service.LMI_CreateOrModifyPartition(
Extent=sda)
print_partition(outparams['partition'])
On an empty disk with GPT partition table this code creates:
On an empty disk with MS-DOS partition table, the code creates:
The resulting partitions can be seen in the diagram above.
Enumerate LMI_PartitionBasedOn associations of the disk.
Following code lists all partitions on /dev/sda, together with their location:
# Find the disk
sda = root.LMI_StorageExtent.first_instance(
Key="DeviceID",
Value="/dev/sda")
based_ons = sda.references(ResultClass="LMI_PartitionBasedOn")
for based_on in based_ons:
print "Found partition", based_on.Dependent['DeviceID'], \
"at sectors", based_on.StartingAddress, based_on.EndingAddress
# TODO: check extended partition
Using side-effect of FindPartitionLocation, we can find size of the largest partition that can be created on /dev/sda:
# Find the disk
sda = root.LMI_StorageExtent.first_instance(
Key="DeviceID",
Value="/dev/sda")
# Find LMI_DiskPartitionConfigurationCapabilities associated to the disk
sda_partition_capabilities = sda.associators(
AssocClass='LMI_InstalledPartitionTable') [0]
# Call its FindPartitionLocation without 'Size' parameter
# - the largest available space is returned.
(ret, outparams, err) = sda_partition_capabilities.FindPartitionLocation(
Extent = sda)
print "Largest space for a partition:", outparams['size']
Call LMI_DeletePartition:
sda1 = root.CIM_StorageExtent.first_instance(
Key="DeviceID",
Value="/dev/sda1")
(ret, outparams, err) = partitioning_service.LMI_DeletePartition(
Partition = sda1.path)
In future, we might implement: