mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
image: pass sector_size to partition_device()
This commit is contained in:
parent
3d3002114f
commit
f848474b08
2 changed files with 10 additions and 23 deletions
17
image/cli.py
17
image/cli.py
|
@ -17,7 +17,7 @@ from .boot import cmd_boot
|
|||
from .cryptsetup import encryption_option, get_cryptmapper_path, luks_close, luks_create, luks_open
|
||||
from .flash import cmd_flash
|
||||
from .image import (
|
||||
IMG_FILE_BOOT_DEFAULT_SIZE,
|
||||
IMG_DEFAULT_SIZE_BOOT_MB,
|
||||
create_boot_fs,
|
||||
create_img_file,
|
||||
create_root_fs,
|
||||
|
@ -114,16 +114,7 @@ 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)
|
||||
bootfs_size_mb = IMG_DEFAULT_SIZE_BOOT_MB
|
||||
|
||||
if encryption is None:
|
||||
encryption = profile.encryption
|
||||
|
@ -145,7 +136,7 @@ def cmd_build(
|
|||
pkgbuilds |= set(filter_pkgbuilds(packages_extra, arch=arch, allow_empty_results=True, use_paths=False))
|
||||
build_packages(pkgbuilds, arch, try_download=not no_download_pkgs)
|
||||
|
||||
sector_size = sector_size or device.get_image_sectorsize()
|
||||
sector_size = sector_size or device.get_image_sectorsize() or 512
|
||||
|
||||
image_path = block_target or get_image_path(device, flavour.name)
|
||||
|
||||
|
@ -156,7 +147,7 @@ def cmd_build(
|
|||
|
||||
loop_device = losetup_setup_image(image_path, sector_size or device.get_image_sectorsize_default())
|
||||
|
||||
partition_device(loop_device, boot_partition_size=bootfs_size_str)
|
||||
partition_device(loop_device, sector_size=sector_size, boot_partition_size_mb=bootfs_size_mb)
|
||||
partprobe(loop_device)
|
||||
|
||||
boot_dev: str
|
||||
|
|
|
@ -23,9 +23,7 @@ from .cryptsetup import is_luks, get_luks_offset, luks_close, luks_open
|
|||
|
||||
MAPPER_DIR = '/dev/mapper/'
|
||||
|
||||
# image files need to be slightly smaller than partitions to fit
|
||||
IMG_FILE_ROOT_DEFAULT_SIZE = "1800M"
|
||||
IMG_FILE_BOOT_DEFAULT_SIZE = "90M"
|
||||
IMG_DEFAULT_SIZE_BOOT_MB = 90
|
||||
|
||||
|
||||
def dd_image(input: str, output: str, blocksize='1M') -> CompletedProcess:
|
||||
|
@ -356,14 +354,12 @@ def create_img_file(image_path: str, size_str: str):
|
|||
return image_path
|
||||
|
||||
|
||||
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'
|
||||
def partition_device(device: str, sector_size: int, boot_partition_size_mb: int = IMG_DEFAULT_SIZE_BOOT_MB):
|
||||
initial_offset = 1048576 // sector_size # 2048 for 512, 256 for 4096
|
||||
boot_partition_size: int = align_bytes(boot_partition_size_mb * 1024 * 1024, 4096)
|
||||
create_partition_table = ['mklabel', 'msdos']
|
||||
create_boot_partition = ['mkpart', 'primary', 'ext2', '0%', boot_partition_size]
|
||||
create_root_partition = ['mkpart', 'primary', boot_partition_size, '100%']
|
||||
create_boot_partition = ['mkpart', 'primary', 'ext2', f'{initial_offset}s', f'{boot_partition_size}b']
|
||||
create_root_partition = ['mkpart', 'primary', f'{bytes_to_sectors(boot_partition_size, sector_size) + initial_offset}s', '100%']
|
||||
enable_boot = ['set', '1', 'boot', 'on']
|
||||
result = run_root_cmd([
|
||||
'parted',
|
||||
|
|
Loading…
Add table
Reference in a new issue