Add kernel-install scripts

Install a 20-grubby.install and 90-loaderentry.install kernel-install
scripts in /etc/kernel/install.d so these have higher precedence than
the ones installed in /usr/lib/kernel/install.d by the systemd pkg.

If GRUB 2 pkg isn't installed, then the systemd scripts are executed
on kernel installation and removal.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
This commit is contained in:
Javier Martinez Canillas 2018-03-09 11:20:12 +01:00 committed by Peter Jones
parent 06b68a8c94
commit 61faef65b2
2 changed files with 112 additions and 1 deletions

99
20-grub.install Executable file
View File

@ -0,0 +1,99 @@
#!/bin/bash
[[ -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
# Remove it, since for grub2 the images are always installed in /boot
rm -rf "${BOOT_DIR_ABS%/*}"
BLS_DIR="/boot/loader/entries"
if [ -d /sys/firmware/efi ]; then
BLS_DIR="/boot/efi/EFI/${ID}/loader/entries"
fi
[[ "$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 \
"$KERNEL_DIR"/dtb \
; do
[[ -e "$i" ]] || continue
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
cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
command -v restorecon &>/dev/null && \
restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
fi
fi
if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then
[[ -d "$BLS_DIR" ]] || mkdir -p "$BLS_DIR"
if [[ ! -f "${KERNEL_DIR}/bls.conf" ]]; then
if [ "${flavor}" = "-debug" ]; then
debugname=" with debugging"
else
debugname=""
fi
cat >"${KERNEL_DIR}/bls.conf" <<EOF
title ${NAME} (${KERNEL_VERSION}) ${VERSION}${debugname}
linux /vmlinuz-${KERNEL_VERSION}
initrd /initramfs-${KERNEL_VERSION}.img
options \$kernelopts
id ${ID}-0-${KERNEL_VERSION}
grub_users \$grub_users
grub_arg --unrestricted
grub_class kernel${flavor}
EOF
fi
cp -aT "${KERNEL_DIR}/bls.conf" "${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf" || exit $?
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
rm -f "${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf"
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"
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

View File

@ -7,7 +7,7 @@
Name: grub2
Epoch: 1
Version: 2.02
Release: 27%{?dist}
Release: 28%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
Group: System Environment/Base
License: GPLv3+
@ -21,6 +21,7 @@ Source4: http://unifoundry.com/unifont-5.1.20080820.pcf.gz
Source5: theme.tar.bz2
Source6: gitignore
Source8: strtoull_test.c
Source9: 20-grub.install
%include %{SOURCE1}
@ -211,6 +212,11 @@ cat << EOF > ${RPM_BUILD_ROOT}%{_sysconfdir}/prelink.conf.d/grub2.conf
-b /usr/sbin/grub2-sparc64-setup
EOF
# Install kernel-install scripts
install -Dm0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE9}
ln -sf /dev/null %{buildroot}%{_sysconfdir}/kernel/install.d/20-grubby.install
ln -sf /dev/null %{buildroot}%{_sysconfdir}/kernel/install.d/90-loaderentry.install
# Don't run debuginfo on all the grub modules and whatnot; it just
# rejects them, complains, and slows down extraction.
%global finddebugroot "%{_builddir}/%{?buildsubdir}/debug"
@ -303,6 +309,9 @@ fi
%dir %{_datarootdir}/grub/themes/
%exclude %{_datarootdir}/grub/themes/*
%attr(0700,root,root) %dir %{_sysconfdir}/grub.d
%{_prefix}/lib/kernel/install.d/20-grub.install
%{_sysconfdir}/kernel/install.d/20-grubby.install
%{_sysconfdir}/kernel/install.d/90-loaderentry.install
%dir %{_datarootdir}/grub
%exclude %{_datarootdir}/grub/*
%dir /boot/%{name}
@ -451,6 +460,9 @@ fi
%endif
%changelog
* Fri Mar 09 2018 Javier Martinez Canillas <javierm@redhat.com> - 2.02-28
- Install kernel-install scripts.
* Tue Mar 06 2018 Peter Jones <pjones@redhat.com> - 2.02-27
- Build the blscfg module in on EFI builds.