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.
This commit is contained in:
parent
e74d0a9a5c
commit
9d8813b3b4
7
NEWS
7
NEWS
|
@ -7,6 +7,13 @@ CHANGES WITH 234 in spe
|
||||||
fallback was redundant and interfered with the [!UNAVAIL=return]
|
fallback was redundant and interfered with the [!UNAVAIL=return]
|
||||||
suffix. See nss-resolve(8) for the recommended configuration.
|
suffix. See nss-resolve(8) for the recommended configuration.
|
||||||
|
|
||||||
|
* All kernel install plugins are called with the environment variable
|
||||||
|
KERNEL_INSTALL_MACHINE_ID which is set to the machine ID given by
|
||||||
|
/etc/machine-id. If the file is missing or empty, the variable is
|
||||||
|
empty and BOOT_DIR_ABS is the path of a temporary directory which is
|
||||||
|
removed after the all plugins exit. So, if KERNEL_INSTALL_MACHINE_ID
|
||||||
|
is empty, all plugins should not put anything in BOOT_DIR_ABS.
|
||||||
|
|
||||||
CHANGES WITH 233:
|
CHANGES WITH 233:
|
||||||
|
|
||||||
* This version requires at least gperf 3.1 for building, 3.0 is not
|
* This version requires at least gperf 3.1 for building, 3.0 is not
|
||||||
|
|
|
@ -7,13 +7,11 @@ KERNEL_VERSION="$2"
|
||||||
BOOT_DIR_ABS="$3"
|
BOOT_DIR_ABS="$3"
|
||||||
KERNEL_IMAGE="$4"
|
KERNEL_IMAGE="$4"
|
||||||
|
|
||||||
if [[ -f /etc/machine-id ]]; then
|
if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
|
||||||
read MACHINE_ID < /etc/machine-id
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [[ $MACHINE_ID ]]; then
|
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
|
BOOT_DIR="/$MACHINE_ID/$KERNEL_VERSION"
|
||||||
BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
|
BOOT_ROOT=${BOOT_DIR_ABS%$BOOT_DIR}
|
||||||
|
|
|
@ -77,18 +77,15 @@ if [[ -f /etc/machine-id ]]; then
|
||||||
read MACHINE_ID < /etc/machine-id
|
read MACHINE_ID < /etc/machine-id
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [[ $MACHINE_ID ]]; then
|
|
||||||
echo "Could not determine your machine ID from /etc/machine-id." >&2
|
|
||||||
echo "Please run 'systemd-machine-id-setup' as root. See man:machine-id(5)" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
|
if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
|
||||||
echo "Not enough arguments" >&2
|
echo "Not enough arguments" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
|
if ! [[ $MACHINE_ID ]]; then
|
||||||
|
BOOT_DIR_ABS=$(mktemp -d /tmp/kernel-install.XXXXX) || exit 1
|
||||||
|
trap "rm -rf '$BOOT_DIR_ABS'" EXIT INT QUIT PIPE
|
||||||
|
elif [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
|
||||||
BOOT_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
|
BOOT_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
|
||||||
elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
|
elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
|
||||||
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
|
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
|
||||||
|
@ -102,6 +99,8 @@ else
|
||||||
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
|
BOOT_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export KERNEL_INSTALL_MACHINE_ID=$MACHINE_ID
|
||||||
|
|
||||||
ret=0
|
ret=0
|
||||||
|
|
||||||
readarray -t PLUGINS <<<"$(
|
readarray -t PLUGINS <<<"$(
|
||||||
|
@ -127,11 +126,20 @@ case $COMMAND in
|
||||||
"$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE"
|
"$f" add "$KERNEL_VERSION" "$BOOT_DIR_ABS" "$KERNEL_IMAGE"
|
||||||
x=$?
|
x=$?
|
||||||
if [[ $x == $SKIP_REMAINING ]]; then
|
if [[ $x == $SKIP_REMAINING ]]; then
|
||||||
exit 0
|
ret=0
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
((ret+=$x))
|
((ret+=$x))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if ! [[ $MACHINE_ID ]] && ! rmdir "$BOOT_DIR_ABS"; then
|
||||||
|
echo "Warning: In kernel-install plugins, requiring BOOT_DIR_ABS to be preset is deprecated." >&2
|
||||||
|
echo " All plugins should not put anything in BOOT_DIR_ABS if the environment" >&2
|
||||||
|
echo " variable KERNEL_INSTALL_MACHINE_ID is empty." >&2
|
||||||
|
rm -rf "$BOOT_DIR_ABS"
|
||||||
|
((ret+=$?))
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
remove)
|
remove)
|
||||||
|
@ -140,7 +148,8 @@ case $COMMAND in
|
||||||
"$f" remove "$KERNEL_VERSION" "$BOOT_DIR_ABS"
|
"$f" remove "$KERNEL_VERSION" "$BOOT_DIR_ABS"
|
||||||
x=$?
|
x=$?
|
||||||
if [[ $x == $SKIP_REMAINING ]]; then
|
if [[ $x == $SKIP_REMAINING ]]; then
|
||||||
exit 0
|
ret=0
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
((ret+=$x))
|
((ret+=$x))
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue