Harald Hoyer ffd5ff
From b39b8452d23d098aa4f6898a2bdb8391aa45836e Mon Sep 17 00:00:00 2001
Harald Hoyer ffd5ff
From: Javier Martinez Canillas <javierm@redhat.com>
Harald Hoyer ffd5ff
Date: Wed, 28 Feb 2018 09:39:12 +0100
Harald Hoyer ffd5ff
Subject: [PATCH] 5?-dracut*.install: Allow scripts to install the initramfs in
Harald Hoyer ffd5ff
 /boot dir
Harald Hoyer ffd5ff
Harald Hoyer ffd5ff
The GRUB 2 bootloaders expect the initrd to be installed in /boot instead
Harald Hoyer ffd5ff
of /boot/$MACHINE_ID/$KERNEL_VERSION/{linux,initrd}, so if that directory
Harald Hoyer ffd5ff
doesn't exists, install the initramfs images on the /boot directory.
Harald Hoyer ffd5ff
Harald Hoyer ffd5ff
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Harald Hoyer ffd5ff
---
Harald Hoyer ffd5ff
 50-dracut.install        | 17 ++++++++++-----
Harald Hoyer ffd5ff
 51-dracut-rescue.install | 55 ++++++++++++++++++++++++++++++++++--------------
Harald Hoyer ffd5ff
 2 files changed, 51 insertions(+), 21 deletions(-)
Harald Hoyer ffd5ff
Harald Hoyer ffd5ff
diff --git a/50-dracut.install b/50-dracut.install
Harald Hoyer ffd5ff
index f1314d02..64e3549f 100755
Harald Hoyer ffd5ff
--- a/50-dracut.install
Harald Hoyer ffd5ff
+++ b/50-dracut.install
Harald Hoyer ffd5ff
@@ -11,6 +11,13 @@ if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
Harald Hoyer ffd5ff
     exit 0
Harald Hoyer ffd5ff
 fi
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
+if [[ -d "$BOOT_DIR_ABS" ]]; then
Harald Hoyer ffd5ff
+    INITRD="initrd"
Harald Hoyer ffd5ff
+else
Harald Hoyer ffd5ff
+    BOOT_DIR_ABS="/boot"
Harald Hoyer ffd5ff
+    INITRD="initramfs-${KERNEL_VERSION}.img"
Harald Hoyer ffd5ff
+fi
Harald Hoyer ffd5ff
+
Harald Hoyer ffd5ff
 ret=0
Harald Hoyer ffd5ff
 case "$COMMAND" in
Harald Hoyer ffd5ff
     add)
Harald Hoyer ffd5ff
@@ -18,9 +25,9 @@ case "$COMMAND" in
Harald Hoyer ffd5ff
         if [[ -f ${INITRD_IMAGE_PREGENERATED} ]]; then
Harald Hoyer ffd5ff
             # we found an initrd at the same place as the kernel
Harald Hoyer ffd5ff
             # use this and don't generate a new one
Harald Hoyer ffd5ff
-            cp --reflink=auto "$INITRD_IMAGE_PREGENERATED" "$BOOT_DIR_ABS/initrd" \
Harald Hoyer ffd5ff
-                && chown root:root "$BOOT_DIR_ABS/initrd" \
Harald Hoyer ffd5ff
-                && chmod 0600 "$BOOT_DIR_ABS/initrd" \
Harald Hoyer ffd5ff
+            cp --reflink=auto "$INITRD_IMAGE_PREGENERATED" "$BOOT_DIR_ABS/$INITRD" \
Harald Hoyer ffd5ff
+                && chown root:root "$BOOT_DIR_ABS/$INITRD" \
Harald Hoyer ffd5ff
+                && chmod 0600 "$BOOT_DIR_ABS/$INITRD" \
Harald Hoyer ffd5ff
                 && exit 0
Harald Hoyer ffd5ff
         fi
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
@@ -42,11 +49,11 @@ case "$COMMAND" in
Harald Hoyer ffd5ff
                 break
Harald Hoyer ffd5ff
             fi
Harald Hoyer ffd5ff
         done
Harald Hoyer ffd5ff
-	dracut ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS"/initrd "$KERNEL_VERSION"
Harald Hoyer ffd5ff
+	dracut ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
Harald Hoyer ffd5ff
         ret=$?
Harald Hoyer ffd5ff
 	;;
Harald Hoyer ffd5ff
     remove)
Harald Hoyer ffd5ff
-        rm -f -- "$BOOT_DIR_ABS"/initrd
Harald Hoyer ffd5ff
+        rm -f -- "$BOOT_DIR_ABS/$INITRD"
Harald Hoyer ffd5ff
         ret=$?
Harald Hoyer ffd5ff
 	;;
Harald Hoyer ffd5ff
 esac
Harald Hoyer ffd5ff
diff --git a/51-dracut-rescue.install b/51-dracut-rescue.install
Harald Hoyer ffd5ff
index 7fbeac1d..3f07a698 100755
Harald Hoyer ffd5ff
--- a/51-dracut-rescue.install
Harald Hoyer ffd5ff
+++ b/51-dracut-rescue.install
Harald Hoyer ffd5ff
@@ -63,15 +63,30 @@ if ! [[ ${BOOT_OPTIONS[*]} ]]; then
Harald Hoyer ffd5ff
     exit 1
