image: pass sector_size to partition_device()

This commit is contained in:
InsanePrawn 2023-07-09 21:52:03 +02:00
parent fbe43456f8
commit d2942945e4
2 changed files with 10 additions and 23 deletions

View file

@ -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',