From dcd9d196a4ae52ba1bfd0e8aae2f7d8f3428db8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=BD=D0=B0=D0=B1?= Date: Tue, 16 Mar 2021 17:38:20 +0100 Subject: [PATCH] kernel-install: respect $MACHINE_ID and ignore /etc/machine-id if on tmpfs Confer https://github.com/systemd/systemd/pull/19006#issuecomment-800234022: On some systems it's the admin's explicit choice not to to have the machine ID leak into the ESP On some systems the machine ID is transient, generated at every boot, and hence should not be written to the ESP --- man/kernel-install.xml | 10 +++++++--- src/kernel-install/kernel-install | 14 ++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/man/kernel-install.xml b/man/kernel-install.xml index 88208250e88..f278c2f5578 100644 --- a/man/kernel-install.xml +++ b/man/kernel-install.xml @@ -161,8 +161,12 @@ Environment variables + If is used, $KERNEL_INSTALL_VERBOSE=1 will be set for the plugins. They may output additional logs in this case. + + If MACHINE_ID= is set and not empty, it will be used as MACHINE-ID, + overriding any automatic detection attempts. The value must be a valid machine ID (32 hexadecimal characters). @@ -214,9 +218,9 @@ The content of this file specifies the machine identification - MACHINE-ID. If $BOOT/Default exists, - or /etc/machine-id doesn't, kernel-install - will use the literal Default as the machine ID instead. + MACHINE-ID. If /etc/machine-id + cannot be read or is temporary (backed by a file on tmpfs), + kernel-install will use Default instead. diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install index c9a80b2e3d4..89f00744178 100755 --- a/src/kernel-install/kernel-install +++ b/src/kernel-install/kernel-install @@ -85,20 +85,14 @@ fi KERNEL_VERSION="$1" KERNEL_IMAGE="$2" -# Reuse directory created without a machine ID present if it exists. -if [[ -d /efi/Default ]] || [[ -d /boot/Default ]] || [[ -d /boot/efi/Default ]]; then - MACHINE_ID="Default" -elif [[ -f /etc/machine-id ]]; then - read MACHINE_ID < /etc/machine-id -else - MACHINE_ID="Default" -fi - if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then echo "Not enough arguments" >&2 exit 1 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" + if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION" elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then @@ -113,7 +107,7 @@ else ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION" fi -export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID +export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID" ret=0 -- 2.47.3