disk_util: do not zero MBR and GPT when resizing disk

Calling cgpt create when resizing zeros the MBR boot code. This worked
with the syslinux setup because the boot code was re-written. When not
using syslinux it is easier to just preserve the existing MBR instead.
This commit is contained in:
Michael Marineau 2014-08-30 15:57:23 -07:00
parent cb97931478
commit fd8618336d

View File

@ -162,6 +162,7 @@ def LoadPartitionConfig(options):
# metadata. Kinda odd but the best place I've got with this data structure. # metadata. Kinda odd but the best place I've got with this data structure.
if layout_name == options.disk_layout: if layout_name == options.disk_layout:
metadata['blocks'] = disk_block_count metadata['blocks'] = disk_block_count
metadata['bytes'] = disk_block_count * metadata['block_size']
# Verify 'base' before other layouts because it is inherited by the others # Verify 'base' before other layouts because it is inherited by the others
@ -267,13 +268,18 @@ def WritePartitionTable(options, config=None, partitions=None):
if not (config and partitions): if not (config and partitions):
config, partitions = LoadPartitionConfig(options) config, partitions = LoadPartitionConfig(options)
# If we are not creating a fresh image all partitions must be compatible. if options.create:
if not options.create: Cgpt('create', '-c', '-s', config['metadata']['blocks'], options.disk_image)
else:
# If we are not creating a fresh image all partitions must be compatible.
GetPartitionTableFromImage(options, config, partitions) GetPartitionTableFromImage(options, config, partitions)
if not all(p['image_compat'] for p in partitions.itervalues()): if not all(p['image_compat'] for p in partitions.itervalues()):
raise InvalidLayout("New disk layout is incompatible existing image") raise InvalidLayout("New disk layout is incompatible existing image")
Cgpt('create', '-c', '-s', config['metadata']['blocks'], options.disk_image) # Extend the disk image size as needed
with open(options.disk_image, 'r+') as image_fd:
image_fd.truncate(config['metadata']['bytes'])
Cgpt('repair', options.disk_image)
syslinux = None syslinux = None
for partition in partitions.itervalues(): for partition in partitions.itervalues():