From f0a9d3a670c966f7e12cbcd30048bb8b3e48b58e Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Mon, 7 Feb 2022 01:48:55 +0100 Subject: [PATCH] image.py: add create_filesystem(), improve log output in cmd_inspect() --- image.py | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/image.py b/image.py index 86049c9..1ab21c6 100644 --- a/image.py +++ b/image.py @@ -268,36 +268,31 @@ def partition_device(device: str): raise Exception(f'Failed to create partitions on {device}') -def create_root_fs(device: str, blocksize: int): - result = subprocess.run([ - 'mkfs.ext4', - '-O', - '^metadata_csum', +def create_filesystem(device: str, blocksize: int = 4096, label=None, options=[], fstype='ext4'): + # blocksize can be 4k max due to pagesize + blocksize = min(blocksize, 4096) + if fstype.startswith('ext'): + # blocksize for ext-fs must be >=1024 + blocksize = max(blocksize, 1024) + + labels = ['-L', label] if label else [] + cmd = [ + f'mkfs.{fstype}', '-F', - '-L', - 'kupfer_root', - '-N', - '100000', '-b', str(blocksize), - device, - ]) + ] + labels + [device] + result = subprocess.run(cmd) if result.returncode != 0: - raise Exception(f'Failed to create ext4 filesystem on {device}') + raise Exception(f'Failed to create {fstype} filesystem on {device} with CMD: {cmd}') + + +def create_root_fs(device: str, blocksize: int): + create_filesystem(device, blocksize=blocksize, label='kupfer_root', options=['-O', '^metadata_csum', '-N', '100000']) def create_boot_fs(device: str, blocksize: int): - result = subprocess.run([ - 'mkfs.ext2', - '-F', - '-L', - 'kupfer_boot', - '-b', - str(blocksize), - device, - ]) - if result.returncode != 0: - raise Exception(f'Failed to create ext2 filesystem on {device}') + create_filesystem(device, blocksize=blocksize, label='kupfer_boot', fstype='ext2') def install_rootfs(rootfs_device: str, bootfs_device: str, device, flavour, arch, packages, extra_repos, profile): @@ -437,7 +432,10 @@ def cmd_inspect(shell: bool = False): if shell: chroot.initialized = True chroot.activate() - build_enable_qemu_binfmt(arch) + if arch != config.runtime['arch']: + logging.info('Installing requisites for foreign-arch shell') + build_enable_qemu_binfmt(arch) + logging.info('Starting inspection shell') chroot.run_cmd('/bin/bash') else: pause()