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():