]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Refactor copy_{uki,vmlinuz,initrd}
authorMichael Ferrari <nekkodroid404@gmail.com>
Thu, 17 Oct 2024 19:52:28 +0000 (21:52 +0200)
committerMichael Ferrari <nekkodroid404@gmail.com>
Sun, 20 Oct 2024 11:35:49 +0000 (13:35 +0200)
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.

mkosi/__init__.py

index a3f6531820c67f6db05c11d2d5cd8123164f7b65..fe11b337b51b796ae3dae4cd3b2ac197841e259c 100644 (file)
@@ -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)