1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 14:55:37 +03:00

Merge pull request #23439 from keszybz/kernel-install-verbose

Make kernel-install --verbose more verbose and some autodetection logic fixups
This commit is contained in:
Yu Watanabe 2022-05-21 04:26:03 +09:00 committed by GitHub
commit f65dcad5b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,7 +75,7 @@ fi
export KERNEL_INSTALL_VERBOSE=0 export KERNEL_INSTALL_VERBOSE=0
if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then
shift shift
KERNEL_INSTALL_VERBOSE=1 export KERNEL_INSTALL_VERBOSE=1
fi fi
if [ "${0##*/}" = "installkernel" ]; then if [ "${0##*/}" = "installkernel" ]; then
@ -103,25 +103,55 @@ layout=
initrd_generator= initrd_generator=
if [ -r "/etc/kernel/install.conf" ]; then if [ -r "/etc/kernel/install.conf" ]; then
. /etc/kernel/install.conf install_conf="/etc/kernel/install.conf"
elif [ -r "/usr/lib/kernel/install.conf" ]; then elif [ -r "/usr/lib/kernel/install.conf" ]; then
. /usr/lib/kernel/install.conf install_conf="/usr/lib/kernel/install.conf"
else
install_conf=
fi fi
if [ -n "$install_conf" ]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Reading $install_conf…"
. "$install_conf"
# FIXME: This may override configuration in environment variables, e.g. $BOOT_ROOT.
fi
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && [ -n "$layout" ] && \
echo "$install_conf configures layout=$layout"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && [ -n "$initrd_generator" ] && \
echo "$install_conf configures initrd_generator=$initrd_generator"
[ -n "$MACHINE_ID" ] && [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "machine-id $MACHINE_ID set via environment or install.conf"
[ -n "$BOOT_ROOT" ] && [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "BOOT_ROOT=$BOOT_ROOT set via environment or install.conf"
# If /etc/machine-id is initialized we'll use it, otherwise we'll use a freshly # If /etc/machine-id is initialized we'll use it, otherwise we'll use a freshly
# generated one. If the user configured an explicit machine ID to use in # generated one. If the user configured an explicit machine ID to use in
# /etc/machine-info to use for our purpose, we'll use that instead (for # /etc/machine-info to use for our purpose, we'll use that instead (for
# compatibility). # compatibility).
[ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID" if [ -z "$MACHINE_ID" ] && [ -r /etc/machine-info ] && . /etc/machine-info && MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"; then
[ -z "$MACHINE_ID" ] && [ -r /etc/machine-id ] && read -r MACHINE_ID </etc/machine-id [ -n "$MACHINE_ID" ] && [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
[ -z "$MACHINE_ID" ] && MACHINE_ID="$(systemd-id128 new)" echo "machine-id $MACHINE_ID acquired from /etc/machine-info"
fi
if [ -z "$MACHINE_ID" ] && [ -r /etc/machine-id ] && read -r MACHINE_ID </etc/machine-id; then
[ -n "$MACHINE_ID" ] && [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "machine-id $MACHINE_ID acquired from /etc/machine-id"
fi
if [ -z "$MACHINE_ID" ]; then
MACHINE_ID="$(systemd-id128 new)" || exit 1
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "new machine-id $MACHINE_ID generated"
fi
# Now that we determined the machine ID to use, let's determine the "token" for # Now that we determined the machine ID to use, let's determine the "token" for
# the boot loader entry to generate. We use that for naming the directory below # the boot loader entry to generate. We use that for naming the directory below
# $BOOT where we want to place the kernel/initrd and related resources, as well # $BOOT where we want to place the kernel/initrd and related resources, as well
# for naming the .conf boot loader spec entry. Typically this is just the # for naming the .conf boot loader spec entry. Typically this is just the
# machine ID, but it can be anything else, too, if we are told so. # machine ID, but it can be anything else, too, if we are told so.
[ -z "$ENTRY_TOKEN" ] && [ -r /etc/kernel/entry-token ] && read -r ENTRY_TOKEN </etc/kernel/entry-token if [ -z "$ENTRY_TOKEN" ] && [ -r /etc/kernel/entry-token ] && read -r ENTRY_TOKEN </etc/kernel/entry-token; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "entry-token \"$ENTRY_TOKEN\" acquired from /etc/kernel/entry-token"
fi
if [ -z "$ENTRY_TOKEN" ]; then if [ -z "$ENTRY_TOKEN" ]; then
# If not configured explicitly, then use a few candidates: the machine ID, # If not configured explicitly, then use a few candidates: the machine ID,
# the IMAGE_ID= and ID= fields from /etc/os-release and finally the fixed # the IMAGE_ID= and ID= fields from /etc/os-release and finally the fixed
@ -134,38 +164,65 @@ if [ -z "$ENTRY_TOKEN" ]; then
else else
ENTRY_TOKEN_SEARCH="$ENTRY_TOKEN" ENTRY_TOKEN_SEARCH="$ENTRY_TOKEN"
fi fi
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Entry-token candidates: $ENTRY_TOKEN_SEARCH"
# NB: The $MACHINE_ID is guaranteed to be a valid machine ID, but # NB: The $MACHINE_ID is guaranteed to be a valid machine ID, but
# $ENTRY_TOKEN can be any string that fits into a VFAT filename, though # $ENTRY_TOKEN can be any string that fits into a VFAT filename, though
# typically is just the machine ID. # typically is just the machine ID.
[ -z "$BOOT_ROOT" ] && for suff in $ENTRY_TOKEN_SEARCH; do if [ -n "$BOOT_ROOT" ]; then
for pref in "/efi" "/boot" "/boot/efi"; do # If this was already configured, don't try to guess
BOOT_ROOT_SEARCH="$BOOT_ROOT"
else
BOOT_ROOT_SEARCH="/efi /boot /boot/efi"
fi
for pref in $BOOT_ROOT_SEARCH; do
for suff in $ENTRY_TOKEN_SEARCH; do
if [ -d "$pref/$suff" ]; then if [ -d "$pref/$suff" ]; then
BOOT_ROOT="$pref" [ -z "$BOOT_ROOT" ] && BOOT_ROOT="$pref"
ENTRY_TOKEN="$suff" [ -z "$ENTRY_TOKEN" ] && ENTRY_TOKEN="$suff"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "$pref/$suff exists, using BOOT_ROOT=$BOOT_ROOT, ENTRY_TOKEN=$ENTRY_TOKEN"
break 2 break 2
else
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "$pref/$suff not found…"
fi
if [ -d "$pref/loader/entries" ]; then
[ -z "$BOOT_ROOT" ] && BOOT_ROOT="$pref"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "$pref/loader/entries exists, using BOOT_ROOT=$BOOT_ROOT"
break 2
else
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "$pref/loader/entries not found…"
fi fi
done done
done done
[ -z "$BOOT_ROOT" ] && for pref in "/efi" "/boot" "/boot/efi"; do
if [ -d "$pref/loader/entries" ]; then
BOOT_ROOT="$pref"
break
fi
done
[ -z "$BOOT_ROOT" ] && for pref in "/efi" "/boot/efi"; do [ -z "$BOOT_ROOT" ] && for pref in "/efi" "/boot/efi"; do
if mountpoint -q "$pref"; then if mountpoint -q "$pref"; then
BOOT_ROOT="$pref" BOOT_ROOT="$pref"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "$pref is a mount point, using BOOT_ROOT=$BOOT_ROOT"
break break
else
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "$pref is not a mount point…"
fi fi
done done
[ -z "$BOOT_ROOT" ] && BOOT_ROOT="/boot" if [ -z "$BOOT_ROOT" ]; then
BOOT_ROOT="/boot"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "KERNEL_INSTALL_BOOT_ROOT autodection yielded no candidates, using \"$BOOT_ROOT\""
fi
[ -z "$ENTRY_TOKEN" ] && ENTRY_TOKEN="$MACHINE_ID" if [ -z "$ENTRY_TOKEN" ]; then
ENTRY_TOKEN="$MACHINE_ID"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "No entry-token candidate matched, using \"$ENTRY_TOKEN\" from machine-id"
fi
if [ -z "$layout" ]; then if [ -z "$layout" ]; then
# No layout configured by the administrator. Let's try to figure it out # No layout configured by the administrator. Let's try to figure it out
@ -183,19 +240,27 @@ if [ -z "$layout" ]; then
# have no idea what that means, let's stay away from it by default. # have no idea what that means, let's stay away from it by default.
layout="other" layout="other"
fi fi
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
echo "$BOOT_ROOT/loader/entries.srel with '$ENTRIES_SREL' found, using layout=$layout"
elif [ -d "$BOOT_ROOT/$ENTRY_TOKEN" ]; then elif [ -d "$BOOT_ROOT/$ENTRY_TOKEN" ]; then
# If the metadata in $BOOT_ROOT doesn't tell us anything, then check if # If the metadata in $BOOT_ROOT doesn't tell us anything, then check if
# the entry token directory already exists. If so, let's assume it's # the entry token directory already exists. If so, let's assume it's
# the standard boot loader spec, too. # the standard boot loader spec, too.
layout="bls" layout="bls"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "$BOOT_ROOT/$ENTRY_TOKEN exists, using layout=$layout"
else else
# There's no metadata in $BOOT_ROOT, and apparently no entry token # There's no metadata in $BOOT_ROOT, and apparently no entry token
# directory installed? Then we really don't know anything. # directory installed? Then we really don't know anything.
layout="other" layout="other"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Entry-token directory not found, using layout=$layout"
fi fi
fi fi
ENTRY_DIR_ABS="$BOOT_ROOT/$ENTRY_TOKEN/$KERNEL_VERSION" ENTRY_DIR_ABS="$BOOT_ROOT/$ENTRY_TOKEN/$KERNEL_VERSION"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Using ENTRY_DIR_ABS=$ENTRY_DIR_ABS"
# Provide a directory where to store generated initrds # Provide a directory where to store generated initrds
cleanup() { cleanup() {
@ -226,6 +291,8 @@ PLUGINS="$(
IFS=" IFS="
" "
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo -e "Plugin files:\n$PLUGINS"
case "$COMMAND" in case "$COMMAND" in
add) add)
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then