Skip to content

Commit

Permalink
Add support for building UKI addons
Browse files Browse the repository at this point in the history
  • Loading branch information
NekkoDroid committed Sep 28, 2024
1 parent 84c1701 commit 105d81c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,35 @@ def install_uki(
f.write("fi\n")


def build_uki_addon(context: Context, config: Path, output: Path) -> None:
cmd: list[PathString] = [
"build",
"--output", output,
"--config", config,
] # fmt: skip

options: list[PathString] = [
"--bind", output.parent, output.parent,
"--ro-bind", config, config,
] # fmt: skip

with complete_step(f"Generating UKI addon for {config}"):
run_ukify(context, cmd, options)


def install_uki_addons(context: Context) -> None:
if not context.config.unified_kernel_image_addons:
return

addon_dir = context.root / "boot/loader/addons"
with umask(~0o755):
addon_dir.mkdir(parents=True, exist_ok=True)

for addon in context.config.unified_kernel_image_addons:
output = addon_dir / addon.with_suffix(".addon.efi").name
build_uki_addon(context, config=addon, output=output)


def install_kernel(context: Context, partitions: Sequence[Partition]) -> None:
# Iterates through all kernel versions included in the image and generates a combined
# kernel+initrd+cmdline+osrelease EFI file from it and places it in the /EFI/Linux directory of
Expand Down Expand Up @@ -1943,6 +1972,9 @@ def install_kernel(context: Context, partitions: Sequence[Partition]) -> None:
if context.config.bootloader == Bootloader.uki:
break

if want_uki(context):
install_uki_addons(context)


def make_uki(
context: Context, stub: Path, kver: str, kimg: Path, microcode: list[Path], output: Path
Expand Down
11 changes: 11 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,7 @@ class Config:
shim_bootloader: ShimBootloader
unified_kernel_images: ConfigFeature
unified_kernel_image_format: str
unified_kernel_image_addons: list[Path]
initrds: list[Path]
initrd_packages: list[str]
initrd_volatile_packages: list[str]
Expand Down Expand Up @@ -2552,6 +2553,15 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple
# default=
help="Specify the format used for the UKI filename",
),
ConfigSetting(
dest="unified_kernel_image_addons",
long="--unified-kernel-image-addon",
metavar="PATH",
section="Content",
parse=config_make_list_parser(delimiter=",", parse=make_path_parser()),
recursive_paths=("mkosi.uki-addons/",),
help="Configuration files to generate UKI addons",
),
ConfigSetting(
dest="initrds",
long="--initrd",
Expand Down Expand Up @@ -4479,6 +4489,7 @@ def summary(config: Config) -> str:
Shim Bootloader: {config.shim_bootloader}
Unified Kernel Images: {config.unified_kernel_images}
Unified Kernel Image Format: {config.unified_kernel_image_format}
Unified Kernel Image Addons: {line_join_list(config.unified_kernel_image_addons)}
Initrds: {line_join_list(config.initrds)}
Initrd Packages: {line_join_list(config.initrd_packages)}
Initrd Volatile Packages: {line_join_list(config.initrd_volatile_packages)}
Expand Down
8 changes: 8 additions & 0 deletions mkosi/resources/man/mkosi.md
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,14 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
| `&h` | `roothash=` or `usrhash=` value of kernel argument |
| `&c` | Number of tries used for boot attempt counting |

`UnifiedKernelImageAddons=`, `--unified-kernel-image-addon`
: Build additional UKI addons. Takes a comma separated list of paths to
`ukify` config files. This option may be used multiple times in which case
each config gets built into a corresponding addon. Each addon has the name
of the config file, with the extension replaced with `.addon.efi`.
Config files in the `mkosi.uki-addons/` directory are automatically picked
up.

`Initrds=`, `--initrd`
: Use user-provided initrd(s). Takes a comma separated list of paths to initrd
files. This option may be used multiple times in which case the initrd lists
Expand Down
4 changes: 4 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ def test_config() -> None:
"Target": "/"
}
],
"UnifiedKernelImageAddons": [
"/my-addon.conf"
],
"UnifiedKernelImageFormat": "myuki",
"UnifiedKernelImages": "auto",
"UnitProperties": [
Expand Down Expand Up @@ -515,6 +518,7 @@ def test_config() -> None:
tools_tree_packages=[],
tools_tree_release=None,
tools_tree_repositories=["abc"],
unified_kernel_image_addons=[Path("/my-addon.conf")],
unified_kernel_image_format="myuki",
unified_kernel_images=ConfigFeature.auto,
unit_properties=["PROPERTY=VALUE"],
Expand Down

0 comments on commit 105d81c

Please sign in to comment.