Blame 0175-dracut.sh-add-default-path-for-uefi.patch

Harald Hoyer 53404a
From 13e8bf850ce5e64b2a6b0c9baa336ce525c45848 Mon Sep 17 00:00:00 2001
Harald Hoyer 53404a
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 53404a
Date: Thu, 8 Dec 2016 17:53:40 +0100
Harald Hoyer 53404a
Subject: [PATCH] dracut.sh: add default path for --uefi
Harald Hoyer 53404a
Harald Hoyer 53404a
The default output filename for --uefi is
Harald Hoyer 53404a
<EFI>/EFI/Linux/linux-$kernel$-<MACHINE_ID>-<BUILD_ID>.efi.
Harald Hoyer 53404a
<EFI> might be /efi, /boot or /boot/efi depending on where the ESP partition
Harald Hoyer 53404a
is mounted. The <BUILD_ID> is taken from BUILD_ID in /usr/lib/os-release or
Harald Hoyer 53404a
if it exists /etc/os-release and is left out, if BUILD_ID is non-existant or
Harald Hoyer 53404a
empty.
Harald Hoyer 53404a
Harald Hoyer 53404a
Also a new option --no-machineid was added, which affects the default output
Harald Hoyer 53404a
filename of --uefi and will discard the <MACHINE_ID> part.
Harald Hoyer 53404a
---
Harald Hoyer 53404a
 dracut.8.asc | 10 +++++++++-
Harald Hoyer 53404a
 dracut.sh    | 43 +++++++++++++++++++++++++++++++++----------
Harald Hoyer 53404a
 2 files changed, 42 insertions(+), 11 deletions(-)
Harald Hoyer 53404a
Harald Hoyer 53404a
diff --git a/dracut.8.asc b/dracut.8.asc
Harald Hoyer 53404a
index 0e01707..4ab0872 100644
Harald Hoyer 53404a
--- a/dracut.8.asc
Harald Hoyer 53404a
+++ b/dracut.8.asc
Harald Hoyer 53404a
@@ -485,7 +485,15 @@ will not be able to boot.
Harald Hoyer 53404a
 
Harald Hoyer 53404a
 **--uefi**::
Harald Hoyer 53404a
     Instead of creating an initramfs image, dracut will create an UEFI executable,
Harald Hoyer 53404a
-    which can be executed by an UEFI BIOS.
Harald Hoyer 53404a
+    which can be executed by an UEFI BIOS. The default output filename is
Harald Hoyer 53404a
+    _<EFI>/EFI/Linux/linux-$kernel$-<MACHINE_ID>-<BUILD_ID>.efi_. <EFI> might be
Harald Hoyer 53404a
+    _/efi_, _/boot_ or _/boot/efi_ depending on where the ESP partition is mounted.
Harald Hoyer 53404a
+    The <BUILD_ID> is taken from BUILD_ID in _/usr/lib/os-release_ or if it exists
Harald Hoyer 53404a
+    _/etc/os-release_ and is left out, if BUILD_ID is non-existant or empty.
Harald Hoyer 53404a
+
Harald Hoyer 53404a
+**--no-machineid**::
Harald Hoyer 53404a
+    affects the default output filename of **--uefi** and will discard the <MACHINE_ID>
Harald Hoyer 53404a
+    part.
Harald Hoyer 53404a
 
Harald Hoyer 53404a
 **--uefi-stub _<FILE>_**::
Harald Hoyer 53404a
     Specifies the UEFI stub loader, which will load the attached kernel, initramfs and
Harald Hoyer 53404a
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 53404a
index 2d79bbc..0886343 100755
Harald Hoyer 53404a
--- a/dracut.sh
Harald Hoyer 53404a
+++ b/dracut.sh
Harald Hoyer 53404a
@@ -371,6 +371,7 @@ rearrange_params()
Harald Hoyer 53404a
         --long kernel-image: \
Harald Hoyer 53404a
         --long no-hostonly-i18n \
Harald Hoyer 53404a
         --long hostonly-i18n \
Harald Hoyer 53404a
+        --long no-machineid \
Harald Hoyer 53404a
         -- "$@")
Harald Hoyer 53404a
 
Harald Hoyer 53404a
     if (( $? != 0 )); then
