2018-03-09 10:20:12 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-06-15 13:06:00 +00:00
|
|
|
if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-03-09 10:20:12 +00:00
|
|
|
[[ -f /etc/default/grub ]] && . /etc/default/grub
|
|
|
|
[[ -f /etc/os-release ]] && . /etc/os-release
|
|
|
|
|
|
|
|
COMMAND="$1"
|
|
|
|
KERNEL_VERSION="$2"
|
|
|
|
BOOT_DIR_ABS="$3"
|
|
|
|
KERNEL_IMAGE="$4"
|
|
|
|
|
|
|
|
KERNEL_DIR="${KERNEL_IMAGE%/*}"
|
|
|
|
|
|
|
|
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
|
|
|
|
|
2019-03-08 17:22:23 +00:00
|
|
|
# If ${BOOT_DIR_ABS} exists, some other boot loader is active.
|
|
|
|
[[ -d "${BOOT_DIR_ABS}" ]] && exit 0
|
2018-03-09 10:20:12 +00:00
|
|
|
|
|
|
|
BLS_DIR="/boot/loader/entries"
|
|
|
|
|
2018-04-03 17:41:24 +00:00
|
|
|
mkbls() {
|
|
|
|
local kernelver=$1 && shift
|
|
|
|
local datetime=$1 && shift
|
2020-05-06 17:13:01 +00:00
|
|
|
local kernelopts=$1 && shift
|
2018-04-03 17:41:24 +00:00
|
|
|
|
|
|
|
local debugname=""
|
2018-05-10 15:48:20 +00:00
|
|
|
local debugid=""
|
2018-04-03 17:41:24 +00:00
|
|
|
local flavor=""
|
|
|
|
|
2018-05-10 15:48:20 +00:00
|
|
|
if [[ "$kernelver" == *\+* ]] ; then
|
|
|
|
local flavor=-"${kernelver##*+}"
|
2018-04-03 17:41:24 +00:00
|
|
|
if [[ "${flavor}" == "-debug" ]]; then
|
|
|
|
local debugname=" with debugging"
|
2018-05-10 15:48:20 +00:00
|
|
|
local debugid="-debug"
|
2018-04-03 17:41:24 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
title ${NAME} (${kernelver}) ${VERSION}${debugname}
|
2018-05-10 15:48:20 +00:00
|
|
|
version ${kernelver}${debugid}
|
2018-04-03 17:41:24 +00:00
|
|
|
linux /vmlinuz-${kernelver}
|
|
|
|
initrd /initramfs-${kernelver}.img
|
2020-05-06 17:13:01 +00:00
|
|
|
options ${kernelopts}
|
2018-04-03 17:41:24 +00:00
|
|
|
grub_users \$grub_users
|
|
|
|
grub_arg --unrestricted
|
2021-06-29 13:31:16 +00:00
|
|
|
grub_class ${ID}
|
2018-04-03 17:41:24 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2018-03-09 10:20:12 +00:00
|
|
|
[[ "$KERNEL_VERSION" == *\+* ]] && flavor=-"${KERNEL_VERSION##*+}"
|
|
|
|
case "$COMMAND" in
|
|
|
|
add)
|
|
|
|
if [[ "${KERNEL_DIR}" != "/boot" ]]; then
|
|
|
|
for i in \
|
|
|
|
"$KERNEL_IMAGE" \
|
|
|
|
"$KERNEL_DIR"/System.map \
|
|
|
|
"$KERNEL_DIR"/config \
|
|
|
|
"$KERNEL_DIR"/zImage.stub \
|
2018-04-03 17:41:24 +00:00
|
|
|
"$KERNEL_DIR"/dtb
|
|
|
|
do
|
2018-03-09 10:20:12 +00:00
|
|
|
[[ -e "$i" ]] || continue
|
2018-10-24 16:51:55 +00:00
|
|
|
rm -f "/boot/${i##*/}-${KERNEL_VERSION}"
|
2018-03-09 10:20:12 +00:00
|
|
|
cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}"
|
|
|
|
done
|
|
|
|
# hmac is .vmlinuz-<version>.hmac so needs a special treatment
|
|
|
|
i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac"
|
|
|
|
if [[ -e "$i" ]]; then
|
2018-10-24 16:51:55 +00:00
|
|
|
rm -f "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
2018-03-09 10:20:12 +00:00
|
|
|
cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
|
|
|
fi
|
2022-12-05 00:41:23 +00:00
|
|
|
# OLD method using gzip'd file (will be deprecated and removed in the future)
|
2021-06-21 06:08:10 +00:00
|
|
|
# symvers is symvers-<version>.gz symlink, needs a special treatment
|
|
|
|
i="$KERNEL_DIR/symvers.gz"
|
|
|
|
if [[ -e "$i" ]]; then
|
|
|
|
rm -f "/boot/symvers-${KERNEL_VERSION}.gz"
|
|
|
|
ln -s "$i" "/boot/symvers-${KERNEL_VERSION}.gz"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon "/boot/symvers-${KERNEL_VERSION}.gz"
|
|
|
|
fi
|
2022-12-05 00:41:23 +00:00
|
|
|
# symvers is symvers-<version>.bz symlink, needs a special treatment
|
|
|
|
i="$KERNEL_DIR/symvers.bz"
|
|
|
|
if [[ -e "$i" ]]; then
|
|
|
|
rm -f "/boot/symvers-${KERNEL_VERSION}.bz"
|
|
|
|
ln -s "$i" "/boot/symvers-${KERNEL_VERSION}.bz"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon "/boot/symvers-${KERNEL_VERSION}.bz"
|
|
|
|
fi
|
2018-03-09 10:20:12 +00:00
|
|
|
fi
|
|
|
|
|
2018-04-03 17:41:24 +00:00
|
|
|
if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then
|
2020-05-06 17:13:01 +00:00
|
|
|
if [[ -f /etc/kernel/cmdline ]]; then
|
2022-08-17 15:03:25 +00:00
|
|
|
if [[ /etc/kernel/cmdline -ot /etc/default/grub ]]; then
|
|
|
|
# user modified /etc/default/grub manually; sync
|
|
|
|
grub2-mkconfig -o /etc/grub2.cfg
|
|
|
|
fi
|
2020-05-06 17:13:01 +00:00
|
|
|
read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
|
|
|
|
elif [[ -f /usr/lib/kernel/cmdline ]]; then
|
|
|
|
read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline
|
|
|
|
else
|
|
|
|
declare -a BOOT_OPTIONS
|
|
|
|
|
|
|
|
read -r -d '' -a line < /proc/cmdline
|
|
|
|
for i in "${line[@]}"; do
|
|
|
|
[[ "${i#initrd=*}" != "$i" ]] && continue
|
|
|
|
[[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
|
|
|
|
BOOT_OPTIONS+=("$i")
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2018-10-23 09:10:09 +00:00
|
|
|
eval "$(grub2-get-kernel-settings)" || true
|
2018-04-03 17:41:24 +00:00
|
|
|
[[ -d "$BLS_DIR" ]] || mkdir -m 0700 -p "$BLS_DIR"
|
2018-10-23 09:10:09 +00:00
|
|
|
BLS_ID="${MACHINE_ID}-${KERNEL_VERSION}"
|
|
|
|
BLS_TARGET="${BLS_DIR}/${BLS_ID}.conf"
|
2020-05-06 17:13:01 +00:00
|
|
|
mkbls "${KERNEL_VERSION}" \
|
|
|
|
"$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${KERNEL_DIR}")")" \
|
|
|
|
"${BOOT_OPTIONS[*]}" >"${BLS_TARGET}"
|
|
|
|
command -v restorecon &>/dev/null && restorecon -R "${BLS_TARGET}"
|
2018-04-11 11:48:47 +00:00
|
|
|
|
2018-06-04 16:28:07 +00:00
|
|
|
LINUX="$(grep '^linux[ \t]' "${BLS_TARGET}" | sed -e 's,^linux[ \t]*,,')"
|
|
|
|
INITRD="$(grep '^initrd[ \t]' "${BLS_TARGET}" | sed -e 's,^initrd[ \t]*,,')"
|
2021-06-30 09:38:27 +00:00
|
|
|
if [[ "$(grub2-probe --device $(grub2-probe --target=device /) --target=fs)" == "btrfs" &&
|
|
|
|
"${SUSE_BTRFS_SNAPSHOT_BOOTING}" == "true" ]]; then
|
|
|
|
LINUX_RELPATH="$(grub2-mkrelpath -r /boot${LINUX})"
|
|
|
|
else
|
|
|
|
LINUX_RELPATH="$(grub2-mkrelpath /boot${LINUX})"
|
|
|
|
fi
|
2018-06-04 16:28:07 +00:00
|
|
|
BOOTPREFIX="$(dirname ${LINUX_RELPATH})"
|
2018-10-24 16:51:55 +00:00
|
|
|
ROOTPREFIX="$(dirname "/boot${LINUX}")"
|
2018-06-04 16:28:07 +00:00
|
|
|
|
|
|
|
if [[ $LINUX != $LINUX_RELPATH ]]; then
|
|
|
|
sed -i -e "s,^linux.*,linux ${BOOTPREFIX}${LINUX},g" "${BLS_TARGET}"
|
|
|
|
sed -i -e "s,^initrd.*,initrd ${BOOTPREFIX}${INITRD},g" "${BLS_TARGET}"
|
|
|
|
fi
|
|
|
|
|
2023-08-22 12:14:44 +00:00
|
|
|
if ( [[ "$KERNEL_VERSION" != *${GRUB_DEFAULT_KERNEL_TYPE}* ]] && \
|
|
|
|
[ "x$GRUB_NON_STANDARD_KERNEL" == "xtrue" ] ) || \
|
|
|
|
( echo "$KERNEL_VERSION" | grep -E -q "64k|auto|rt|uki" && \
|
|
|
|
[ "x$GRUB_NON_STANDARD_KERNEL" != "xtrue" ] ) || \
|
|
|
|
( [[ "$KERNEL_VERSION" == *debug* ]] && [ "x$GRUB_DEFAULT_TO_DEBUG" != "xtrue" ] ); then
|
2018-10-25 08:54:24 +00:00
|
|
|
GRUB_UPDATE_DEFAULT_KERNEL=false
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$GRUB_UPDATE_DEFAULT_KERNEL" = "xtrue" ]; then
|
|
|
|
NEWDEFAULT="${BLS_ID}"
|
|
|
|
fi
|
|
|
|
|
2018-04-11 11:48:47 +00:00
|
|
|
if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
|
2018-10-19 16:56:26 +00:00
|
|
|
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
|
2018-04-11 11:48:47 +00:00
|
|
|
cp -aT "${BLS_TARGET}" "${BLS_DEBUG}"
|
|
|
|
TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')"
|
2020-05-06 17:13:01 +00:00
|
|
|
OPTIONS="$(echo "${BOOT_OPTIONS[*]} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')"
|
2018-04-11 11:48:47 +00:00
|
|
|
sed -i -e "s/^title.*/title ${TITLE}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}"
|
2020-05-06 17:13:01 +00:00
|
|
|
sed -i -e "s/^options.*/options ${OPTIONS}/" "${BLS_DEBUG}"
|
2018-10-25 08:54:24 +00:00
|
|
|
if [ -n "$NEWDEFAULT" -a "x$GRUB_DEFAULT_TO_DEBUG" = "xtrue" ]; then
|
2018-10-23 09:10:09 +00:00
|
|
|
NEWDEFAULT="${BLS_DEBUG_ID}"
|
|
|
|
fi
|
|
|
|
fi
|
2018-10-25 08:54:24 +00:00
|
|
|
if [ -n "$NEWDEFAULT" ]; then
|
|
|
|
grub2-editenv - set "saved_entry=${NEWDEFAULT}"
|
|
|
|
fi
|
2018-04-11 11:48:47 +00:00
|
|
|
|
2018-10-11 20:13:17 +00:00
|
|
|
# this probably isn't the best place to do this, but it will do for now.
|
2018-10-24 16:51:55 +00:00
|
|
|
if [ -e "${ROOTPREFIX}${INITRD}" -a -e "${ROOTPREFIX}${LINUX}" -a \
|
|
|
|
"${ROOTPREFIX}${INITRD}" -ot "${ROOTPREFIX}${LINUX}" -a \
|
2018-10-11 20:13:17 +00:00
|
|
|
-x /usr/lib/kernel/install.d/50-dracut.install ]; then
|
2018-10-24 16:51:55 +00:00
|
|
|
rm -f "${ROOTPREFIX}${INITRD}"
|
2018-10-11 20:13:17 +00:00
|
|
|
fi
|
2018-04-03 17:41:24 +00:00
|
|
|
exit 0
|
2018-03-09 10:20:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --install "$KERNEL_VERSION" || exit $?
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --mkinitrd --dracut --depmod --update "$KERNEL_VERSION" || exit $?
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --rpmposttrans "$KERNEL_VERSION" || exit $?
|
2018-04-03 17:41:24 +00:00
|
|
|
# If grubby is used there's no need to run other installation plugins
|
|
|
|
exit 77
|
2018-03-09 10:20:12 +00:00
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
|
2018-04-03 17:41:24 +00:00
|
|
|
if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then
|
2018-04-11 11:48:47 +00:00
|
|
|
BLS_TARGET="${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf"
|
2018-10-19 16:56:26 +00:00
|
|
|
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
|
2018-04-11 11:48:47 +00:00
|
|
|
rm -f "${BLS_TARGET}" "${BLS_DEBUG}"
|
2018-03-09 10:20:12 +00:00
|
|
|
|
|
|
|
for i in vmlinuz System.map config zImage.stub dtb; do
|
|
|
|
rm -rf "/boot/${i}-${KERNEL_VERSION}"
|
|
|
|
done
|
|
|
|
# hmac is .vmlinuz-<version>.hmac so needs a special treatment
|
|
|
|
rm -f "/boot/.vmlinuz-${KERNEL_VERSION}.hmac"
|
2021-06-21 06:08:10 +00:00
|
|
|
# symvers is symvers-<version>.gz symlink, needs a special treatment
|
|
|
|
rm -f "/boot/symvers-${KERNEL_VERSION}.gz"
|
2018-03-09 10:20:12 +00:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor+-$flavor}" --rminitrd --rmmoddep --remove "$KERNEL_VERSION" || exit $?
|
|
|
|
# If grubby is used there's no need to run other installation plugins
|
|
|
|
exit 77
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|