From: Daan De Meyer Date: Fri, 2 Feb 2024 08:51:45 +0000 (+0100) Subject: Add fallback for older bootctl X-Git-Tag: v21~74^2 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2341%2Fhead;p=thirdparty%2Fmkosi.git Add fallback for older bootctl --- 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)