]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Replace root=PARTUUID and mount.usr=PARTUUID with the actual partition UUID
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 4 Jul 2024 18:41:09 +0000 (20:41 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 4 Jul 2024 20:59:44 +0000 (22:59 +0200)
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.

mkosi/__init__.py
mkosi/resources/mkosi.md

index 474542c0869ab49722683006d18a41bccd6f835d..c88206156f44baf51c36c187f513434ebf60e775 100644 (file)
@@ -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,
         )
 
index aa206bd3b90221652ef0a4fa11e06ccc133aba23..8ccbfa284918396ffab932cc4400a54721b04a98 100644 (file)
@@ -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/<kver>/kernel` directory. mkosi checks for a match anywhere in the module