]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install: only generate systemd.boot_id= in kernel command line if used for...
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Feb 2022 13:44:48 +0000 (14:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 11 Mar 2022 10:34:34 +0000 (11:34 +0100)
Now that we can distinguish the naming of the boot loader spec
dirs/files and the machine ID let's tweak the logic for suffixing the
kernel cmdline with systemd.boot_id=: let's only do that when we
actually need the boot ID for naming these dirs/files. If we don't,
let's not bother.

This should be beneficial for "golden" images that shall not carry any
machine IDs at all, i.e acquire their identity only once the final
userspace is actually reached.

src/kernel-install/90-loaderentry.install

index 46261a2c11ba35e66af505f11e0cafbf744a9ad7..c1d69aa82468531e4c5ec72e4fbfd4b9429992b0 100644 (file)
@@ -70,10 +70,15 @@ else
     BOOT_OPTIONS="$(tr -s "$IFS" '\n' </proc/cmdline | grep -ve '^BOOT_IMAGE=' -e '^initrd=' | tr '\n' ' ')"
 fi
 
-# Suffix with the machine ID we use, so that the machine ID remains stable,
-# even during factory reset, in the initrd (where the system's machine ID is
-# not directly accessible yet), and if the root file system is volatile.
-BOOT_OPTIONS="${BOOT_OPTIONS% } systemd.machine_id=$MACHINE_ID"
+BOOT_OPTIONS="${BOOT_OPTIONS% }"
+
+# If the boot entries are named after the machine ID, then suffix the kernel
+# command line with the machine ID we use, so that the machine ID remains
+# stable, even during factory reset, in the initrd (where the system's machine
+# ID is not directly accessible yet), and if the root file system is volatile.
+if [ "$ENTRY_TOKEN" = "$MACHINE_ID" ]; then
+    BOOT_OPTIONS="$BOOT_OPTIONS systemd.machine_id=$MACHINE_ID"
+fi
 
 if [ -r /etc/kernel/tries ]; then
     read -r TRIES </etc/kernel/tries
@@ -121,7 +126,10 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
 {
     echo "title      $PRETTY_NAME"
     echo "version    $KERNEL_VERSION"
-    echo "machine-id $MACHINE_ID"
+    if [ "$ENTRY_TOKEN" = "$MACHINE_ID" ]; then
+        # See similar logic above for the systemd.machine_id= kernel command line option
+        echo "machine-id $MACHINE_ID"
+    fi
     echo "options    $BOOT_OPTIONS"
     echo "linux      $ENTRY_DIR/linux"