From: Daan De Meyer Date: Tue, 9 Dec 2025 11:59:35 +0000 (+0100) Subject: Add SplitArtifacts=repart-definitions X-Git-Tag: v26~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1acab18874433b504b080dcf8753826c8b0d5bd9;p=thirdparty%2Fmkosi.git Add SplitArtifacts=repart-definitions For use in mkosi-obs --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a7be4899a..a012d45fc 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2458,6 +2458,28 @@ def copy_initrd(context: Context) -> None: break +def copy_repart_definitions(context: Context) -> None: + if ArtifactOutput.repart_definitions not in context.config.split_artifacts: + return + + if context.config.output_format == OutputFormat.esp: + definitions = [context.workspace / "esp-definitions"] + elif context.config.output_format.is_extension_or_portable_image(): + definitions = [extension_or_portable_image_repart_definitions(context)] + elif (d := context.workspace / "repart-definitions").exists(): + definitions = [d] + elif context.config.output_format == OutputFormat.disk: + definitions = context.config.repart_dirs + else: + definitions = [] + + if not definitions: + return + + for d in definitions: + copy_tree(d, context.config.output_dir_or_cwd() / context.config.output_split_repart_definitions) + + def calculate_sha256sum(context: Context) -> None: if not context.config.checksum: return @@ -3729,7 +3751,7 @@ def write_split_roothash(context: Context, partitions: Sequence[Partition]) -> N (context.staging / context.config.output_split_roothash).write_text(roothash.partition("=")[2]) -def make_extension_or_portable_image(context: Context, output: Path) -> None: +def extension_or_portable_image_repart_definitions(context: Context) -> Path: if context.config.verity == Verity.disabled or ( context.config.verity == Verity.auto and (not context.config.verity_key or not context.config.verity_certificate) @@ -3738,7 +3760,11 @@ def make_extension_or_portable_image(context: Context, output: Path) -> None: else: unsigned = "" - r = context.resources / f"repart/definitions/{context.config.output_format}{unsigned}.repart.d" + return context.resources / f"repart/definitions/{context.config.output_format}{unsigned}.repart.d" + + +def make_extension_or_portable_image(context: Context, output: Path) -> None: + definitions = extension_or_portable_image_repart_definitions(context) cmdline: list[PathString] = [ "systemd-repart", @@ -3750,7 +3776,7 @@ def make_extension_or_portable_image(context: Context, output: Path) -> None: "--seed", str(context.config.seed) if context.config.seed else "random", "--empty=create", "--size=auto", - "--definitions", workdir(r), + "--definitions", workdir(definitions), workdir(output), ] # fmt: skip options: list[PathString] = [ @@ -3759,7 +3785,7 @@ def make_extension_or_portable_image(context: Context, output: Path) -> None: "--become-root", "--bind", output.parent, workdir(output.parent), *context.rootoptions(readonly=True), - "--ro-bind", r, workdir(r), + "--ro-bind", definitions, workdir(definitions), ] # fmt: skip if not context.config.architecture.is_native(): @@ -4019,6 +4045,7 @@ def build_image(context: Context) -> None: copy_uki(context) copy_vmlinuz(context) copy_initrd(context) + copy_repart_definitions(context) if context.config.output_format == OutputFormat.tar: make_tar(context.root, context.staging / context.config.output_with_format, sandbox=context.sandbox) diff --git a/mkosi/config.py b/mkosi/config.py index 961ddfc26..e84c328ff 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -633,6 +633,7 @@ class ArtifactOutput(StrEnum): roothash = enum.auto() os_release = enum.auto() kernel_modules_initrd = enum.auto() + repart_definitions = enum.auto() @staticmethod def compat_no() -> list["ArtifactOutput"]: @@ -2297,6 +2298,10 @@ class Config: def output_split_kernel_modules_initrd(self) -> str: return f"{self.output}.kernel-modules-initrd" + @property + def output_split_repart_definitions(self) -> str: + return f"{self.output}.repart.d" + @property def output_nspawn_settings(self) -> str: return f"{self.output}.nspawn" @@ -2339,6 +2344,7 @@ class Config: self.output_split_roothash, self.output_split_os_release, self.output_split_kernel_modules_initrd, + self.output_split_repart_definitions, self.output_nspawn_settings, self.output_checksum, self.output_signature, diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index b34eeb1ef..4cb8a1e48 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -692,7 +692,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, `SplitArtifacts=`, `--split-artifacts=` : The artifact types to split out of the final image. A comma-delimited list consisting of `uki`, `kernel`, `initrd`, `os-release`, `prcs`, `partitions`, - `roothash`, `kernel-modules-initrd` and `tar`. When building a bootable image `kernel` + `roothash`, `kernel-modules-initrd`, `repart-definitions` and `tar`. When building a bootable image `kernel` and `initrd` correspond to their artifact found in the image (or in the UKI), while `uki` copies out the entire UKI. If `pcrs` is specified, a JSON file containing the pre-calculated TPM2 digests is written out, according @@ -719,6 +719,11 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, initrd inspection tools don't properly handle multiple initrds appended to each other. + When `repart-definitions` is specified, a directory containing the used repart + definition files is written to the output directory. If multiple directories are + configured via `RepartDirectories=`, they are merged, with later directories + taking priority over earlier ones when files with identical names exist. + By default `uki`, `kernel` and `initrd` are split out. `RepartDirectories=`, `--repart-directory=`