From aa78259811ee20a4ad8261c8b7fcb33ecb7a2f44 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 2 Feb 2024 09:51:45 +0100 Subject: [PATCH] Add fallback for older bootctl --- mkosi/__init__.py | 7 +------ mkosi/config.py | 6 ++++++ mkosi/qemu.py | 12 ++++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 7cbc22d9c..ac7f2e8ab 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -44,6 +44,7 @@ from mkosi.config import ( format_tree, parse_config, summary, + systemd_tool_version, want_selinux_relabel, yes_no, ) @@ -2220,12 +2221,6 @@ def check_outputs(config: Config) -> None: die(f"Output path {f} exists already. (Consider invocation with --force.)") -def systemd_tool_version(config: Config, tool: PathString) -> GenericVersion: - return GenericVersion( - run([tool, "--version"], stdout=subprocess.PIPE, sandbox=config.sandbox()).stdout.split()[2].strip("()") - ) - - def check_tool(config: Config, *tools: PathString, reason: str, hint: Optional[str] = None) -> Path: tool = find_binary(*tools, root=config.tools()) if not tool: diff --git a/mkosi/config.py b/mkosi/config.py index 1cfbbdd45..555463861 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -3763,3 +3763,9 @@ def want_selinux_relabel(config: Config, root: Path, fatal: bool = True) -> Opti binpolicy = sorted(policies, key=lambda p: GenericVersion(p.name), reverse=True)[0] return policy, fc, binpolicy + + +def systemd_tool_version(config: Config, tool: PathString) -> GenericVersion: + return GenericVersion( + run([tool, "--version"], stdout=subprocess.PIPE, sandbox=config.sandbox()).stdout.split()[2].strip("()") + ) diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 61db95ed1..11a50bf43 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -30,6 +30,7 @@ from mkosi.config import ( QemuFirmware, QemuVsockCID, format_bytes, + systemd_tool_version, want_selinux_relabel, ) from mkosi.log import die @@ -139,8 +140,15 @@ class KernelType(StrEnum): @classmethod def identify(cls, config: Config, path: Path) -> "KernelType": - type = run(["bootctl", "kernel-identify", path], - stdout=subprocess.PIPE, sandbox=config.sandbox(options=["--ro-bind", path, path])).stdout.strip() + if systemd_tool_version(config, "bootctl") < 253: + logging.warning("bootctl doesn't know kernel-identify verb, assuming 'unknown' kernel type") + return KernelType.unknown + + type = run( + ["bootctl", "kernel-identify", path], + stdout=subprocess.PIPE, + sandbox=config.sandbox(options=["--ro-bind", path, path]), + ).stdout.strip() try: return cls(type) -- 2.47.2