From 277ae5cf056e447082b61a28bb5558bccef96487 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 7197a152..12827c42 100644 --- a/live-build/functions +++ b/live-build/functions @@ -379,7 +379,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 }