]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Move debian/ubuntu kernel-install workaround to a kernel-install script 1060/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 15 Jul 2022 21:32:16 +0000 (23:32 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 27 Jul 2022 15:53:15 +0000 (17:53 +0200)
Instead of manually running dpkg-reconfigure dracut in mkosi. Let's
drop in a kernel install script that runs dpkg-reconfigure dracut. We
can install this script as part of the install function and get rid
of a distribution specific check.

mkosi/__init__.py
mkosi/resources/dpkg-reconfigure-dracut.install [new file with mode: 0644]

index b18bd9cde01ab51b4d344cd18eda044eb0f55ee9..cb12a8e81beb65a2c8f47450c549e0be92e85297 100644 (file)
@@ -2811,6 +2811,9 @@ def install_debian_or_ubuntu(args: MkosiArgs, root: Path, *, do_run_build_script
     if "bios" in args.boot_protocols or ("linux" in args.boot_protocols and "uefi" not in args.boot_protocols):
         root.joinpath("boot", args.machine_id).mkdir(mode=0o700)
 
+    write_resource(root / "etc/kernel/install.d/50-mkosi-dpkg-reconfigure-dracut.install",
+                   "mkosi.resources", "dpkg-reconfigure-dracut.install", executable=True)
+
 
 @complete_step("Installing Debian…")
 def install_debian(args: MkosiArgs, root: Path, do_run_build_script: bool) -> None:
@@ -7213,12 +7216,6 @@ def run_kernel_install(args: MkosiArgs, root: Path, do_run_build_script: bool, f
         return
 
     with complete_step("Generating initramfs images…"):
-        # Running kernel-install on Debian/Ubuntu doesn't regenerate the initramfs. Instead, we can trigger
-        # regeneration of the initramfs via "dpkg-reconfigure dracut". kernel-install can then be called to put
-        # the generated initrds in the right place.
-        if args.distribution in (Distribution.debian, Distribution.ubuntu):
-            run_workspace_command(args, root, ["dpkg-reconfigure", "dracut"])
-
         for kver, kimg in gen_kernel_images(args, root):
             run_workspace_command(args, root, ["kernel-install", "add", kver, Path("/") / kimg],
                                   env=args.environment)
diff --git a/mkosi/resources/dpkg-reconfigure-dracut.install b/mkosi/resources/dpkg-reconfigure-dracut.install
new file mode 100644 (file)
index 0000000..8b7f817
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+COMMAND="${1:?}"
+
+case "$COMMAND" in
+    add)
+        if [ "$#" -ge 5 ]; then
+            # An explicit initrd path was passed so no need to regenerate the default initrd.
+            exit 0
+        fi
+
+        # Running kernel-install on Debian/Ubuntu doesn't regenerate the initramfs. Instead, we can trigger
+        # regeneration of the initramfs via "dpkg-reconfigure dracut".
+        dpkg-reconfigure dracut
+        ;;
+    *)
+        exit 0
+        ;;
+esac