| Server IP : 3.147.158.171 / Your IP : 216.73.216.216 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/kernel/install.d/ |
Upload File : |
#!/usr/bin/bash
if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
exit 0
fi
[[ -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
# If ${BOOT_DIR_ABS} exists, some other boot loader is active.
[[ -d "${BOOT_DIR_ABS}" ]] && exit 0
BLS_DIR="/boot/loader/entries"
mkbls() {
local kernelver=$1 && shift
local datetime=$1 && shift
local kernelopts=$1 && shift
local debugname=""
local debugid=""
local flavor=""
if [[ "$kernelver" == *\+* ]] ; then
local flavor=-"${kernelver##*+}"
if [[ "${flavor}" == "-debug" ]]; then
local debugname=" with debugging"
local debugid="-debug"
fi
fi
cat <<EOF
title ${NAME} (${kernelver}) ${VERSION}${debugname}
version ${kernelver}${debugid}
linux /vmlinuz-${kernelver}
initrd /initramfs-${kernelver}.img
options ${kernelopts}
grub_users \$grub_users
grub_arg --unrestricted
grub_class ${ID}
EOF
}
default_bls() {
local saved_entry
local saved_entry_file
saved_entry=$(grub2-editenv - list | grep -oP '(?<=saved_entry=).*$')
saved_entry_file=${BLS_DIR}/${saved_entry}.conf
# If there is no "saved_entry", try to take the running kernel
if [[ -z "$saved_entry" ]] || [[ ! -f "$saved_entry_file" ]]; then
for bls_file in "$BLS_DIR"/*-"$(uname -r)".conf; do
if [[ -f "$bls_file" ]]; then
# Let's set this as default explicitly
if [[ "$GRUB_UPDATE_DEFAULT_KERNEL" = "true" ]]; then
bls="${bls_file%.conf}"
bls="${bls##*/}"
grub2-editenv - set "saved_entry=${bls}"
fi
echo "$bls_file"
return
fi
done
else
echo "$saved_entry_file"
fi
}
[[ "$KERNEL_VERSION" == *\+* ]] && flavor=-"${KERNEL_VERSION##*+}"
case "$COMMAND" in
add)
if [[ "${KERNEL_DIR}" != "/boot" ]]; then
# rename to match the name used in the pseudo-BLS snippet above
rm -f "/boot/vmlinuz-${KERNEL_VERSION}"
cp --preserve=timestamps -T "${KERNEL_IMAGE}" "/boot/vmlinuz-${KERNEL_VERSION}"
command -v restorecon &>/dev/null && \
restorecon -R "/boot/vmlinuz-${KERNEL_VERSION}"
for i in \
"$KERNEL_DIR"/System.map \
"$KERNEL_DIR"/config \
"$KERNEL_DIR"/zImage.stub \
"$KERNEL_DIR"/dtb
do
[[ -e "$i" ]] || continue
rm -f "/boot/${i##*/}-${KERNEL_VERSION}"
cp --preserve=timestamps -T "$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
rm -f "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
cp --preserve=timestamps "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
command -v restorecon &>/dev/null && \
restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
fi
# OLD method using gzip'd file (will be deprecated and removed in the future)
# 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
# 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
fi
if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then
if [[ -f /etc/kernel/cmdline ]]; then
if [[ /etc/kernel/cmdline -ot /etc/default/grub ]]; then
# user modified /etc/default/grub manually; sync
grub2-mkconfig -o /etc/grub2.cfg
fi
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
elif [ ! -z "$GRUB_CMDLINE_LINUX" ] || [ ! -z "$GRUB_CMDLINE_LINUX_DEFAULT" ]; then
declare -a BOOT_OPTIONS
# Grab the root device and "ro" option from the current command line
# because doing otherwise is too hard
read -r -d '' -a line < /proc/cmdline
for i in "${line[@]}"; do
if [[ "${i#root=*}" != "$i" ]] ; then
BOOT_OPTIONS+=("$i")
fi
if [ "$i" == "ro" ]; then
BOOT_OPTIONS+=("$i")
fi
done
# Grab everything else from /etc/default/grub
if [ ! -z "$GRUB_CMDLINE_LINUX" ]; then
BOOT_OPTIONS+=("$GRUB_CMDLINE_LINUX")
fi
if [ ! -z "$GRUB_CMDLINE_LINUX_DEFAULT" ]; then
BOOT_OPTIONS+=("$GRUB_CMDLINE_LINUX_DEFAULT")
fi
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
eval "$(grub2-get-kernel-settings)" || true
[[ -d "$BLS_DIR" ]] || mkdir -m 0700 -p "$BLS_DIR"
BLS_ID="${MACHINE_ID}-${KERNEL_VERSION}"
BLS_TARGET="${BLS_DIR}/${BLS_ID}.conf"
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}"
LINUX="$(grep '^linux[ \t]' "${BLS_TARGET}" | sed -e 's,^linux[ \t]*,,')"
INITRD="$(grep '^initrd[ \t]' "${BLS_TARGET}" | sed -e 's,^initrd[ \t]*,,')"
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
BOOTPREFIX="$(dirname ${LINUX_RELPATH})"
ROOTPREFIX="$(dirname "/boot${LINUX}")"
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
if [[ "$KERNEL_VERSION" == *\+* ]] && [ "x$GRUB_DEFAULT_TO_DEBUG" != "xtrue" ]; then
GRUB_UPDATE_DEFAULT_KERNEL=false
fi
# Only update the default when making a minor kernel upgrade. This
# is to prevent unpredictability when multiple namespaced kernel
# packages are installed that each ship different major kernel
# versions.
#
# E.g. if you have kernel-A.B.C installed, then update the default
# when you install kernel-A.B.D. Do not update the default when
# installing kernel-X.Y.Z (with A!=X or B!=Y).
CUR_DEFAULT_BLS="$(default_bls)"
if [[ -f "$CUR_DEFAULT_BLS" ]]; then
CUR_DEFAULT_VERSION=$(grep -oP '(?<=version ).*' "$CUR_DEFAULT_BLS")
CUR_MAJOR=$(cut -d. -f1-2 <<<"$CUR_DEFAULT_VERSION")
NEW_MAJOR=$(cut -d. -f1-2 <<<"$KERNEL_VERSION")
if [[ "$CUR_MAJOR" != "$NEW_MAJOR" ]]; then
GRUB_UPDATE_DEFAULT_KERNEL=false
fi
fi
if [ "x$GRUB_UPDATE_DEFAULT_KERNEL" = "xtrue" ]; then
NEWDEFAULT="${BLS_ID}"
fi
if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
cp --preserve=timestamps -T "${BLS_TARGET}" "${BLS_DEBUG}"
TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')"
OPTIONS="$(echo "${BOOT_OPTIONS[*]} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')"
sed -i -e "s/^title.*/title ${TITLE}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}"
sed -i -e "s/^options.*/options ${OPTIONS}/" "${BLS_DEBUG}"
if [ -n "$NEWDEFAULT" -a "x$GRUB_DEFAULT_TO_DEBUG" = "xtrue" ]; then
NEWDEFAULT="${BLS_DEBUG_ID}"
fi
fi
if [ -n "$NEWDEFAULT" ]; then
grub2-editenv - set "saved_entry=${NEWDEFAULT}"
fi
# this probably isn't the best place to do this, but it will do for now.
if [ -e "${ROOTPREFIX}${INITRD}" -a -e "${ROOTPREFIX}${LINUX}" -a \
"${ROOTPREFIX}${INITRD}" -ot "${ROOTPREFIX}${LINUX}" -a \
-x /usr/lib/kernel/install.d/50-dracut.install ]; then
rm -f "${ROOTPREFIX}${INITRD}"
fi
exit 0
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 $?
# If grubby is used there's no need to run other installation plugins
exit 77
;;
remove)
if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then
BLS_TARGET="${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf"
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
rm -f "${BLS_TARGET}" "${BLS_DEBUG}"
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"
# symvers is symvers-<version>.gz symlink, needs a special treatment
rm -f "/boot/symvers-${KERNEL_VERSION}.gz"
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