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():
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]:
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 (
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 ")
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)}
}}
"""
context.root / kimg,
microcodes,
initrds,
- finalize_cmdline(context, roothash),
+ finalize_cmdline(context, partitions, roothash),
boot_binary,
)
`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