]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install: Introduce KERNEL_INSTALL_MACHINE_ID in /etc/machine-info 21757/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 14 Dec 2021 16:09:08 +0000 (17:09 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 16 Dec 2021 11:24:42 +0000 (12:24 +0100)
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
man/kernel-install.xml
man/machine-info.xml
src/kernel-install/kernel-install

diff --git a/NEWS b/NEWS
index 6dcfd8061022903932687734d5668aa31f9d14e0..38af20b76969b519bdbf4fb76a64346e8e35a884 100644 (file)
--- 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,
index 670beb35b8ba55576abd709459e764804958952d..c6414b13dd10a5efc9c5ffd1836fb463a014340e 100644 (file)
             <command>kernel-install</command> will use <literal>Default</literal> instead.</para>
           </listitem>
       </varlistentry>
+      <varlistentry>
+        <term>
+          <filename>/etc/machine-info</filename>
+        </term>
+          <listitem>
+            <para>If this file contains the <varname>KERNEL_INSTALL_MACHINE_ID</varname> variable,
+            <command>kernel-install</command> will use it as <replaceable>MACHINE-ID</replaceable> instead of
+            the contents of <filename>/etc/machine-id</filename>. If the variable is not found in
+            <filename>/etc/machine-info</filename>, <command>kernel-install</command> will try to save the
+            machine ID it uses to install to <varname>$BOOT</varname> to this file.</para>
+          </listitem>
+      </varlistentry>
       <varlistentry>
         <term>
           <filename>/etc/os-release</filename>
index 3de68100470d375e4659aba9b6c880bce6571154..b4b5af26e08a1ad79d9d0d393b3665ce80aaa186 100644 (file)
         specific as <literal>Left Rack, 2nd Shelf</literal>.
         </para></listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term><varname>KERNEL_INSTALL_MACHINE_ID=</varname></term>
+
+        <listitem><para>Specifies the installation-specific installation directory
+        <command>kernel-install</command> 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
+        <cite>machine-id(5)</cite> will be used.</para></listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
 
index f2d954f2dd409d9cb1fb9114db09ba392224e988..103b44ebda73faeb3b5b0b63e017e099ec84cdcc 100755 (executable)
@@ -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-id
+[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$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