ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
8d419f
From 455b9b9dd4d462db7482f67d8e730b25e75b1505 Mon Sep 17 00:00:00 2001
8d419f
From: Lennart Poettering <lennart@poettering.net>
8d419f
Date: Wed, 9 Feb 2022 14:29:19 +0100
8d419f
Subject: [PATCH] kernel-install: add a new $ENTRY_TOKEN variable for naming
8d419f
 boot entries
8d419f
MIME-Version: 1.0
8d419f
Content-Type: text/plain; charset=UTF-8
8d419f
Content-Transfer-Encoding: 8bit
8d419f
8d419f
This cleans up naming of boot loader spec boot entries a bit (i.e. the
8d419f
naming of the .conf snippet files, and the directory in $BOOT where the
8d419f
kernel images and initrds are placed), and isolates it from the actual machine
8d419f
ID concept.
8d419f
8d419f
Previously there was a sinlge concept for both things, because typically
8d419f
the entries are just named after the machine ID. However one could also
8d419f
use a different identifier, i.e. not a 128bit ID in which cases issues
8d419f
pop up everywhere. For example, the "machine-id" field in the generated
8d419f
snippets would not be a machine ID anymore, and the newly added
8d419f
systemd.machine_id= kernel parameter would possibly get passed invalid
8d419f
data.
8d419f
8d419f
Hence clean this up:
8d419f
8d419f
$MACHINE_ID → always a valid 128bit ID.
8d419f
8d419f
$ENTRY_TOKEN → usually the $MACHINE_ID but can be any other string too.
8d419f
This is used to name the directory to put kernels/initrds in. It's also
8d419f
used for naming the *.conf snippets that implement the Boot Loader Type
8d419f
1 spec.
8d419f
8d419f
(cherry picked from commit 3907044ffa568aedf076d0f9807489ec78f87502)
8d419f
8d419f
Related: #2065061
8d419f
---
8d419f
 src/kernel-install/90-loaderentry.install | 11 ++++++-----
8d419f
 src/kernel-install/kernel-install         | 21 +++++++++++++++++----
8d419f
 2 files changed, 23 insertions(+), 9 deletions(-)
8d419f
8d419f
diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install
8d419f
index 046771169c..46261a2c11 100644
8d419f
--- a/src/kernel-install/90-loaderentry.install
8d419f
+++ b/src/kernel-install/90-loaderentry.install
8d419f
@@ -29,6 +29,7 @@ INITRD_OPTIONS_SHIFT=4
8d419f
 [ "$KERNEL_INSTALL_LAYOUT" = "bls" ] || exit 0
8d419f
 
8d419f
 MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
8d419f
+ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN"
8d419f
 BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
8d419f
 
8d419f
 BOOT_MNT="$(stat -c %m "$BOOT_ROOT")"
8d419f
@@ -41,10 +42,10 @@ fi
8d419f
 case "$COMMAND" in
8d419f
     remove)
8d419f
         [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
8d419f
-            echo "Removing $BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION*.conf"
8d419f
+            echo "Removing $BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION*.conf"
8d419f
         exec rm -f \
8d419f
-            "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf" \
8d419f
-            "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
8d419f
+            "$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION.conf" \
8d419f
+            "$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION+"*".conf"
8d419f
         ;;
8d419f
     add)
8d419f
         ;;
8d419f
@@ -80,9 +81,9 @@ if [ -r /etc/kernel/tries ]; then
8d419f
         echo "/etc/kernel/tries does not contain an integer." >&2
8d419f
         exit 1
8d419f
     fi
8d419f
-    LOADER_ENTRY="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
8d419f
+    LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.conf"
8d419f
 else
8d419f
-    LOADER_ENTRY="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
8d419f
+    LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION.conf"
8d419f
 fi
8d419f
 
8d419f
 if ! [ -d "$ENTRY_DIR_ABS" ]; then
8d419f
diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install
8d419f
index e94aa79bc6..75a31c62d4 100755
8d419f
--- a/src/kernel-install/kernel-install
8d419f
+++ b/src/kernel-install/kernel-install
8d419f
@@ -97,7 +97,19 @@ fi
8d419f
 [ -z "$MACHINE_ID" ] && [ -r /etc/machine-id ]   && read -r MACHINE_ID 
8d419f
 [ -z "$MACHINE_ID" ] && MACHINE_ID="$(systemd-id128 new)"
8d419f
 
8d419f
-[ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "loader/entries"; do
8d419f
+# Now that we determined the machine ID to use, let's determine the "token" for
8d419f
+# the boot loader entry to generate. We use that for naming the directory below
8d419f
+# $BOOT where we want to place the kernel/initrd and related resources, as well
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
+
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
         if [ -d "$pref/$suff" ]; then
8d419f
             BOOT_ROOT="$pref"
8d419f
@@ -117,14 +129,14 @@ done
8d419f
 
8d419f
 if [ -z "$layout" ]; then
8d419f
     # Administrative decision: if not present, some scripts generate into /boot.
8d419f
-    if [ -d "$BOOT_ROOT/$MACHINE_ID" ]; then
8d419f
+    if [ -d "$BOOT_ROOT/$ENTRY_TOKEN" ]; then
8d419f
         layout="bls"
8d419f
     else
8d419f
         layout="other"
8d419f
     fi
8d419f
 fi
8d419f
 
8d419f
-ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
8d419f
+ENTRY_DIR_ABS="$BOOT_ROOT/$ENTRY_TOKEN/$KERNEL_VERSION"
8d419f
 
8d419f
 # Provide a directory where to store generated initrds
8d419f
 cleanup() {
8d419f
@@ -136,6 +148,7 @@ trap cleanup EXIT
8d419f
 KERNEL_INSTALL_STAGING_AREA="$(mktemp -d -t -p /tmp kernel-install.staging.XXXXXXX)"
8d419f
 
8d419f
 export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
8d419f
+export KERNEL_INSTALL_ENTRY_TOKEN="$ENTRY_TOKEN"
8d419f
 export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
8d419f
 export KERNEL_INSTALL_LAYOUT="$layout"
8d419f
 export KERNEL_INSTALL_INITRD_GENERATOR="$initrd_generator"
8d419f
@@ -168,7 +181,7 @@ case "$COMMAND" in
8d419f
         fi
8d419f
 
8d419f
         if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then
8d419f
-            # Compatibility with earlier versions that used the presence of $BOOT_ROOT/$MACHINE_ID
8d419f
+            # Compatibility with earlier versions that used the presence of $BOOT_ROOT/$ENTRY_TOKEN
8d419f
             # to signal to 00-entry-directory to create $ENTRY_DIR_ABS
8d419f
             # to serve as the indication to use or to not use the BLS
8d419f
             if [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ]; then