ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
8d419f
From a774b3d6c43863b632f211aa21e61cb48e2ee736 Mon Sep 17 00:00:00 2001
8d419f
From: Lennart Poettering <lennart@poettering.net>
8d419f
Date: Thu, 10 Feb 2022 14:27:22 +0100
8d419f
Subject: [PATCH] kernel-install: search harder for kernel image/initrd drop-in
8d419f
 dir
8d419f
8d419f
If not explicitly configured, let's search a bit harder for the
8d419f
ENTRY_TOKEN, and let's try the machine ID, the IMAGE_ID and ID fields of
8d419f
/etc/os-release and finally "Default", all below potential $XBOOTLDR.
8d419f
8d419f
(cherry picked from commit 6637cf9db67237857279262d93ee0e39023c5b85)
8d419f
8d419f
Related: #2065061
8d419f
---
8d419f
 src/kernel-install/kernel-install | 27 ++++++++++++++++++++++++---
8d419f
 1 file changed, 24 insertions(+), 3 deletions(-)
8d419f
8d419f
diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install
8d419f
index 75a31c62d4..c42c40592a 100755
8d419f
--- a/src/kernel-install/kernel-install
8d419f
+++ b/src/kernel-install/kernel-install
8d419f
@@ -103,29 +103,50 @@ fi
8d419f
 # for naming the .conf boot loader spec entry. Typically this is just the
8d419f
 # machine ID, but it can be anything else, too, if we are told so.
8d419f
 [ -z "$ENTRY_TOKEN" ] && [ -r /etc/kernel/entry-token ] && read -r ENTRY_TOKEN 
8d419f
-[ -z "$ENTRY_TOKEN" ] && ENTRY_TOKEN="$MACHINE_ID"
8d419f
+if [ -z "$ENTRY_TOKEN" ]; then
8d419f
+    # If not configured explicitly, then use a few candidates: the machine ID,
8d419f
+    # the IMAGE_ID= and ID= fields from /etc/os-release and finally the fixed
8d419f
+    # string "Default"
8d419f
+    ENTRY_TOKEN_SEARCH="$MACHINE_ID"
8d419f
+    [ -r /etc/os-release ] && . /etc/os-release
8d419f
+    [ -n "$IMAGE_ID" ] && ENTRY_TOKEN_SEARCH="$ENTRY_TOKEN_SEARCH $IMAGE_ID"
8d419f
+    [ -n "$ID" ] && ENTRY_TOKEN_SEARCH="$ENTRY_TOKEN_SEARCH $ID"
8d419f
+    ENTRY_TOKEN_SEARCH="$ENTRY_TOKEN_SEARCH Default"
8d419f
+else
8d419f
+    ENTRY_TOKEN_SEARCH="$ENTRY_TOKEN"
8d419f
+fi
8d419f
 
8d419f
 # NB: The $MACHINE_ID is guaranteed to be a valid machine ID, but
8d419f
 #     $ENTRY_TOKEN can be any string that fits into a VFAT filename, though
8d419f
 #     typically is just the machine ID.
8d419f
 
8d419f
-[ -z "$BOOT_ROOT" ] && for suff in "$ENTRY_TOKEN" "loader/entries"; do
8d419f
-    for pref in "/efi" "/boot" "/boot/efi" ; do
8d419f
+[ -z "$BOOT_ROOT" ] && for suff in $ENTRY_TOKEN_SEARCH; do
8d419f
+    for pref in "/efi" "/boot" "/boot/efi"; do
8d419f
         if [ -d "$pref/$suff" ]; then
8d419f
             BOOT_ROOT="$pref"
8d419f
+            ENTRY_TOKEN="$suff"
8d419f
             break 2
8d419f
         fi
8d419f
     done
8d419f
 done
8d419f
 
8d419f
+[ -z "$BOOT_ROOT" ] && for pref in "/efi" "/boot" "/boot/efi"; do
8d419f
+    if [ -d "$pref/loader/entries" ]; then
8d419f
+        BOOT_ROOT="$pref"
8d419f
+        break
8d419f
+    fi
8d419f
+done
8d419f
+
8d419f
 [ -z "$BOOT_ROOT" ] && for pref in "/efi" "/boot/efi"; do
8d419f
     if mountpoint -q "$pref"; then
8d419f
         BOOT_ROOT="$pref"
8d419f
         break
8d419f
     fi
8d419f
 done
8d419f
+
8d419f
 [ -z "$BOOT_ROOT" ] && BOOT_ROOT="/boot"
8d419f
 
8d419f
+[ -z "$ENTRY_TOKEN" ] && ENTRY_TOKEN="$MACHINE_ID"
8d419f
 
8d419f
 if [ -z "$layout" ]; then
8d419f
     # Administrative decision: if not present, some scripts generate into /boot.