From 7d9e48a6524ccbea4e7734333e98b0278acb26e5 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Sun, 9 Jul 2023 19:57:24 +0200 Subject: [PATCH] image: use IMG_FILE_BOOT_DEFAULT_SIZE to calculate shrunk boot partition size --- image/cli.py | 16 +++++++++++++--- image/image.py | 7 +++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/image/cli.py b/image/cli.py index 3833339..9cc106c 100644 --- a/image/cli.py +++ b/image/cli.py @@ -114,6 +114,16 @@ def cmd_build( profile: Profile = config.get_profile(profile_name) flavour = get_profile_flavour(profile_name) 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: encryption = profile.encryption @@ -142,11 +152,11 @@ def cmd_build( makedir(os.path.dirname(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()) - partition_device(loop_device) + partition_device(loop_device, boot_partition_size=bootfs_size_str) partprobe(loop_device) boot_dev: str @@ -159,7 +169,7 @@ def cmd_build( root_dev = loop_root else: 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_raw = root_dev diff --git a/image/image.py b/image/image.py index bebe82d..557b7fb 100644 --- a/image/image.py +++ b/image/image.py @@ -356,8 +356,11 @@ def create_img_file(image_path: str, size_str: str): return image_path -def partition_device(device: str): - boot_partition_size = '100MiB' +def partition_device(device: str, boot_partition_size: Optional[str] = None): + 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_boot_partition = ['mkpart', 'primary', 'ext2', '0%', boot_partition_size] create_root_partition = ['mkpart', 'primary', boot_partition_size, '100%']