Harald Hoyer ffd5ff
 fi
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
-BOOT_DIR="/${MACHINE_ID}/0-rescue"
Harald Hoyer ffd5ff
-BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
Harald Hoyer ffd5ff
-LOADER_ENTRY="$BOOT_ROOT/loader/entries/${MACHINE_ID}-0-rescue.conf"
Harald Hoyer ffd5ff
+if [[ -d "$BOOT_DIR_ABS" ]]; then
Harald Hoyer ffd5ff
+    BOOT_DIR="/${MACHINE_ID}/0-rescue"
Harald Hoyer ffd5ff
+    BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
Harald Hoyer ffd5ff
+    LOADER_ENTRY="$BOOT_ROOT/loader/entries/${MACHINE_ID}-0-rescue.conf"
Harald Hoyer ffd5ff
+    KERNEL="linux"
Harald Hoyer ffd5ff
+    INITRD="initrd"
Harald Hoyer ffd5ff
+else
Harald Hoyer ffd5ff
+    BLS_DIR="/boot/loader/entries"
Harald Hoyer ffd5ff
+    if [ -d /sys/firmware/efi ]; then
Harald Hoyer ffd5ff
+	BLS_DIR="/boot/efi/EFI/${ID}/loader/entries"
Harald Hoyer ffd5ff
+    fi
Harald Hoyer ffd5ff
+
Harald Hoyer ffd5ff
+    BOOT_DIR_ABS="/boot"
Harald Hoyer ffd5ff
+    LOADER_ENTRY="$BLS_DIR/${MACHINE_ID}-0-rescue.conf"
Harald Hoyer ffd5ff
+    KERNEL="vmlinuz-0-rescue-${MACHINE_ID}"
Harald Hoyer ffd5ff
+    INITRD="initramfs-0-rescue-${MACHINE_ID}.img"
Harald Hoyer ffd5ff
+fi
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
 ret=0
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
 case "$COMMAND" in
Harald Hoyer ffd5ff
     add)
Harald Hoyer ffd5ff
-        [[ -f "$LOADER_ENTRY" ]] && exit 0
Harald Hoyer ffd5ff
+        [[ -f "$LOADER_ENTRY" ]] && [[ -f "$BOOT_DIR_ABS/$KERNEL" ]] \
Harald Hoyer ffd5ff
+            && [[ -f "$BOOT_DIR_ABS/$INITRD" ]] && exit 0
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
         # source our config dir
Harald Hoyer ffd5ff
         for f in $(dropindirs_sort ".conf" "/etc/dracut.conf.d" "/usr/lib/dracut/dracut.conf.d"); do
Harald Hoyer ffd5ff
@@ -82,21 +97,29 @@ case "$COMMAND" in
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
         [[ -d "$BOOT_DIR_ABS" ]] || mkdir -p "$BOOT_DIR_ABS"
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
-        if ! cp --reflink=auto "$KERNEL_IMAGE" "$BOOT_DIR_ABS"/linux; then
Harald Hoyer ffd5ff
-            echo "Can't copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'!" >&2
Harald Hoyer ffd5ff
+        if ! cp --reflink=auto "$KERNEL_IMAGE" "$BOOT_DIR_ABS/$KERNEL"; then
Harald Hoyer ffd5ff
+            echo "Can't copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/$KERNEL'!" >&2
Harald Hoyer ffd5ff
         fi
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
-        dracut --no-hostonly -a "rescue" "$BOOT_DIR_ABS"/initrd "$KERNEL_VERSION"
Harald Hoyer ffd5ff
-        ((ret+=$?))
Harald Hoyer ffd5ff
+        if [[ ! -f "$BOOT_DIR_ABS/$INITRD" ]]; then
Harald Hoyer ffd5ff
+            dracut --no-hostonly -a "rescue" "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
Harald Hoyer ffd5ff
+            ((ret+=$?))
Harald Hoyer ffd5ff
+        fi
Harald Hoyer ffd5ff
+
Harald Hoyer ffd5ff
+        if [[ -d "$BOOT_DIR" ]]; then
Harald Hoyer ffd5ff
+            {
Harald Hoyer ffd5ff
+                echo "title      $PRETTY_NAME - Rescue Image"
Harald Hoyer ffd5ff
+                echo "version    $KERNEL_VERSION"
Harald Hoyer ffd5ff
+                echo "machine-id $MACHINE_ID"
Harald Hoyer ffd5ff
+                echo "options    ${BOOT_OPTIONS[@]} rd.auto=1"
Harald Hoyer ffd5ff
+                echo "linux      $BOOT_DIR/linux"
Harald Hoyer ffd5ff
+                echo "initrd     $BOOT_DIR/initrd"
Harald Hoyer ffd5ff
+            } > $LOADER_ENTRY
Harald Hoyer ffd5ff
+        else
Harald Hoyer ffd5ff
+            cp -aT "${KERNEL_IMAGE%/*}/bls.conf" $LOADER_ENTRY
Harald Hoyer ffd5ff
+            sed -i 's/'$KERNEL_VERSION'/0-rescue-'${MACHINE_ID}'/' $LOADER_ENTRY
Harald Hoyer ffd5ff
+        fi
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff
-        {
Harald Hoyer ffd5ff
-            echo "title      $PRETTY_NAME - Rescue Image"
Harald Hoyer ffd5ff
-            echo "version    $KERNEL_VERSION"
Harald Hoyer ffd5ff
-            echo "machine-id $MACHINE_ID"
Harald Hoyer ffd5ff
-            echo "options    ${BOOT_OPTIONS[@]} rd.auto=1"
Harald Hoyer ffd5ff
-            echo "linux      $BOOT_DIR/linux"
Harald Hoyer ffd5ff
-            echo "initrd     $BOOT_DIR/initrd"
Harald Hoyer ffd5ff
-        } > $LOADER_ENTRY
Harald Hoyer ffd5ff
         ((ret+=$?))
Harald Hoyer ffd5ff
         ;;
Harald Hoyer ffd5ff
 
Harald Hoyer ffd5ff