On Thu, 2013-01-03 at 17:09 +0100, Jan Safranek wrote:
With following code snippet, pyanaconda.storage now creates an
extended
partition on a disk, allocating the largest free space on the disk.
Is creation of an empty extended partition one of your requirements?
Handling of extended partitions is not very straightforward, partly
because in anaconda we want to implicitly create them as needed. I
expect there may be several issues related to requesting empty extended
partitions. One thing is that anaconda currently removes any empty
extended partitions as part of doPartitioning, so any subsequent calls
to doPartitioning after the below snippet will remove your new
partition. Feel free to file an RFE for creation of empty extended
partitions and we can work through it there.
David
disk = storage.devicetree.getDeviceByName('sda')
partition =
storage.newPartition(parents=[disk],size=1,grow=True,partType=parted.PARTITION_EXTENDED,
primary=True)
action = pyanaconda.storage.deviceaction.ActionCreateDevice(partition)
storage.devicetree.registerAction(action)
print "before:", partition.isExtended
pyanaconda.storage.partitioning.doPartitioning(storage=storage)
print "after:", partition.isExtended
Without this patch, doPartitioning() would change the partition type from
parted.PARTITION_EXTENDED to parted.PARTITION_NORMAL and the second print
output would be different from the first one.
part_type variable comes from getNextPartitionType(), which either returns
NORMAL, if there is space for another primary partition in partition table
or EXTENDED, if the new partition should be logical. It says nothing about
application's reqest.
Signed-off-by: Jan Safranek <jsafrane(a)redhat.com>
---
pyanaconda/storage/partitioning.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/pyanaconda/storage/partitioning.py b/pyanaconda/storage/partitioning.py
index 87372fa..9a5f351 100644
--- a/pyanaconda/storage/partitioning.py
+++ b/pyanaconda/storage/partitioning.py
@@ -1060,6 +1060,10 @@ def allocatePartitions(storage, disks, partitions, freespace):
raise PartitioningError(_("not enough free space after "
"creating extended partition"))
+ # create extended partition if application requested so
+ if _part.isExtended and part_type == parted.PARTITION_NORMAL:
+ part_type = parted.PARTITION_EXTENDED
+
partition = addPartition(disklabel, free, part_type, _part.req_size)
log.debug("created partition %s of %dMB and added it to %s" %
(partition.getDeviceNodeName(), partition.getSize(),