From c9b8b10a612410bb1d1167169f0fc4f3381ba0ca Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 24 Oct 2018 12:51:55 -0400 Subject: [PATCH] 20-grub-install: Replace, rather than overwrite, the existing kernel. In rhbz#1638405, we worked around the issue of an existing initramfs being in the way by removing it if it's older than the kernel we're in the process of installing. But it was buggy and only worked with some filesystem layouts and paths, and also possibly had some issues with file creation times causing the shell -ot comparison to fail in some cases. This patch changes it to remove the existing kernel (as well as other related files) in the case that it's going to do the copy, and also fixes the path issues. Resolves: rhbz#1642402 Related: rhbz#1638405 Signed-off-by: Peter Jones Tested-by: Prarit Bhargava --- 20-grub.install | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/20-grub.install b/20-grub.install index 3f6e33f..3238e43 100755 --- a/20-grub.install +++ b/20-grub.install @@ -62,6 +62,7 @@ case "$COMMAND" in "$KERNEL_DIR"/dtb do [[ -e "$i" ]] || continue + rm -f "/boot/${i##*/}-${KERNEL_VERSION}" cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}" command -v restorecon &>/dev/null && \ restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}" @@ -69,6 +70,7 @@ case "$COMMAND" in # hmac is .vmlinuz-.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 -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" command -v restorecon &>/dev/null && \ restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" @@ -92,6 +94,7 @@ case "$COMMAND" in INITRD="$(grep '^initrd[ \t]' "${BLS_TARGET}" | sed -e 's,^initrd[ \t]*,,')" LINUX_RELPATH="$(grub2-mkrelpath /boot${LINUX})" BOOTPREFIX="$(dirname ${LINUX_RELPATH})" + ROOTPREFIX="$(dirname "/boot${LINUX}")" if [[ $LINUX != $LINUX_RELPATH ]]; then sed -i -e "s,^linux.*,linux ${BOOTPREFIX}${LINUX},g" "${BLS_TARGET}" @@ -124,10 +127,10 @@ case "$COMMAND" in fi # this probably isn't the best place to do this, but it will do for now. - if [ -e "${BOOTPREFIX}${INITRD}" -a -e "${BOOTPREFIX}${LINUX}" -a \ - "${BOOTPREFIX}${INITRD}" -ot "${BOOTPREFIX}${LINUX}" -a \ + 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 "${BOOTPREFIX}${INITRD}" + rm -f "${ROOTPREFIX}${INITRD}" fi exit 0 fi