From 447a822f8ee47b63a4cae00423c4d407bfa5e516 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 15 Dec 2021 13:58:24 +0100 Subject: [PATCH 1/2] kernel-install: Remove "Default" from list of suffixes checked This was an undocumented change in behavior introduced by 9e82a74cb0f08a288f9db228a0b5bec8a7188cdb. Previously, we only checked for "Default" if we didn't find a machine ID. Let's make sure we keep the previous behavior intact. --- src/kernel-install/kernel-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install index 9999b86ed8..f2d954f2dd 100755 --- a/src/kernel-install/kernel-install +++ b/src/kernel-install/kernel-install @@ -93,7 +93,7 @@ fi [ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && [ "$(stat -fc %T /etc/machine-id)" != "tmpfs" ] && read -r MACHINE_ID < /etc/machine-id [ -z "$MACHINE_ID" ] && MACHINE_ID="Default" -[ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "Default" "loader/entries"; do +[ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "loader/entries"; do for pref in "/efi" "/boot/efi" "/boot"; do if [ -d "$pref/$suff" ]; then BOOT_ROOT="$pref" From 357376d0bb525b064f468e0e2af8193b4b90d257 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 14 Dec 2021 17:09:08 +0100 Subject: [PATCH 2/2] kernel-install: Introduce KERNEL_INSTALL_MACHINE_ID in /etc/machine-info If KERNEL_INSTALL_MACHINE_ID is defined in /etc/machine-info, prefer it over the machine ID from /etc/machine-id. If a machine ID is defined in neither /etc/machine-info nor in /etc/machine-id, generate a new UUID and try to write it to /etc/machine-info as KERNEL_INSTALL_MACHINE_ID and use it as the machine ID if writing it to /etc/machine-info succeeds. In practice, this means we have a more robust fallback if there's no machine ID in /etc/machine-id than just using "Default" and allows image builders to force kernel-install to use KERNEL_INSTALL_MACHINE_ID by simply writing it to /etc/machine-info themselves. --- NEWS | 9 +++++++++ man/kernel-install.xml | 12 ++++++++++++ man/machine-info.xml | 10 ++++++++++ src/kernel-install/kernel-install | 10 +++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 6dcfd80610..38af20b769 100644 --- a/NEWS +++ b/NEWS @@ -6400,6 +6400,15 @@ CHANGES WITH 234: temporary directory is passed as the entry directory and removed after all the plugins exit. + * If KERNEL_INSTALL_MACHINE_ID is set in /etc/machine-info, kernel-install + will now use its value as the machine ID instead of the machine ID + from /etc/machine-id. If KERNEL_INSTALL_MACHINE_ID isn't set in + /etc/machine-info and no machine ID is set in /etc/machine-id, + kernel-install will try to store the current machine ID there as + KERNEL_INSTALL_MACHINE_ID. If there is no machine ID, kernel-install + will generate a new UUID, store it in /etc/machine-info as + KERNEL_INSTALL_MACHINE_ID and use it as the machine ID. + Contributions from: Adrian Heine né Lang, Aggelos Avgerinos, Alexander Kurtz, Alexandros Frantzis, Alexey Brodkin, Alex Lu, Amir Pakdel, Amir Yalon, Anchor Cat, Anthony Parsons, Bastien Nocera, Benjamin Gilbert, diff --git a/man/kernel-install.xml b/man/kernel-install.xml index 670beb35b8..c6414b13dd 100644 --- a/man/kernel-install.xml +++ b/man/kernel-install.xml @@ -228,6 +228,18 @@ kernel-install will use Default instead. + + + /etc/machine-info + + + If this file contains the KERNEL_INSTALL_MACHINE_ID variable, + kernel-install will use it as MACHINE-ID instead of + the contents of /etc/machine-id. If the variable is not found in + /etc/machine-info, kernel-install will try to save the + machine ID it uses to install to $BOOT to this file. + + /etc/os-release diff --git a/man/machine-info.xml b/man/machine-info.xml index 3de6810047..b4b5af26e0 100644 --- a/man/machine-info.xml +++ b/man/machine-info.xml @@ -128,6 +128,16 @@ specific as Left Rack, 2nd Shelf. + + + KERNEL_INSTALL_MACHINE_ID= + + Specifies the installation-specific installation directory + kernel-install should use. The value must be a valid machine ID (32 hexadecimal + characters). This would generally be the original machine-id that was used when the boot loader + entries for this installation were first added. When not set, the current value of + machine-id(5) will be used. + diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install index f2d954f2dd..103b44ebda 100755 --- a/src/kernel-install/kernel-install +++ b/src/kernel-install/kernel-install @@ -90,7 +90,15 @@ if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then exit 1 fi -[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && [ "$(stat -fc %T /etc/machine-id)" != "tmpfs" ] && read -r MACHINE_ID < /etc/machine-id +# Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine +# ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate +# a new machine ID in /etc/machine-info. If that fails, use "Default". + +[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID" +[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && read -r MACHINE_ID >/etc/machine-info +[ -z "$MACHINE_ID" ] && NEW_MACHINE_ID="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc/machine-info +[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID" [ -z "$MACHINE_ID" ] && MACHINE_ID="Default" [ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "loader/entries"; do