ac3a84
From abbfdf2aa3e17a84d0f4075f125e670defaf7296 Mon Sep 17 00:00:00 2001
ac3a84
From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= <marcus.schaefer@gmail.com>
ac3a84
Date: Wed, 16 Nov 2022 00:17:19 +0100
ac3a84
Subject: [PATCH] Fix reading /etc/machine-id in kernel-install (#25388)
ac3a84
ac3a84
* Fix reading /etc/machine-id in kernel-install
ac3a84
ac3a84
The kernel-install script has code to read the contents of
ac3a84
/etc/machine-id into the MACHINE_ID variable. Depending
ac3a84
on the variable content kernel-install either logs the
ac3a84
value or creates a new machine id via 'systemd-id128 new'.
ac3a84
In that logic there is one issue. If the file /etc/machine-id
ac3a84
exists but is empty, the script tries to call read on an
ac3a84
empty file which return with an exit code != 0. As the
ac3a84
script code also uses 'set -e', kernel-install will exit at
ac3a84
this point which is unexpected.
ac3a84
ac3a84
The condition of an empty /etc/machine-id file exists for
ac3a84
example when building OS images, which should initialize the
ac3a84
system id on first boot but not staticly inside of the image.
ac3a84
afaik an empty /etc/machine-id is also a common approach
ac3a84
to make systemd indicate that it should create a new system
ac3a84
id. Because of this, the commit makes sure the reading of
ac3a84
/etc/machine-id does not fail in any case such that the
ac3a84
handling of the MACHINE_ID variable takes place.
ac3a84
ac3a84
(cherry picked from commit 883e7cbfc0dba6c81338e7924419b5cbb0cba0b2)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/kernel-install/kernel-install.in | 2 +-
ac3a84
 1 file changed, 1 insertion(+), 1 deletion(-)
ac3a84
ac3a84
diff --git a/src/kernel-install/kernel-install.in b/src/kernel-install/kernel-install.in
ac3a84
index 22eb4d2be1..bba22f8a20 100755
ac3a84
--- a/src/kernel-install/kernel-install.in
ac3a84
+++ b/src/kernel-install/kernel-install.in
ac3a84
@@ -158,7 +158,7 @@ if [ -z "$MACHINE_ID" ] && [ -f /etc/machine-info ]; then
ac3a84
     [ -n "$MACHINE_ID" ] && \
ac3a84
         log_verbose "machine-id $MACHINE_ID acquired from /etc/machine-info"
ac3a84
 fi
ac3a84
-if [ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ]; then
ac3a84
+if [ -z "$MACHINE_ID" ] && [ -s /etc/machine-id ]; then
ac3a84
     read -r MACHINE_ID 
ac3a84
     [ -n "$MACHINE_ID" ] && \
ac3a84
         log_verbose "machine-id $MACHINE_ID acquired from /etc/machine-id"