From 807d7019f8cb1d95f6326ecb0f4809c8519c2ec9 Mon Sep 17 00:00:00 2001 From: Bobby The Builder Date: Sun, 7 Mar 2021 08:38:37 -0500 Subject: [PATCH] install: add --filesystem to handle ext4 or f2fs (MR 2011) Co-Authored-By: Oliver Smith --- pmb/config/__init__.py | 1 + pmb/helpers/frontend.py | 8 +++++++- pmb/install/format.py | 33 ++++++++++++++++++++------------- pmb/parse/arguments.py | 5 +++++ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 639dfc60..34e0e955 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -420,6 +420,7 @@ deviceinfo_attributes = [ "sd_embed_firmware_step_size", "partition_blacklist", "boot_part_start", + "root_filesystem", # weston "weston_pixman_type", diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index f131b37c..d85c5077 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -251,6 +251,9 @@ def install(args): if args.rsync: raise ValueError("--on-device-installer cannot be combined with" " --rsync") + if args.filesystem: + raise ValueError("--on-device-installer cannot be combined with" + " --filesystem") else: if args.ondev_cp: raise ValueError("--cp can only be combined with --ondev") @@ -279,7 +282,10 @@ def install(args): if flasher.get("split", False): args.split = True - # Warning for android recovery zip with FDE + # Android recovery zip related + if args.android_recovery_zip and args.filesystem: + raise ValueError("--android-recovery-zip cannot be combined with" + " --filesystem (patches welcome)") if args.android_recovery_zip and args.full_disk_encryption: logging.info("WARNING: --fde is rarely used in combination with" " --android-recovery-zip. If this does not work, consider" diff --git a/pmb/install/format.py b/pmb/install/format.py index 17a8d89d..c1e9e3e2 100644 --- a/pmb/install/format.py +++ b/pmb/install/format.py @@ -75,21 +75,28 @@ def format_and_mount_root(args, device, root_label, sdcard): """ # Format if not args.rsync: - # Some downstream kernels don't support metadata_csum (#1364). - # When changing the options of mkfs.ext4, also change them in the - # recovery zip code (see 'grep -r mkfs\.ext4')! - mkfs_ext4_args = ["mkfs.ext4", "-O", "^metadata_csum", "-F", - "-q", "-L", root_label] + filesystem = (args.filesystem or args.deviceinfo["root_filesystem"] or + "ext4") - # When we don't know the file system size before hand like - # with non-block devices, we need to explicitely set a number of - # inodes. See #1717 and #1845 for details - if not sdcard: - mkfs_ext4_args = mkfs_ext4_args + ["-N", "100000"] + if filesystem == "ext4": + # Some downstream kernels don't support metadata_csum (#1364). + # When changing the options of mkfs.ext4, also change them in the + # recovery zip code (see 'grep -r mkfs\.ext4')! + mkfs_root_args = ["mkfs.ext4", "-O", "^metadata_csum", "-F", + "-q", "-L", root_label] + # When we don't know the file system size before hand like + # with non-block devices, we need to explicitely set a number of + # inodes. See #1717 and #1845 for details + if not sdcard: + mkfs_root_args = mkfs_root_args + ["-N", "100000"] + elif filesystem == "f2fs": + mkfs_root_args = ["mkfs.f2fs", "-f", "-l", root_label] + else: + raise RuntimeError(f"Don't know how to format {filesystem}!") - install_fsprogs(args, "ext4") - logging.info("(native) format " + device) - pmb.chroot.root(args, mkfs_ext4_args + [device]) + install_fsprogs(args, filesystem) + logging.info(f"(native) format {device} (root, {filesystem})") + pmb.chroot.root(args, mkfs_root_args + [device]) # Mount mountpoint = "/mnt/install" diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 267fb439..f1c3a7b9 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -155,6 +155,11 @@ def arguments_install(subparser): " 'pmbootstrap install' run or by providing it" " as CHROOT_DEST with --cp", action="store_true") + # Other + group = ret.add_argument_group("other optional arguments") + group.add_argument("--filesystem", help="root filesystem type", + choices=["ext4", "f2fs"]) + def arguments_export(subparser): ret = subparser.add_parser("export", help="create convenience symlinks"