From ecca97805300de2ab8baef1c849923fefdd50e3a Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 16 Oct 2013 18:05:54 -0700 Subject: [PATCH] fix(cgpt.py): Fix GPT reserved space calculations. The existing code arbitrarily multiplies START_SECTOR by 512 converting from blocks/sectors to bytes, but blocks was the correct unit to begin with. Also the secondary GPT area is not considered but that was OK because the bogus unit conversion oversized our disks by almost 16MB. Instead of relying on bugs properly reserve 34 sectors at each end of the disk. (Well, we could get away with only 33 at the end since it doesn't have a MBR but meh.) --- build_library/cgpt.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build_library/cgpt.py b/build_library/cgpt.py index 2176cf258e..2d6d54d3f4 100755 --- a/build_library/cgpt.py +++ b/build_library/cgpt.py @@ -12,7 +12,7 @@ import uuid from optparse import OptionParser # First sector we can use. -START_SECTOR = 64 +GPT_RESERVED_SECTORS = 34 class ConfigNotFound(Exception): pass @@ -222,14 +222,16 @@ def WritePartitionTable(options, image_type, layout_filename, disk_filename): config = LoadPartitionConfig(layout_filename) partitions = GetPartitionTable(options, config, image_type) - disk_block_count = START_SECTOR * config['metadata']['block_size'] + disk_block_count = GPT_RESERVED_SECTORS for partition in partitions: disk_block_count += partition['blocks'] - sector = START_SECTOR + disk_block_count += GPT_RESERVED_SECTORS + Cgpt('create', '-c', '-s', disk_block_count, disk_filename) + sector = GPT_RESERVED_SECTORS for partition in partitions: if partition['type'] != 'blank': Cgpt('add', '-i', partition['num'],