Harald Hoyer 53404a
@@ -566,6 +567,8 @@ while :; do
Harald Hoyer 53404a
                        uefi_stub_l="$2";               PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 53404a
         --kernel-image)
Harald Hoyer 53404a
                        kernel_image_l="$2";            PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 53404a
+        --no-machineid)
Harald Hoyer 53404a
+                       machine_id_l="no";;
Harald Hoyer 53404a
         --) shift; break;;
Harald Hoyer 53404a
 
Harald Hoyer 53404a
         *)  # should not even reach this point
Harald Hoyer 53404a
@@ -624,16 +627,6 @@ if [[ $kernel ]]; then
Harald Hoyer 53404a
     fi
Harald Hoyer 53404a
 fi
Harald Hoyer 53404a
 
Harald Hoyer 53404a
-if ! [[ $outfile ]]; then
Harald Hoyer 53404a
-    [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
Harald Hoyer 53404a
-
Harald Hoyer 53404a
-    if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
Harald Hoyer 53404a
-        outfile="/boot/${MACHINE_ID}/$kernel/initrd"
Harald Hoyer 53404a
-    else
Harald Hoyer 53404a
-        outfile="/boot/initramfs-$kernel.img"
Harald Hoyer 53404a
-    fi
Harald Hoyer 53404a
-fi
Harald Hoyer 53404a
-
Harald Hoyer 53404a
 unset LC_MESSAGES
Harald Hoyer 53404a
 unset LC_CTYPE
Harald Hoyer 53404a
 export LC_ALL=C
Harald Hoyer 53404a
@@ -751,6 +744,36 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
Harald Hoyer 53404a
 [[ $loginstall_l ]] && loginstall="$loginstall_l"
Harald Hoyer 53404a
 [[ $uefi_stub_l ]] && uefi_stub="$uefi_stub_l"
Harald Hoyer 53404a
 [[ $kernel_image_l ]] && kernel_image="$kernel_image_l"
Harald Hoyer 53404a
+[[ $machine_id_l ]] && machine_id="$machine_id_l"
Harald Hoyer 53404a
+
Harald Hoyer 53404a
+if ! [[ $outfile ]]; then
Harald Hoyer 53404a
+    if [[ $machine_id != "no" ]]; then
Harald Hoyer 53404a
+        [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
Harald Hoyer 53404a
+    fi
Harald Hoyer 53404a
+
Harald Hoyer 53404a
+    if [[ $uefi == "yes" ]]; then
Harald Hoyer 53404a
+        BUILD_ID=$(cat /etc/os-release /usr/lib/os-release \
Harald Hoyer 53404a
+                       | while read -r line || [[ $line ]]; do \
Harald Hoyer 53404a
+                       [[ $line =~ BUILD_ID\=* ]] && eval "$line" && echo "$BUILD_ID" && break; \
Harald Hoyer 53404a
+                   done)
Harald Hoyer 53404a
+        if [[ -d /efi ]] && mountpoint -q /efi; then
Harald Hoyer 53404a
+            efidir=/efi
Harald Hoyer 53404a
+        else
Harald Hoyer 53404a
+            efidir=/boot/EFI
Harald Hoyer 53404a
+            if [[ -d /boot/efi/EFI ]] && mountpoint -q /boot/efi; then
Harald Hoyer 53404a
+                efidir=/boot/efi/EFI
Harald Hoyer 53404a
+            fi
Harald Hoyer 53404a
+        fi
Harald Hoyer 53404a
+        mkdir -p "$efidir/Linux"
Harald Hoyer 53404a
+        outfile="$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
Harald Hoyer 53404a
+    else
Harald Hoyer 53404a
+        if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
Harald Hoyer 53404a
+            outfile="/boot/${MACHINE_ID}/$kernel/initrd"
Harald Hoyer 53404a
+        else
Harald Hoyer 53404a
+            outfile="/boot/initramfs-$kernel.img"
Harald Hoyer 53404a
+        fi
Harald Hoyer 53404a
+    fi
Harald Hoyer 53404a
+fi
Harald Hoyer 53404a
 
Harald Hoyer 53404a
 # eliminate IFS hackery when messing with fw_dir
Harald Hoyer 53404a
 export DRACUT_FIRMWARE_PATH=${fw_dir// /:}