richardphibel / rpms / systemd

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