From: Daan De Meyer Date: Thu, 4 Jul 2024 18:41:09 +0000 (+0200) Subject: Replace root=PARTUUID and mount.usr=PARTUUID with the actual partition UUID X-Git-Tag: v24~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d85ff5854b3b06f28d0f35f1fecd61115ad335be;p=thirdparty%2Fmkosi.git Replace root=PARTUUID and mount.usr=PARTUUID with the actual partition UUID These are not known upfront so let's treat these literals as placeholders which are to be replaced with the actual partition UUID when we know it. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 474542c08..c88206156 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2278,7 +2278,7 @@ def find_entry_token(context: Context) -> str: return cast(str, output["EntryToken"]) -def finalize_cmdline(context: Context, roothash: Optional[str]) -> list[str]: +def finalize_cmdline(context: Context, partitions: Sequence[Partition], roothash: Optional[str]) -> list[str]: if (context.root / "etc/kernel/cmdline").exists(): cmdline = [(context.root / "etc/kernel/cmdline").read_text().strip()] elif (context.root / "usr/lib/kernel/cmdline").exists(): @@ -2289,7 +2289,16 @@ def finalize_cmdline(context: Context, roothash: Optional[str]) -> list[str]: if roothash: cmdline += [roothash] - return cmdline + context.config.kernel_command_line + cmdline += context.config.kernel_command_line + + if not roothash: + for name in ("root", "mount.usr"): + if not (root := next((p.uuid for p in partitions if p.type.startswith(name)), None)): + continue + + cmdline = [f"{name}=PARTUUID={root}" if c == f"{name}=PARTUUID" else c for c in cmdline] + + return cmdline def finalize_microcode(context: Context) -> list[Path]: @@ -2322,7 +2331,7 @@ def install_type1( entry.parent.mkdir(parents=True, exist_ok=True) kmods = build_kernel_modules_initrd(context, kver) - cmdline = finalize_cmdline(context, finalize_roothash(partitions)) + cmdline = finalize_cmdline(context, partitions, finalize_roothash(partitions)) with umask(~0o600): if ( @@ -2360,8 +2369,12 @@ def install_type1( config = prepare_grub_config(context) assert config - root = finalize_root(partitions) - assert root + if ( + not any(c.startswith("root=PARTUUID=") for c in context.config.kernel_command_line) and + not any(c.startswith("mount.usr=PARTUUID=") for c in context.config.kernel_command_line) and + (root := finalize_root(partitions)) + ): + cmdline = [root] + cmdline with config.open("a") as f: f.write("if ") @@ -2379,7 +2392,7 @@ def install_type1( textwrap.dedent( f"""\ menuentry "{token}-{kver}" {{ - linux /{kimg.relative_to(context.root / "boot")} {root} {" ".join(cmdline)} + linux /{kimg.relative_to(context.root / "boot")} {" ".join(cmdline)} initrd {" ".join(os.fspath(Path("/") / i.relative_to(context.root / "boot")) for i in initrds)} }} """ @@ -2470,7 +2483,7 @@ def install_uki(context: Context, kver: str, kimg: Path, token: str, partitions: context.root / kimg, microcodes, initrds, - finalize_cmdline(context, roothash), + finalize_cmdline(context, partitions, roothash), boot_binary, ) diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index aa206bd3b..8ccbfa284 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -1066,6 +1066,14 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, `KernelCommandLine=`, `--kernel-command-line=` : Use the specified kernel command line when building images. + If the value of this setting contains the literals `root=PARTUUID` + or `mount.usr=PARTUUID`, these are replaced with the partition UUID + of the root or usr partition respectively. For example, + `root=PARTUUID` would be replaced with + `root=PARTUUID=58c7d0b2-d224-4834-a16f-e036322e88f7` where + `58c7d0b2-d224-4834-a16f-e036322e88f7` is the partition UUID of the + root partition. + `KernelModulesInclude=`, `--kernel-modules-include=` : Takes a list of regex patterns that specify kernel modules to include in the image. Patterns should be relative to the `/usr/lib/modules//kernel` directory. mkosi checks for a match anywhere in the module