From 6b2bcd1959cc2de86a559a9815b32364b814f27c Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 11 Apr 2013 15:01:07 +0300 Subject: [PATCH] partitinedfs.py: implement the --part-type option Implement the --part-type option for GPT partitions. In case of MBR partitions - just error out and say that the option is not implemented, but if someone needs it for the MBR case in the future - it may be implemented. Change-Id: I7f45db71df85bd36850d1379a38a84fe73532de6 Signed-off-by: Artem Bityutskiy --- mic/imager/raw.py | 3 ++- mic/utils/partitionedfs.py | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mic/imager/raw.py b/mic/imager/raw.py index 474a76f..19efe0d 100644 --- a/mic/imager/raw.py +++ b/mic/imager/raw.py @@ -193,7 +193,8 @@ class RawImageCreator(BaseImageCreator): p.label, fsopts = p.fsopts, boot = p.active, - align = p.align) + align = p.align, + part_type = p.part_type) self.__instloop.layout_partitions(self._ptable_format) diff --git a/mic/utils/partitionedfs.py b/mic/utils/partitionedfs.py index 03999c5..226e4d9 100644 --- a/mic/utils/partitionedfs.py +++ b/mic/utils/partitionedfs.py @@ -94,7 +94,8 @@ class PartitionedMount(Mount): self.__add_disk(part['disk_name']) def add_partition(self, size, disk_name, mountpoint, fstype = None, - label=None, fsopts = None, boot = False, align = None): + label=None, fsopts = None, boot = False, align = None, + part_type = None): """ Add the next partition. Prtitions have to be added in the first-to-last order. """ @@ -146,6 +147,7 @@ class PartitionedMount(Mount): 'num': None, # Partition number 'boot': boot, # Bootable flag 'align': align, # Partition alignment + 'part_type' : part_type, # Partition type 'partuuid': None } # Partition UUID (GPT-only) self.__add_partition(part) @@ -174,6 +176,13 @@ class PartitionedMount(Mount): raise MountError("No disk %s for partition %s" \ % (p['disk_name'], p['mountpoint'])) + if p['part_type'] and ptable_format != 'gpt': + # The --part-type can also be implemented for MBR partitions, + # in which case it would map to the 1-byte "partition type" + # filed at offset 3 of the partition entry. + raise MountError("setting custom partition type is only " \ + "imlemented for GPT partitions") + # Get the disk where the partition is located d = self.disks[p['disk_name']] d['numpart'] += 1 @@ -339,7 +348,8 @@ class PartitionedMount(Mount): "%d" % p['num'], flag_name, "on"]) # If the partition table format is "gpt", find out PARTUUIDs for all - # the partitions + # the partitions. And if users specified custom parition type UUIDs, + # set them. for disk_name, disk in self.disks.items(): if disk['ptable_format'] != 'gpt': continue @@ -353,11 +363,18 @@ class PartitionedMount(Mount): for n in d['partitions']: p = self.partitions[n] if p['num'] == pnum: - # Found, assign PARTUUID + # Found, fetch PARTUUID (partition's unique ID) p['partuuid'] = entry['part_uuid'] - msger.debug("PARTUUID for partition %d of disk '%s' " \ + msger.debug("PARTUUID for partition %d on disk '%s' " \ "(mount point '%s') is '%s'" % (pnum, \ disk_name, p['mountpoint'], p['partuuid'])) + if p['part_type']: + entry['type_uuid'] = p['part_type'] + msger.debug("Change type of partition %d on disk " \ + "'%s' (mount point '%s') to '%s'" % \ + (pnum, disk_name, p['mountpoint'], + p['part_type'])) + gpt_parser.change_partition(entry) del gpt_parser -- 2.7.4