|
|
8d419f |
From 7738d7793bc83421536f9962c794633006613725 Mon Sep 17 00:00:00 2001
|
|
|
8d419f |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
8d419f |
Date: Wed, 9 Feb 2022 13:59:36 +0100
|
|
|
8d419f |
Subject: [PATCH] kernel-install: don't try to persist used machine ID locally
|
|
|
8d419f |
|
|
|
8d419f |
This reworks the how machine ID used by the boot loader spec snippet
|
|
|
8d419f |
generation logic. Instead of persisting it automatically to /etc/ we'll
|
|
|
8d419f |
append it via systemd.machined_id= to the kernel command line, and thus
|
|
|
8d419f |
persist it in the generated boot loader spec snippets instead. This has
|
|
|
8d419f |
nice benefits:
|
|
|
8d419f |
|
|
|
8d419f |
1. We do not collide with read-only root
|
|
|
8d419f |
2. The machine ID remains stable across factory reset, so that we can
|
|
|
8d419f |
safely recognize the path in $BOOT we drop our kernel images in
|
|
|
8d419f |
again, i.e. kernel updates will work correctly and safely across
|
|
|
8d419f |
kernel factory resets.
|
|
|
8d419f |
3. Previously regular systems had different machine IDs while in
|
|
|
8d419f |
initrd and after booting into the host system. With this change
|
|
|
8d419f |
they will now have the same.
|
|
|
8d419f |
|
|
|
8d419f |
This then drops implicit persisting of KERNEL_INSTALL_MACHINE_ID, as its
|
|
|
8d419f |
unnecessary then. The field is still honoured though, for compat
|
|
|
8d419f |
reasons.
|
|
|
8d419f |
|
|
|
8d419f |
This also drops the "Default" fallback previously used, as it actually
|
|
|
8d419f |
is without effect, the randomized ID generation already took precedence
|
|
|
8d419f |
in all cases. This means $MACHNE_ID/KERNEL_INSTALL_MACHINE_ID are now
|
|
|
8d419f |
guaranteed to look like a proper machine ID, which is useful for us,
|
|
|
8d419f |
given you need it that way to be able to pass it to the
|
|
|
8d419f |
systemd.machine_id= kernel command line option.
|
|
|
8d419f |
|
|
|
8d419f |
(cherry picked from commit 11ce3ea2f2219ab9c0700bcf7f8ed4312d80e937)
|
|
|
8d419f |
|
|
|
8d419f |
Related: #2065061
|
|
|
8d419f |
---
|
|
|
8d419f |
src/kernel-install/90-loaderentry.install | 6 +++++-
|
|
|
8d419f |
src/kernel-install/kernel-install | 16 +++++++---------
|
|
|
8d419f |
2 files changed, 12 insertions(+), 10 deletions(-)
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install
|
|
|
8d419f |
index 3edefdefb4..046771169c 100644
|
|
|
8d419f |
--- a/src/kernel-install/90-loaderentry.install
|
|
|
8d419f |
+++ b/src/kernel-install/90-loaderentry.install
|
|
|
8d419f |
@@ -68,7 +68,11 @@ elif [ -r /usr/lib/kernel/cmdline ]; then
|
|
|
8d419f |
else
|
|
|
8d419f |
BOOT_OPTIONS="$(tr -s "$IFS" '\n'
|
|
|
8d419f |
fi
|
|
|
8d419f |
-BOOT_OPTIONS="${BOOT_OPTIONS% }"
|
|
|
8d419f |
+
|
|
|
8d419f |
+# Suffix with the machine ID we use, so that the machine ID remains stable,
|
|
|
8d419f |
+# even during factory reset, in the initrd (where the system's machine ID is
|
|
|
8d419f |
+# not directly accessible yet), and if the root file system is volatile.
|
|
|
8d419f |
+BOOT_OPTIONS="${BOOT_OPTIONS% } systemd.machine_id=$MACHINE_ID"
|
|
|
8d419f |
|
|
|
8d419f |
if [ -r /etc/kernel/tries ]; then
|
|
|
8d419f |
read -r TRIES
|
|
|
8d419f |
diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install
|
|
|
8d419f |
index 8cfef3208d..e94aa79bc6 100755
|
|
|
8d419f |
--- a/src/kernel-install/kernel-install
|
|
|
8d419f |
+++ b/src/kernel-install/kernel-install
|
|
|
8d419f |
@@ -89,15 +89,13 @@ elif [ -r "/usr/lib/kernel/install.conf" ]; then
|
|
|
8d419f |
. /usr/lib/kernel/install.conf
|
|
|
8d419f |
fi
|
|
|
8d419f |
|
|
|
8d419f |
-# Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
|
|
|
8d419f |
-# ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
|
|
|
8d419f |
-# a new machine ID in /etc/machine-info. If that fails, use "Default".
|
|
|
8d419f |
-[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
|
|
|
8d419f |
-[ -z "$MACHINE_ID" ] && [ -r /etc/machine-id ] && read -r MACHINE_ID
|
|
|
8d419f |
-[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc/machine-info
|
|
|
8d419f |
-[ -z "$MACHINE_ID" ] && NEW_MACHINE_ID="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc/machine-info
|
|
|
8d419f |
-[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
|
|
|
8d419f |
-[ -z "$MACHINE_ID" ] && MACHINE_ID="Default"
|
|
|
8d419f |
+# If /etc/machine-id is initialized we'll use it, otherwise we'll use a freshly
|
|
|
8d419f |
+# generated one. If the user configured an explicit machine ID to use in
|
|
|
8d419f |
+# /etc/machine-info to use for our purpose, we'll use that instead (for
|
|
|
8d419f |
+# compatibility).
|
|
|
8d419f |
+[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
|
|
|
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 |
for pref in "/efi" "/boot" "/boot/efi" ; do
|