From: Daan De Meyer Date: Tue, 5 Jul 2022 13:44:01 +0000 (+0200) Subject: Add --cache-initrd option X-Git-Tag: v14~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59d59e1349053bb59a4214fa8723ff55daff4774;p=thirdparty%2Fmkosi.git Add --cache-initrd option Building initrds is slow, let's add an option that allows building the initrd as part of a cached image so that's it's only built once and reused in any final images. --- diff --git a/mkosi.md b/mkosi.md index 140d9c653..c36cf5bb5 100644 --- a/mkosi.md +++ b/mkosi.md @@ -645,6 +645,13 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0", supported distributions except Clear Linux and this option translates to enabling dracut's hostonly option. +`CacheInitrd=`, `--cache-initrd` + +: If specified, and incremental mode is used, mkosi will build the initrd + in the cache image and reuse it in the final image. Note that this means + that any changes that are only applied to the final image and not the + cached image won't be included in the initrd. + `UsrOnly=`, `--usr-only` : If specified, `mkosi` will only add the `/usr/` directory tree diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 321636520..3a831e473 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -5620,6 +5620,12 @@ def create_parser() -> ArgumentParserMkosi: action=BooleanAction, help="Enable dracut hostonly option", ) + group.add_argument( + "--cache-initrd", + metavar="BOOL", + action=BooleanAction, + help="When using incremental mode, build the initrd in the cache image and don't rebuild it in the final image", + ) group.add_argument( "--split-artifacts", metavar="BOOL", @@ -7391,8 +7397,14 @@ def setup_netdev(args: MkosiArgs, root: Path, do_run_build_script: bool, cached: run(["systemctl", "--root", root, "enable", "systemd-networkd"]) -def run_kernel_install(args: MkosiArgs, root: Path, do_run_build_script: bool, for_cache: bool) -> None: - if not args.bootable or do_run_build_script or for_cache: +def run_kernel_install(args: MkosiArgs, root: Path, do_run_build_script: bool, for_cache: bool, cached: bool) -> None: + if not args.bootable or do_run_build_script: + return + + if not args.cache_initrd and for_cache: + return + + if args.cache_initrd and cached: return with complete_step("Generating initramfs images…"): @@ -7504,7 +7516,7 @@ def build_image( install_build_src(args, root, do_run_build_script, for_cache) install_build_dest(args, root, do_run_build_script, for_cache) install_extra_trees(args, root, for_cache) - run_kernel_install(args, root, do_run_build_script, for_cache) + run_kernel_install(args, root, do_run_build_script, for_cache, cached_tree) install_boot_loader(args, root, loopdev, do_run_build_script, cached_tree) set_root_password(args, root, do_run_build_script, cached_tree) set_serial_terminal(args, root, do_run_build_script, cached_tree) diff --git a/mkosi/backend.py b/mkosi/backend.py index 60a3f7f5b..a4a1c7ca8 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -448,6 +448,7 @@ class MkosiArgs: with_unified_kernel_images: bool gpt_first_lba: Optional[int] hostonly_initrd: bool + cache_initrd: bool base_packages: Union[str, bool] packages: List[str] remove_packages: List[str] diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index 52f6cbc64..501841e03 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -140,6 +140,7 @@ class MkosiConfig: "ephemeral": False, "with_unified_kernel_images": True, "hostonly_initrd": False, + "cache_initrd": False, "ssh": False, "ssh_key": None, "ssh_timeout": 0, @@ -288,6 +289,8 @@ class MkosiConfig: ] if "HostonlyInitrd" in mk_config_output: self.reference_config[job_name]["hostonly_initrd"] = mk_config_output["HostonlyInitrd"] + if "CacheInitrd" in mk_config_output: + self.reference_config[job_name]["cache_initrd"] = mk_config_output["CacheInitrd"] if "MachineID" in mk_config_output: self.reference_config[job_name]["MachineID"] = mk_config_output["MachineID"] if "Packages" in mk_config: