From 09da74e1545d614e5f3daa38710e03a02eef7a35 Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Wed, 3 Feb 2021 14:31:50 +0000 Subject: [PATCH] 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 096a00f40459187719840ccad99e86c7ade2ec12) --- live-build/functions | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/live-build/functions b/live-build/functions index fa4bfd10..b8f91e4f 100644 --- a/live-build/functions +++ b/live-build/functions @@ -355,7 +355,9 @@ undivert_grub() { --divert /etc/grub.d/30_os-prober.dpkg-divert \ --rename /etc/grub.d/30_os-prober - rm "$CHROOT_ROOT"/usr/bin/systemd-detect-virt + 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 }