functions: stop removing systemd-detect-virt unconditionally in undivert_grub

One can call divert_grub; replace_kernel; undivert_grub. And
replace_kernel will call into force_boot_without_initramfs, which
under certain conditions can call divert_grub &
undivert_grub. Resulting in undivert_grub called twice in a row.

When undivert_grub is called twice in a row it wipes
systemd-detect-virt binary from disk, as the rm call is unguarded to
check that there is something to divert if systemd package is
installed. And if the systemd package is not installed, it does not
check that systemd-detect-virt file is in-fact what divert_grub has
created.

Add a guard to check that systemd-detect-virt is the placeholder one,
before removing it.

LP: #1902260
(cherry picked from commit 096a00f404)
fix-kassel
Dimitri John Ledkov 4 years ago
parent d447d167dc
commit 09da74e154
No known key found for this signature in database
GPG Key ID: 9B8EC849D5EF70ED

@ -355,7 +355,9 @@ undivert_grub() {
--divert /etc/grub.d/30_os-prober.dpkg-divert \
--rename /etc/grub.d/30_os-prober
if grep -q "^exit 1$" "$CHROOT_ROOT"/usr/bin/systemd-detect-virt; then
rm "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
fi
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
--rename /usr/bin/systemd-detect-virt
}

Loading…
Cancel
Save