diff options
Diffstat (limited to 'scripts/lib/wic/utils/partitionedfs.py')
-rw-r--r-- | scripts/lib/wic/utils/partitionedfs.py | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/scripts/lib/wic/utils/partitionedfs.py b/scripts/lib/wic/utils/partitionedfs.py index fb95cc790e..162f8e1b9c 100644 --- a/scripts/lib/wic/utils/partitionedfs.py +++ b/scripts/lib/wic/utils/partitionedfs.py @@ -29,6 +29,9 @@ from wic.utils.oe.misc import * # Overhead of the MBR partitioning scheme (just one sector) MBR_OVERHEAD = 1 +# Overhead of the GPT partitioning scheme +GPT_OVERHEAD = 34 + # Size of a sector in bytes SECTOR_SIZE = 512 @@ -61,6 +64,7 @@ class Image: self.disks[disk_name] = \ { 'disk': None, # Disk object 'numpart': 0, # Number of allocate partitions + 'realpart': 0, # Number of partitions in the partition table 'partitions': [], # Indexes to self.partitions 'offset': 0, # Offset of next partition (in sectors) # Minimum required disk size to fit all partitions (in bytes) @@ -85,15 +89,15 @@ class Image: self.__add_disk(part['disk_name']) def add_partition(self, size, disk_name, mountpoint, source_file = None, fstype = None, - label=None, fsopts = None, boot = False, align = None, + label=None, fsopts = None, boot = False, align = None, no_table=False, part_type = None): """ Add the next partition. Prtitions have to be added in the first-to-last order. """ ks_pnum = len(self.partitions) - # Converting MB to sectors for parted - size = size * 1024 * 1024 / self.sector_size + # Converting kB to sectors for parted + size = size * 1024 / self.sector_size # We still need partition for "/" or non-subvolume if mountpoint == "/" or not fsopts: @@ -109,6 +113,7 @@ class Image: 'num': None, # Partition number 'boot': boot, # Bootable flag 'align': align, # Partition alignment + 'no_table' : no_table, # Partition does not appear in partition table 'part_type' : part_type } # Partition type self.__add_partition(part) @@ -120,7 +125,7 @@ class Image: msger.debug("Assigning %s partitions to disks" % ptable_format) - if ptable_format not in ('msdos'): + if ptable_format not in ('msdos', 'gpt'): raise ImageError("Unknown partition table format '%s', supported " \ "formats are: 'msdos'" % ptable_format) @@ -147,15 +152,26 @@ class Image: # Get the disk where the partition is located d = self.disks[p['disk_name']] d['numpart'] += 1 + if not p['no_table']: + d['realpart'] += 1 d['ptable_format'] = ptable_format if d['numpart'] == 1: if ptable_format == "msdos": overhead = MBR_OVERHEAD + elif ptable_format == "gpt": + overhead = GPT_OVERHEAD # Skip one sector required for the partitioning scheme overhead d['offset'] += overhead + if d['realpart'] > 3: + # Reserve a sector for EBR for every logical partition + # before alignment is performed. + if ptable_format == "msdos": + d['offset'] += 1 + + if p['align']: # If not first partition and we do have alignment set we need # to align the partition. @@ -182,20 +198,15 @@ class Image: d['offset'] += p['size'] p['type'] = 'primary' - p['num'] = d['numpart'] + if not p['no_table']: + p['num'] = d['realpart'] + else: + p['num'] = 0 if d['ptable_format'] == "msdos": - if d['numpart'] > 2: - # Every logical partition requires an additional sector for - # the EBR, so steal the last sector from the end of each - # partition starting from the 3rd one for the EBR. This - # will make sure the logical partitions are aligned - # correctly. - p['size'] -= 1 - - if d['numpart'] > 3: + if d['realpart'] > 3: p['type'] = 'logical' - p['num'] = d['numpart'] + 1 + p['num'] = d['realpart'] + 1 d['partitions'].append(n) msger.debug("Assigned %s to %s%d, sectors range %d-%d size %d " @@ -208,6 +219,8 @@ class Image: # minumim disk sizes. for disk_name, d in self.disks.items(): d['min_size'] = d['offset'] + if d['ptable_format'] == "gpt": + d['min_size'] += GPT_OVERHEAD d['min_size'] *= self.sector_size @@ -257,15 +270,25 @@ class Image: msger.debug("Creating partitions") for p in self.partitions: + if p['num'] == 0: + continue + d = self.disks[p['disk_name']] if d['ptable_format'] == "msdos" and p['num'] == 5: - # The last sector of the 3rd partition was reserved for the EBR - # of the first _logical_ partition. This is why the extended - # partition should start one sector before the first logical - # partition. + # Create an extended partition (note: extended + # partition is described in MBR and contains all + # logical partitions). The logical partitions save a + # sector for an EBR just before the start of a + # partition. The extended partition must start one + # sector before the start of the first logical + # partition. This way the first EBR is inside of the + # extended partition. Since the extended partitions + # starts a sector before the first logical partition, + # add a sector at the back, so that there is enough + # room for all logical partitions. self.__create_partition(d['disk'].device, "extended", None, p['start'] - 1, - d['offset'] - p['start']) + d['offset'] - p['start'] + 1) if p['fstype'] == "swap": parted_fs_type = "linux-swap" @@ -338,14 +361,6 @@ class Image: for p in self.partitions: d = self.disks[p['disk_name']] - if d['ptable_format'] == "msdos" and p['num'] == 5: - # The last sector of the 3rd partition was reserved for the EBR - # of the first _logical_ partition. This is why the extended - # partition should start one sector before the first logical - # partition. - self.__write_partition(p['num'], p['source_file'], - p['start'] - 1, - d['offset'] - p['start']) self.__write_partition(p['num'], p['source_file'], p['start'], p['size']) |