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