]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install: respect $MACHINE_ID and ignore /etc/machine-id if on tmpfs
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Tue, 16 Mar 2021 16:38:20 +0000 (17:38 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Dec 2021 08:34:02 +0000 (09:34 +0100)
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
src/kernel-install/kernel-install

index 88208250e8824834dea16307898e9126d6ff502b..f278c2f5578664aabdc9885a49d7e74db89d09ba 100644 (file)
 
   <refsect1>
     <title>Environment variables</title>
+
     <para>If <option>--verbose</option> is used, <varname>$KERNEL_INSTALL_VERBOSE=1</varname> will be set for
     the plugins. They may output additional logs in this case.</para>
+
+    <para>If <varname>MACHINE_ID=</varname> is set and not empty, it will be used as <replaceable>MACHINE-ID</replaceable>,
+    overriding any automatic detection attempts.  The value must be a valid machine ID (32 hexadecimal characters).</para>
   </refsect1>
 
   <refsect1>
         </term>
           <listitem>
             <para>The content of this file specifies the machine identification
-            <replaceable>MACHINE-ID</replaceable>.  If <filename>$BOOT/Default</filename> exists,
-            or <filename>/etc/machine-id</filename> doesn't, <command>kernel-install</command>
-            will use the literal <literal>Default</literal> as the machine ID instead.</para>
+            <replaceable>MACHINE-ID</replaceable>. If <filename>/etc/machine-id</filename>
+            cannot be read or is temporary (backed by a file on <constant>tmpfs</constant>),
+            <command>kernel-install</command> will use <literal>Default</literal> instead.</para>
           </listitem>
       </varlistentry>
       <varlistentry>
index c9a80b2e3d4649bcb81b2efd06d3f7153b8fdd42..89f0074417871058a9bd95dcef4432901974d560 100755 (executable)
@@ -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