From fd8618336d2fab3110f0f9da985f998b80be96dd Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Sat, 30 Aug 2014 15:57:23 -0700 Subject: [PATCH] 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. --- build_library/disk_util | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build_library/disk_util b/build_library/disk_util index b59710e43d..6f51e3989e 100755 --- a/build_library/disk_util +++ b/build_library/disk_util @@ -162,6 +162,7 @@ def LoadPartitionConfig(options): # metadata. Kinda odd but the best place I've got with this data structure. if layout_name == options.disk_layout: 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 @@ -267,13 +268,18 @@ def WritePartitionTable(options, config=None, partitions=None): if not (config and partitions): config, partitions = LoadPartitionConfig(options) - # If we are not creating a fresh image all partitions must be compatible. - if not options.create: + if 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) if not all(p['image_compat'] for p in partitions.itervalues()): 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 for partition in partitions.itervalues():