Skip to content

Commit

Permalink
mkosi-initrd: add some autodetection logic if output is not specified
Browse files Browse the repository at this point in the history
Make use of installation layout (bls or other), `$BOOT_ROOT` partition and
entry token provided by `kernel-install`.
  • Loading branch information
aafeijoo-suse committed Oct 1, 2024
1 parent b7beda5 commit 33c612e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions mkosi/initrd.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

import argparse
import json
import os
import platform
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
from typing import Optional, cast

import mkosi.resources
from mkosi.config import DocFormat, OutputFormat
Expand All @@ -18,6 +21,30 @@
from mkosi.util import resource_path


def get_layout_output_dir() -> tuple[Optional[str], str]:
layout = ""
output_dir = ""

if find_binary("kernel-install"):
output = json.loads(
run(
["kernel-install", "--json=short", "inspect"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
check=False,
).stdout
)
layout = cast(str, output["Layout"])
if layout == "bls":
boot_root = cast(str, output["BootRoot"])
entry_token = cast(str, output["EntryToken"])
output_dir = f"{boot_root}/{entry_token}"
elif layout == "other":
output_dir = "/boot"

return (layout or None, output_dir)


@uncaught_exception_handler()
def main() -> None:
log_setup()
Expand Down Expand Up @@ -88,6 +115,16 @@ def main() -> None:
show_docs("mkosi-initrd", DocFormat.all(), resources=r)
return

if not args.output_dir:
layout, args.output_dir = get_layout_output_dir()
if args.output_dir:
if layout == "bls":
args.output_dir += "/" + args.kernel_version
if not Path(args.output_dir).is_dir():
args.output_dir = ""
elif layout == "other" and args.output == "initrd":
args.output += "-" + args.kernel_version

cmdline: list[PathString] = [
"mkosi",
"--force",
Expand Down

0 comments on commit 33c612e

Please sign in to comment.