Skip to content

Commit 357376d

Browse files
committed
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.
1 parent 447a822 commit 357376d

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

NEWS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6400,6 +6400,15 @@ CHANGES WITH 234:
64006400
temporary directory is passed as the entry directory and removed
64016401
after all the plugins exit.
64026402

6403+
* If KERNEL_INSTALL_MACHINE_ID is set in /etc/machine-info, kernel-install
6404+
will now use its value as the machine ID instead of the machine ID
6405+
from /etc/machine-id. If KERNEL_INSTALL_MACHINE_ID isn't set in
6406+
/etc/machine-info and no machine ID is set in /etc/machine-id,
6407+
kernel-install will try to store the current machine ID there as
6408+
KERNEL_INSTALL_MACHINE_ID. If there is no machine ID, kernel-install
6409+
will generate a new UUID, store it in /etc/machine-info as
6410+
KERNEL_INSTALL_MACHINE_ID and use it as the machine ID.
6411+
64036412
Contributions from: Adrian Heine né Lang, Aggelos Avgerinos, Alexander
64046413
Kurtz, Alexandros Frantzis, Alexey Brodkin, Alex Lu, Amir Pakdel, Amir
64056414
Yalon, Anchor Cat, Anthony Parsons, Bastien Nocera, Benjamin Gilbert,

man/kernel-install.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@
228228
<command>kernel-install</command> will use <literal>Default</literal> instead.</para>
229229
</listitem>
230230
</varlistentry>
231+
<varlistentry>
232+
<term>
233+
<filename>/etc/machine-info</filename>
234+
</term>
235+
<listitem>
236+
<para>If this file contains the <varname>KERNEL_INSTALL_MACHINE_ID</varname> variable,
237+
<command>kernel-install</command> will use it as <replaceable>MACHINE-ID</replaceable> instead of
238+
the contents of <filename>/etc/machine-id</filename>. If the variable is not found in
239+
<filename>/etc/machine-info</filename>, <command>kernel-install</command> will try to save the
240+
machine ID it uses to install to <varname>$BOOT</varname> to this file.</para>
241+
</listitem>
242+
</varlistentry>
231243
<varlistentry>
232244
<term>
233245
<filename>/etc/os-release</filename>

man/machine-info.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@
128128
specific as <literal>Left Rack, 2nd Shelf</literal>.
129129
</para></listitem>
130130
</varlistentry>
131+
132+
<varlistentry>
133+
<term><varname>KERNEL_INSTALL_MACHINE_ID=</varname></term>
134+
135+
<listitem><para>Specifies the installation-specific installation directory
136+
<command>kernel-install</command> should use. The value must be a valid machine ID (32 hexadecimal
137+
characters). This would generally be the original machine-id that was used when the boot loader
138+
entries for this installation were first added. When not set, the current value of
139+
<cite>machine-id(5)</cite> will be used.</para></listitem>
140+
</varlistentry>
131141
</variablelist>
132142
</refsect1>
133143

src/kernel-install/kernel-install

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
9090
exit 1
9191
fi
9292

93-
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && [ "$(stat -fc %T /etc/machine-id)" != "tmpfs" ] && read -r MACHINE_ID < /etc/machine-id
93+
# Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine
94+
# ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate
95+
# a new machine ID in /etc/machine-info. If that fails, use "Default".
96+
97+
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
98+
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && read -r MACHINE_ID </etc/machine-id
99+
[ -n "$MACHINE_ID" ] && [ -z "$KERNEL_INSTALL_MACHINE_ID" ] && echo "KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID" >>/etc/machine-info
100+
[ -z "$MACHINE_ID" ] && NEW_MACHINE_ID="$(systemd-id128 new)" && echo "KERNEL_INSTALL_MACHINE_ID=$NEW_MACHINE_ID" >>/etc/machine-info
101+
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ] && source /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
94102
[ -z "$MACHINE_ID" ] && MACHINE_ID="Default"
95103

96104
[ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "loader/entries"; do

0 commit comments

Comments
 (0)