]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(install.d): respect more kernel-install env variables
authorAndrew Ammerlaan <andrewammerlaan@gentoo.org>
Sat, 17 Jun 2023 06:18:55 +0000 (08:18 +0200)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Mon, 26 Jun 2023 07:39:24 +0000 (09:39 +0200)
- If kernel-install has defined a staging area for us
(KERNEL_INSTALL_STAGING_AREA) install generated initrd/uki.efi there.
The actual install is then handled by 90-loaderentry.install or
90-uki-copy-install.

- Also skip regeneration if an uki.efi already exists.

- Pass --kernel-image to dracut, this is required to generate an uki (uefi=yes)

- Add --no-uefi argument to dracut rescue image generation, this ensures that
it at least installs correctly. TODO: Rework 51-dracut-rescue.install to also
work with uki's.

This fixes installing a kernel with uefi=yes in dracut config and layout=uki
in kernel/install.conf.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
install.d/50-dracut.install
install.d/51-dracut-rescue.install

index a81c41c959c3e877281aa582621f695892110d3d..eae3084974074740c3fbc3deeb1d32def47c5222 100755 (executable)
@@ -11,23 +11,40 @@ if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
     exit 0
 fi
 
-if [[ -d "$BOOT_DIR_ABS" ]]; then
-    INITRD="initrd"
+# Mismatching the install layout and the --uefi/--no-uefi opts just creates a mess.
+if [[ "$KERNEL_INSTALL_LAYOUT" == "uki" && -n "$KERNEL_INSTALL_STAGING_AREA" ]]; then
+    BOOT_DIR_ABS="$KERNEL_INSTALL_STAGING_AREA"
+    IMAGE="uki.efi"
+    UEFI_OPTS="--uefi"
+elif [[ "$KERNEL_INSTALL_LAYOUT" == "bls" && -n "$KERNEL_INSTALL_STAGING_AREA" ]]; then
+    BOOT_DIR_ABS="$KERNEL_INSTALL_STAGING_AREA"
+    IMAGE="initrd"
+    UEFI_OPTS="--no-uefi"
 else
-    BOOT_DIR_ABS="/boot"
-    INITRD="initramfs-${KERNEL_VERSION}.img"
+    # No layout information, use users --uefi/--no-uefi preference
+    UEFI_OPTS=""
+    if [[ -d "$BOOT_DIR_ABS" ]]; then
+        IMAGE="initrd"
+    else
+        BOOT_DIR_ABS="/boot"
+        IMAGE="initramfs-${KERNEL_VERSION}.img"
+    fi
 fi
 
 ret=0
 case "$COMMAND" in
     add)
-        INITRD_IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/initrd
-        if [[ -f ${INITRD_IMAGE_PREGENERATED} ]]; then
-            # we found an initrd at the same place as the kernel
+        if [[ "$IMAGE" == "uki.efi" ]]; then
+            IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/uki.efi
+        else
+            IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/initrd
+        fi
+        if [[ -f ${IMAGE_PREGENERATED} ]]; then
+            # we found an initrd or uki.efi at the same place as the kernel
             # use this and don't generate a new one
-            cp --reflink=auto "$INITRD_IMAGE_PREGENERATED" "$BOOT_DIR_ABS/$INITRD" \
-                && chown root:root "$BOOT_DIR_ABS/$INITRD" \
-                && chmod 0600 "$BOOT_DIR_ABS/$INITRD" \
+            cp --reflink=auto "$IMAGE_PREGENERATED" "$BOOT_DIR_ABS/$IMAGE" \
+                && chown root:root "$BOOT_DIR_ABS/$IMAGE" \
+                && chmod 0600 "$BOOT_DIR_ABS/$IMAGE" \
                 && exit 0
         fi
 
@@ -58,12 +75,14 @@ case "$COMMAND" in
         dracut -f \
             ${noimageifnotneeded:+--noimageifnotneeded} \
             $([[ "$KERNEL_INSTALL_VERBOSE" == 1 ]] && echo --verbose) \
-            "$BOOT_DIR_ABS/$INITRD" \
+            $([[ -n "$KERNEL_IMAGE" ]] && echo --kernel-image "${KERNEL_IMAGE}") \
+            "$UEFI_OPTS" \
+            "$BOOT_DIR_ABS/$IMAGE" \
             "$KERNEL_VERSION"
         ret=$?
        ;;
     remove)
-        rm -f -- "$BOOT_DIR_ABS/$INITRD"
+        rm -f -- "$BOOT_DIR_ABS/$IMAGE"
         ret=$?
        ;;
 esac
index 8bf9a6d9513bcd9a08a3efdd7b019d717a346eda..562ffcbd7bbb1a582984a7bb355fea1c79f3d99c 100755 (executable)
@@ -96,7 +96,9 @@ case "$COMMAND" in
         fi
 
         if [[ ! -f "$BOOT_DIR_ABS/$INITRD" ]]; then
-            dracut -f --no-hostonly -a "rescue" "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
+            dracut -f --no-hostonly --no-uefi \
+                $([[ -n "$KERNEL_IMAGE" ]] && echo --kernel-image "${KERNEL_IMAGE}") \
+                -a "rescue" "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
             ((ret+=$?))
         fi