mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-11 06:56:58 +02:00
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:
parent
1e17818736
commit
ecca978053
@ -12,7 +12,7 @@ import uuid
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
# First sector we can use.
|
# First sector we can use.
|
||||||
START_SECTOR = 64
|
GPT_RESERVED_SECTORS = 34
|
||||||
|
|
||||||
class ConfigNotFound(Exception):
|
class ConfigNotFound(Exception):
|
||||||
pass
|
pass
|
||||||
@ -222,14 +222,16 @@ def WritePartitionTable(options, image_type, layout_filename, disk_filename):
|
|||||||
|
|
||||||
config = LoadPartitionConfig(layout_filename)
|
config = LoadPartitionConfig(layout_filename)
|
||||||
partitions = GetPartitionTable(options, config, image_type)
|
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:
|
for partition in partitions:
|
||||||
disk_block_count += partition['blocks']
|
disk_block_count += partition['blocks']
|
||||||
|
|
||||||
sector = START_SECTOR
|
disk_block_count += GPT_RESERVED_SECTORS
|
||||||
|
|
||||||
Cgpt('create', '-c', '-s', disk_block_count, disk_filename)
|
Cgpt('create', '-c', '-s', disk_block_count, disk_filename)
|
||||||
|
|
||||||
|
sector = GPT_RESERVED_SECTORS
|
||||||
for partition in partitions:
|
for partition in partitions:
|
||||||
if partition['type'] != 'blank':
|
if partition['type'] != 'blank':
|
||||||
Cgpt('add', '-i', partition['num'],
|
Cgpt('add', '-i', partition['num'],
|
||||||
|
Loading…
Reference in New Issue
Block a user