mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 13:36:58 +02:00
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:
parent
cb97931478
commit
fd8618336d
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user