-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mkosi-addon and kernel-install plugin
Change mkosi-initrd to avoid adding local customizations (crypttab, kmods, fw) to the UKI by default, with an --host-only override. Add new mkosi-addon and kernel-install plugin to build local customizations into an EFI addon instead. This allows us to move closer to the desired goal of having universal UKIs, built by vendors, used together with locally built enhancements.
- Loading branch information
Showing
14 changed files
with
494 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*.cache-pre-inst | ||
.cache | ||
.mkosi.1 | ||
.mkosi-addon.1 | ||
.mkosi-initrd.1 | ||
.mkosi-sandbox.1 | ||
.mypy_cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mkosi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import argparse | ||
import dataclasses | ||
import logging | ||
import os | ||
import sys | ||
import tempfile | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from mkosi import identify_cpu | ||
from mkosi.archive import make_cpio | ||
from mkosi.config import OutputFormat | ||
from mkosi.log import die, log_setup | ||
from mkosi.run import run, uncaught_exception_handler | ||
from mkosi.sandbox import __version__, umask | ||
from mkosi.types import PathString | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class Context: | ||
command: str | ||
kernel_version: str | ||
entry_dir: Path | ||
kernel_image: Path | ||
staging_area: Path | ||
layout: str | ||
image_type: str | ||
verbose: bool | ||
|
||
|
||
def we_are_wanted(context: Context) -> bool: | ||
return context.layout == "uki" | ||
|
||
|
||
def mandatory_variable(name: str) -> str: | ||
try: | ||
return os.environ[name] | ||
except KeyError: | ||
die(f"${name} must be set in the environment") | ||
|
||
|
||
@uncaught_exception_handler() | ||
def main() -> None: | ||
log_setup() | ||
|
||
parser = argparse.ArgumentParser( | ||
description="kernel-install plugin to build local addon for initrd/cmdline/ucode", | ||
allow_abbrev=False, | ||
usage="51-mkosi-addon.install COMMAND KERNEL_VERSION ENTRY_DIR KERNEL_IMAGE…", | ||
) | ||
|
||
parser.add_argument( | ||
"command", | ||
metavar="COMMAND", | ||
help="The action to perform. Only 'add' is supported.", | ||
) | ||
parser.add_argument( | ||
"kernel_version", | ||
metavar="KERNEL_VERSION", | ||
help="Kernel version string", | ||
) | ||
parser.add_argument( | ||
"entry_dir", | ||
metavar="ENTRY_DIR", | ||
type=Path, | ||
nargs="?", | ||
help="Type#1 entry directory (ignored)", | ||
) | ||
parser.add_argument( | ||
"kernel_image", | ||
metavar="KERNEL_IMAGE", | ||
type=Path, | ||
nargs="?", | ||
help="Kernel image", | ||
) | ||
parser.add_argument( | ||
"--version", | ||
action="version", | ||
version=f"mkosi {__version__}", | ||
) | ||
|
||
context = Context( | ||
**vars(parser.parse_args()), | ||
staging_area=Path(mandatory_variable("KERNEL_INSTALL_STAGING_AREA")), | ||
layout=mandatory_variable("KERNEL_INSTALL_LAYOUT"), | ||
image_type=mandatory_variable("KERNEL_INSTALL_IMAGE_TYPE"), | ||
verbose=int(os.getenv("KERNEL_INSTALL_VERBOSE", 0)) > 0, | ||
) | ||
|
||
if context.command != "add" or not context.layout == "uki": | ||
return | ||
|
||
cmdline: list[PathString] = [ | ||
"mkosi-addon", | ||
"--output", "mkosi-local.addon.efi", | ||
"--output-dir", context.staging_area / "uki.efi.extra.d", | ||
] # fmt: skip | ||
|
||
if context.verbose: | ||
cmdline += ["--debug"] | ||
|
||
logging.info(f"Building mkosi-local.addon.efi") | ||
|
||
run(cmdline, stdin=sys.stdin, stdout=sys.stdout) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mkosi/resources/mkosi-addon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.