From 2247fc5aad7230f71e8e7bc3b195490f10467c22 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 6 Oct 2020 11:34:19 +0200 Subject: [PATCH] pmbootstrap install: add --ondev --no-rootfs (MR 1995) Skip building the postmarketOS rootfs, and allow either installing a pre-built pmOS rootfs, or even another operating system. --- pmb/helpers/frontend.py | 23 +++++++++++++++++++++++ pmb/install/_install.py | 34 +++++++++++++++++++--------------- pmb/parse/arguments.py | 6 ++++++ 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index a4ab8428..9237beb4 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -70,6 +70,24 @@ def _parse_suffix(args): return "native" +def _install_ondev_verify_no_rootfs(args): + chroot_dest = "/var/lib/rootfs.img" + dest = f"{args.work}/chroot_installer_{args.device}{chroot_dest}" + if os.path.exists(dest): + return + + if args.ondev_cp: + for _, chroot_dest_cp in args.ondev_cp: + if chroot_dest_cp == chroot_dest: + return + + raise ValueError(f"--no-rootfs set, but rootfs.img not found in install" + " chroot. Either run 'pmbootstrap install' without" + " --no-rootfs first to let it generate the postmarketOS" + " rootfs once, or supply a rootfs file with:" + f" --cp os.img:{chroot_dest}") + + def aportgen(args): for package in args.packages: logging.info("Generate aport: " + package) @@ -236,6 +254,11 @@ def install(args): else: if args.ondev_cp: raise ValueError("--cp can only be combined with --ondev") + if args.ondev_no_rootfs: + raise ValueError("--no-rootfs can only be combined with --ondev." + " Do you mean --no-image?") + if args.ondev_no_rootfs: + _install_ondev_verify_no_rootfs(args) # On-device installer overrides if args.on_device_installer: diff --git a/pmb/install/_install.py b/pmb/install/_install.py index 33f9101c..a5a8d020 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -608,10 +608,11 @@ def install_recovery_zip(args, steps): def install_on_device_installer(args, step, steps): # Generate the rootfs image - suffix_rootfs = f"rootfs_{args.device}" - install_system_image(args, 0, suffix_rootfs, step=step, steps=steps, - split=True) - step += 2 + if not args.ondev_no_rootfs: + suffix_rootfs = f"rootfs_{args.device}" + install_system_image(args, 0, suffix_rootfs, step=step, steps=steps, + split=True) + step += 2 # Prepare the installer chroot logging.info(f"*** ({step}/{steps}) CREATE ON-DEVICE INSTALLER ROOTFS ***") @@ -624,12 +625,13 @@ def install_on_device_installer(args, step, steps): pmb.chroot.apk.install(args, packages, suffix_installer) # Move rootfs image into installer chroot - img = f"{args.device}-root.img" - img_path_src = f"{args.work}/chroot_native/home/pmos/rootfs/{img}" img_path_dest = f"{args.work}/chroot_{suffix_installer}/var/lib/rootfs.img" - logging.info(f"({suffix_installer}) add {img} as /var/lib/rootfs.img") - pmb.install.losetup.umount(args, img_path_src) - pmb.helpers.run.root(args, ["mv", img_path_src, img_path_dest]) + if not args.ondev_no_rootfs: + img = f"{args.device}-root.img" + img_path_src = f"{args.work}/chroot_native/home/pmos/rootfs/{img}" + logging.info(f"({suffix_installer}) add {img} as /var/lib/rootfs.img") + pmb.install.losetup.umount(args, img_path_src) + pmb.helpers.run.root(args, ["mv", img_path_src, img_path_dest]) # Run ondev-prepare, so it may generate nice configs from the channel # properties (e.g. to display the version number), or transform the image @@ -659,9 +661,10 @@ def install_on_device_installer(args, step, steps): # Remove $DEVICE-boot.img (we will generate a new one if --split was # specified, otherwise the separate boot image is not needed) - img_boot = f"{args.device}-boot.img" - logging.info(f"(native) rm {img_boot}") - pmb.chroot.root(args, ["rm", f"/home/pmos/rootfs/{img_boot}"]) + if not args.ondev_no_rootfs: + img_boot = f"{args.device}-boot.img" + logging.info(f"(native) rm {img_boot}") + pmb.chroot.root(args, ["rm", f"/home/pmos/rootfs/{img_boot}"]) # Generate installer image size_reserve = round(os.path.getsize(img_path_dest) / 1024 / 1024) + 200 @@ -740,7 +743,7 @@ def install(args): elif args.android_recovery_zip: steps = 3 elif args.on_device_installer: - steps = 7 + steps = 4 if args.ondev_no_rootfs else 7 else: steps = 4 @@ -751,8 +754,9 @@ def install(args): build=False) step += 1 - create_device_rootfs(args, step, steps) - step += 1 + if not args.ondev_no_rootfs: + create_device_rootfs(args, step, steps) + step += 1 if args.no_image: return diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 07c412bf..c74b7490 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -144,6 +144,12 @@ def arguments_install(subparser): metavar="HOST_SRC:CHROOT_DEST", type=type_ondev_cp, help="copy one or more files from the host system path" " HOST_SRC to the target path CHROOT_DEST") + group.add_argument("--no-rootfs", dest="ondev_no_rootfs", + help="do not generate a pmOS rootfs as" + " /var/lib/rootfs.img (install chroot). The file" + " must either exist from a previous" + " 'pmbootstrap install' run or by providing it" + " as CHROOT_DEST with --cp", action="store_true") def arguments_export(subparser):