From 61faef65b2a6673c4aef96295f75f29519e19149 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mar 14 2018 21:09:34 +0000 Subject: 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 --- diff --git a/20-grub.install b/20-grub.install new file mode 100755 index 0000000..7613562 --- /dev/null +++ b/20-grub.install @@ -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-.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" <.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 diff --git a/grub2.spec b/grub2.spec index 8cbd416..ffaa495 100644 --- a/grub2.spec +++ b/grub2.spec @@ -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 - 2.02-28 +- Install kernel-install scripts. + * Tue Mar 06 2018 Peter Jones - 2.02-27 - Build the blscfg module in on EFI builds.