proxmox-boot: add grub-install wrapper

if a (legacy) system is booted with proxmox-boot-tool, running
`grub-install` without being aware of the fact can render the system
unbootable (e.g. when letting the early stage point to an incompatible
zpool instead of the ESP).

To prevent this we add a dpkg-diversion [0], which simply checks if
`proxmox-boot-tool status` indicates that proxmox-boot is used and
errors out in that case, and runs the actual grub-install else.

Co-authored-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
This commit is contained in:
Stoiko Ivanov 2021-04-23 11:04:49 +02:00 committed by Thomas Lamprecht
parent ff28956d40
commit 7290506104
6 changed files with 53 additions and 1 deletions

View File

@ -6,6 +6,7 @@ all:
install:
install -d ${SBINDIR}
install -m 0755 proxmox-boot-tool ${SBINDIR}/
install -m 0755 grub-install-wrapper ${SBINDIR}/grub-install
.PHONY: clean distclean
distclean:

12
bin/grub-install-wrapper Executable file
View File

@ -0,0 +1,12 @@
#! /bin/sh
set -e
. /usr/share/pve-kernel-helper/scripts/functions
if proxmox-boot-tool status --quiet; then
warn "grub-install is disabled because this system is booted via proxmox-boot-tool, if you really need to run it, run /usr/sbin/grub-install.real"
exit 1
else
grub-install.real "$@"
fi

View File

@ -161,7 +161,7 @@ init() {
mv "$esp_mp/$PMX_LOADER_CONF.tmp" "$esp_mp/$PMX_LOADER_CONF"
else
echo "Installing grub i386-pc target.."
grub-install \
grub-install.real \
--boot-directory $esp_mp \
--target i386-pc \
--no-floppy \

View File

@ -3,4 +3,5 @@ etc/kernel/postinst.d/*
etc/kernel/postrm.d/*
etc/initramfs/post-update.d/proxmox-boot-sync
usr/sbin/proxmox-boot-tool
usr/sbin/grub-install
usr/share/pve-kernel-helper/scripts/functions

22
debian/pve-kernel-helper.postrm vendored Normal file
View File

@ -0,0 +1,22 @@
#! /bin/sh
set -e
case "$1" in
remove|abort-install|disappear)
dpkg-divert --package pve-kernel-helper --remove --rename \
--divert /usr/sbin/grub-install.real /usr/sbin/grub-install
;;
abort-upgrade)
if [ -n "$2" ]; then
if dpkg --compare-versions "$2" lt 6.3-9; then
dpkg-divert --package pve-kernel-helper --remove --rename \
--divert /usr/sbin/grub-install.real /usr/sbin/grub-install
fi
fi
;;
esac
#DEBHELPER#
exit 0

16
debian/pve-kernel-helper.preinst vendored Normal file
View File

@ -0,0 +1,16 @@
#! /bin/sh
set -e
case "$1" in
install)
if [ -z "$2" ]; then
dpkg-divert --package pve-kernel-helper --add --rename \
--divert /usr/sbin/grub-install.real /usr/sbin/grub-install
fi
;;
esac
#DEBHELPER#
exit 0