-
Notifications
You must be signed in to change notification settings - Fork 332
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
Add new mkosi-addon and kernel-install plugin to build local customizations into an EFI addon. 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
13 changed files
with
417 additions
and
143 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
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,54 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import logging | ||
import sys | ||
from pathlib import Path | ||
|
||
from mkosi.initrd import KernelInstallContext | ||
from mkosi.log import log_setup | ||
from mkosi.run import run, uncaught_exception_handler | ||
from mkosi.types import PathString | ||
|
||
|
||
@uncaught_exception_handler() | ||
def main() -> None: | ||
log_setup() | ||
|
||
context = KernelInstallContext.parse( | ||
"kernel-install plugin to build local addon for initrd/cmdline", | ||
"51-mkosi-addon.install COMMAND KERNEL_VERSION ENTRY_DIR KERNEL_IMAGE…", | ||
) | ||
|
||
# No local configuration? Then nothing to do | ||
if not Path("/etc/mkosi-addon").exists() and not Path("/run/mkosi-addon").exists(): | ||
if context.verbose: | ||
logging.info("No local configuration defined, skipping mkosi-addon") | ||
return | ||
|
||
if context.command != "add" or context.layout != "uki": | ||
if context.verbose: | ||
logging.info("Not an UKI layout 'add' step, skipping mkosi-addon") | ||
return | ||
|
||
if not context.kernel_image or not context.kernel_image.exists(): | ||
if context.verbose: | ||
logging.info("No kernel image provided, skipping mkosi-addon") | ||
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("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
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,92 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import argparse | ||
import os | ||
import sys | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import mkosi.resources | ||
from mkosi.config import DocFormat | ||
from mkosi.documentation import show_docs | ||
from mkosi.initrd import initrd_common_args, initrd_finalize, process_crypttab | ||
from mkosi.log import log_setup | ||
from mkosi.run import run, uncaught_exception_handler | ||
from mkosi.types import PathString | ||
from mkosi.util import resource_path | ||
|
||
|
||
@uncaught_exception_handler() | ||
def main() -> None: | ||
log_setup() | ||
|
||
parser = argparse.ArgumentParser( | ||
prog="mkosi-addon", | ||
description="Build initrd/cmdline/ucode addon for the current system using mkosi", | ||
allow_abbrev=False, | ||
usage="mkosi-addon [options...]", | ||
) | ||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
metavar="NAME", | ||
help="Output name", | ||
default="mkosi-local.addon.efi", | ||
) | ||
|
||
initrd_common_args(parser) | ||
|
||
args = parser.parse_args() | ||
|
||
if args.show_documentation: | ||
with resource_path(mkosi.resources) as r: | ||
show_docs("mkosi-addon", DocFormat.all(), resources=r) | ||
return | ||
|
||
with tempfile.TemporaryDirectory() as staging_dir: | ||
cmdline: list[PathString] = [ | ||
"mkosi", | ||
"--force", | ||
"--directory", "", | ||
"--output", args.output, | ||
"--output-directory", staging_dir, | ||
"--build-sources", "", | ||
"--include=mkosi-addon", | ||
"--extra-tree", | ||
f"/usr/lib/modules/{args.kernel_version}:/usr/lib/modules/{args.kernel_version}", | ||
"--extra-tree=/usr/lib/firmware:/usr/lib/firmware", | ||
"--kernel-modules-exclude=.*", | ||
] # fmt: skip | ||
|
||
if args.debug: | ||
cmdline += ["--debug"] | ||
if args.debug_shell: | ||
cmdline += ["--debug-shell"] | ||
|
||
if os.getuid() == 0: | ||
cmdline += [ | ||
"--workspace-dir=/var/tmp", | ||
"--output-mode=600", | ||
] | ||
|
||
for d in ( | ||
"/usr/lib/mkosi-addon", | ||
"/usr/local/lib/mkosi-addon", | ||
"/run/mkosi-addon", | ||
"/etc/mkosi-addon", | ||
): | ||
if Path(d).exists(): | ||
cmdline += ["--include", d] | ||
|
||
cmdline += process_crypttab(staging_dir) | ||
|
||
if Path("/etc/kernel/cmdline").exists(): | ||
cmdline += ["--kernel-command-line", Path("/etc/kernel/cmdline").read_text()] | ||
|
||
run(cmdline, stdin=sys.stdin, stdout=sys.stdout) | ||
|
||
initrd_finalize(staging_dir, args.output, args.output_dir) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.