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.)
This commit is contained in:
Michael Marineau 2013-10-16 18:05:54 -07:00
parent 1e17818736
commit ecca978053

View File

@ -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'],