Skip to content

Commit 9d8813b

Browse files
yuwatakeszybz
authored andcommitted
kernel-install: support the case /etc/machine-id is missing or empty (#5975)
Some .install plugins does not require that machine ID is set such as 20-grubby.install for Fedora and 50-depmod.install. To support such plugins to run without valid machine-id, this commit makes the following change: * if /etc/machine-id is missing or empty, create temporary directory and set its path to BOOT_DIR_ABS, * run the .install helpers with KERNEL_INSTALL_MACHINE_ID environment variable that'd be empty if /etc/machine-id is missing or empty. This may be useful for installing kernel for e.g. stateless systems which initialize machine-id while booting the systems.
1 parent e74d0a9 commit 9d8813b

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ CHANGES WITH 234 in spe
77
fallback was redundant and interfered with the [!UNAVAIL=return]
88
suffix. See nss-resolve(8) for the recommended configuration.
99

10+
* All kernel install plugins are called with the environment variable
11+
KERNEL_INSTALL_MACHINE_ID which is set to the machine ID given by
12+
/etc/machine-id. If the file is missing or empty, the variable is
13+
empty and BOOT_DIR_ABS is the path of a temporary directory which is
14+
removed after the all plugins exit. So, if KERNEL_INSTALL_MACHINE_ID
15+
is empty, all plugins should not put anything in BOOT_DIR_ABS.
16+
1017
CHANGES WITH 233:
1118

1219
* This version requires at least gperf 3.1 for building, 3.0 is not

src/kernel-install/90-loaderentry.install

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ KERNEL_VERSION="$2"
77
BOOT_DIR_ABS="$3"
88
KERNEL_IMAGE="$4"
99

10-
if [[ -f /etc/machine-id ]]; then
11-
read MACHINE_ID < /etc/machine-id
10+
if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
11+
exit 0
1212
fi
1313

14-
if ! [[ $MACHINE_ID ]]; then
15-
exit 1
16-
fi
14+
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
1715

1816
BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
1917
BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}

src/kernel-install/kernel-install

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,15 @@ if [[ -f /etc/machine-id ]]; then
7777
read MACHINE_ID < /etc/machine-id
7878
fi
7979

80-
if ! [[ $MACHINE_ID ]]; then
81-
echo "Could not determine your machine ID from /etc/machine-id." >&2
82-
echo "Please run 'systemd-machine-id-setup' as root. See man:machine-id(5)" >&2
83-
exit 1
84-
fi
85-
8680
if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
8781
echo "Not enough arguments" >&2
8882
exit 1
8983
fi
9084

91-
if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
85+
if ! [[ $MACHINE_ID ]]; then
86+
BOOT_DIR_ABS=$(mktemp -d /tmp/kernel-install.XXXXX) || exit 1
87+
trap "rm -rf '$BOOT_DIR_ABS'" EXIT INT QUIT PIPE
88+
elif [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
9289
BOOT_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
9390
elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
9491
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
@@ -102,6 +99,8 @@ else
10299
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
103100
fi
104101

102+
export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID
103+
105104
ret=0
106105

107106
readarray -t PLUGINS <<<"$(
@@ -127,11 +126,20 @@ case $COMMAND in
127126
"$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE"
128127
x=$?
129128
if [[ $x == $SKIP_REMAINING ]]; then
130-
exit 0
129+
ret=0
130+
break
131131
fi
132132
((ret+=$x))
133133
fi
134134
done
135+
136+
if ! [[ $MACHINE_ID ]] && ! rmdir "$BOOT_DIR_ABS"; then
137+
echo "Warning: In kernel-install plugins, requiring BOOT_DIR_ABS to be preset is deprecated." >&2
138+
echo " All plugins should not put anything in BOOT_DIR_ABS if the environment" >&2
139+
echo " variable KERNEL_INSTALL_MACHINE_ID is empty." >&2
140+
rm -rf "$BOOT_DIR_ABS"
141+
((ret+=$?))
142+
fi
135143
;;
136144

137145
remove)
@@ -140,7 +148,8 @@ case $COMMAND in
140148
"$f" remove "$KERNEL_VERSION" "$BOOT_DIR_ABS"
141149
x=$?
142150
if [[ $x == $SKIP_REMAINING ]]; then
143-
exit 0
151+
ret=0
152+
break
144153
fi
145154
((ret+=$x))
146155
fi

0 commit comments

Comments
 (0)