image: use IMG_FILE_BOOT_DEFAULT_SIZE to calculate shrunk boot partition size
This commit is contained in:
parent
dd4a4212a3
commit
095ecb672f
2 changed files with 18 additions and 5 deletions
16
image/cli.py
16
image/cli.py
|
@ -114,6 +114,16 @@ def cmd_build(
|
||||||
profile: Profile = config.get_profile(profile_name)
|
profile: Profile = config.get_profile(profile_name)
|
||||||
flavour = get_profile_flavour(profile_name)
|
flavour = get_profile_flavour(profile_name)
|
||||||
rootfs_size_mb = flavour.parse_flavourinfo().rootfs_size * 1000 + int(profile.size_extra_mb)
|
rootfs_size_mb = flavour.parse_flavourinfo().rootfs_size * 1000 + int(profile.size_extra_mb)
|
||||||
|
bootfs_size_str = IMG_FILE_BOOT_DEFAULT_SIZE
|
||||||
|
bootfs_size_mb = -1
|
||||||
|
if bootfs_size_str.endswith('M'):
|
||||||
|
bootfs_size_mb = int(bootfs_size_str.rstrip('M'))
|
||||||
|
elif bootfs_size_str.endswith('G'):
|
||||||
|
bootfs_size_mb = int(bootfs_size_str.rstrip('G')) * 1024
|
||||||
|
elif not bootfs_size_str.isdecimal():
|
||||||
|
raise Exception(f"Couldn't part bootfs target size as megabytes: {bootfs_size_str}")
|
||||||
|
else:
|
||||||
|
bootfs_size_mb = int(bootfs_size_str)
|
||||||
|
|
||||||
if encryption is None:
|
if encryption is None:
|
||||||
encryption = profile.encryption
|
encryption = profile.encryption
|
||||||
|
@ -142,11 +152,11 @@ def cmd_build(
|
||||||
makedir(os.path.dirname(image_path))
|
makedir(os.path.dirname(image_path))
|
||||||
|
|
||||||
logging.info(f'Creating new file at {image_path}')
|
logging.info(f'Creating new file at {image_path}')
|
||||||
create_img_file(image_path, f"{rootfs_size_mb}M")
|
create_img_file(image_path, f"{rootfs_size_mb + bootfs_size_mb}M")
|
||||||
|
|
||||||
loop_device = losetup_rootfs_image(image_path, sector_size or device.get_image_sectorsize_default())
|
loop_device = losetup_rootfs_image(image_path, sector_size or device.get_image_sectorsize_default())
|
||||||
|
|
||||||
partition_device(loop_device)
|
partition_device(loop_device, boot_partition_size=bootfs_size_str)
|
||||||
partprobe(loop_device)
|
partprobe(loop_device)
|
||||||
|
|
||||||
boot_dev: str
|
boot_dev: str
|
||||||
|
@ -159,7 +169,7 @@ def cmd_build(
|
||||||
root_dev = loop_root
|
root_dev = loop_root
|
||||||
else:
|
else:
|
||||||
logging.info('Creating per-partition image files')
|
logging.info('Creating per-partition image files')
|
||||||
boot_dev = create_img_file(get_image_path(device, flavour, 'boot'), IMG_FILE_BOOT_DEFAULT_SIZE)
|
boot_dev = create_img_file(get_image_path(device, flavour, 'boot'), f'{bootfs_size_mb}M')
|
||||||
root_dev = create_img_file(get_image_path(device, flavour, 'root'), f'{rootfs_size_mb - 200}M')
|
root_dev = create_img_file(get_image_path(device, flavour, 'root'), f'{rootfs_size_mb - 200}M')
|
||||||
|
|
||||||
root_dev_raw = root_dev
|
root_dev_raw = root_dev
|
||||||
|
|
|
@ -356,8 +356,11 @@ def create_img_file(image_path: str, size_str: str):
|
||||||
return image_path
|
return image_path
|
||||||
|
|
||||||
|
|
||||||
def partition_device(device: str):
|
def partition_device(device: str, boot_partition_size: Optional[str] = None):
|
||||||
boot_partition_size = '100MiB'
|
if boot_partition_size is None:
|
||||||
|
boot_partition_size = IMG_FILE_BOOT_DEFAULT_SIZE
|
||||||
|
if boot_partition_size and boot_partition_size[-1] in ['M', 'G', 'K']:
|
||||||
|
boot_partition_size = f'{boot_partition_size}iB'
|
||||||
create_partition_table = ['mklabel', 'msdos']
|
create_partition_table = ['mklabel', 'msdos']
|
||||||
create_boot_partition = ['mkpart', 'primary', 'ext2', '0%', boot_partition_size]
|
create_boot_partition = ['mkpart', 'primary', 'ext2', '0%', boot_partition_size]
|
||||||
create_root_partition = ['mkpart', 'primary', boot_partition_size, '100%']
|
create_root_partition = ['mkpart', 'primary', boot_partition_size, '100%']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue