From: Michael Ferrari Date: Thu, 17 Oct 2024 19:52:28 +0000 (+0200) Subject: Refactor copy_{uki,vmlinuz,initrd} X-Git-Tag: v25~208^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7be94543a6145fdd28e148d9810701b50c2be0d7;p=thirdparty%2Fmkosi.git Refactor copy_{uki,vmlinuz,initrd} A follow-up commit will introduce the ability to disable copying these to the output directory, so refactor all the logic so that they are contained within their respectiv functions. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a3f653182..fe11b337b 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2152,12 +2152,9 @@ def copy_nspawn_settings(context: Context) -> None: shutil.copy2(context.config.nspawn_settings, context.staging / context.config.output_nspawn_settings) -def copy_uki(context: Context) -> None: - if (context.staging / context.config.output_split_uki).exists(): - return - +def get_uki_path(context: Context) -> Optional[Path]: if not want_efi(context.config) or context.config.unified_kernel_images == ConfigFeature.disabled: - return + return None ukis = sorted( (context.root / "boot/EFI/Linux").glob("*.efi"), @@ -2176,22 +2173,29 @@ def copy_uki(context: Context) -> None: elif ukis: uki = ukis[0] else: - return + return None - shutil.copy(uki, context.staging / context.config.output_split_uki) + return uki - # Extract the combined initrds from the UKI so we can use it to direct kernel boot with qemu if needed. - extract_pe_section(context, uki, ".initrd", context.staging / context.config.output_split_initrd) - # ukify will have signed the kernel image as well. Let's make sure we put the signed kernel - # image in the output directory instead of the unsigned one by reading it from the UKI. - extract_pe_section(context, uki, ".linux", context.staging / context.config.output_split_kernel) +def copy_uki(context: Context) -> None: + if (context.staging / context.config.output_split_uki).exists(): + return + + if uki := get_uki_path(context): + shutil.copy(uki, context.staging / context.config.output_split_uki) def copy_vmlinuz(context: Context) -> None: if (context.staging / context.config.output_split_kernel).exists(): return + # ukify will have signed the kernel image as well. Let's make sure we put the signed kernel + # image in the output directory instead of the unsigned one by reading it from the UKI. + if uki := get_uki_path(context): + extract_pe_section(context, uki, ".linux", context.staging / context.config.output_split_kernel) + return + for _, kimg in gen_kernel_images(context): shutil.copy(context.root / kimg, context.staging / context.config.output_split_kernel) break @@ -2204,6 +2208,11 @@ def copy_initrd(context: Context) -> None: if (context.staging / context.config.output_split_initrd).exists(): return + # Extract the combined initrds from the UKI so we can use it to direct kernel boot with qemu if needed. + if uki := get_uki_path(context): + extract_pe_section(context, uki, ".initrd", context.staging / context.config.output_split_initrd) + return + for kver, _ in gen_kernel_images(context): initrds = finalize_initrds(context)