]> git.proxmox.com Git - pve-kernel-meta.git/commitdiff
proxmox-boot: add grub-install wrapper
authorStoiko Ivanov <s.ivanov@proxmox.com>
Fri, 23 Apr 2021 09:04:49 +0000 (11:04 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 23 Apr 2021 11:28:56 +0000 (13:28 +0200)
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>
bin/Makefile
bin/grub-install-wrapper [new file with mode: 0755]
bin/proxmox-boot-tool
debian/pve-kernel-helper.install
debian/pve-kernel-helper.postrm [new file with mode: 0644]
debian/pve-kernel-helper.preinst [new file with mode: 0644]

index b78fa425905017828cf00adedd96934b99960178..2e1834286a62b38edfbcc5993cc06c4731b69703 100644 (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:
diff --git a/bin/grub-install-wrapper b/bin/grub-install-wrapper
new file mode 100755 (executable)
index 0000000..a61e984
--- /dev/null
@@ -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
+
index 219ea3b60a619651a7913ea6b9f91ed15443759d..079fa266ede6ff38621ea3400f3f1506fb98fb3b 100755 (executable)
@@ -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 \
index f03b05a6ddd64420f611e6d49970d3aa83267172..5f264aa26c26537524e17fe3048d2788a0333b66 100644 (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
diff --git a/debian/pve-kernel-helper.postrm b/debian/pve-kernel-helper.postrm
new file mode 100644 (file)
index 0000000..080598b
--- /dev/null
@@ -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
diff --git a/debian/pve-kernel-helper.preinst b/debian/pve-kernel-helper.preinst
new file mode 100644 (file)
index 0000000..6e21b51
--- /dev/null
@@ -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