diff --git a/debian/changelog b/debian/changelog index 032064a1..4dbdcd37 100644 --- a/debian/changelog +++ b/debian/changelog @@ -32,6 +32,8 @@ livecd-rootfs (2.408.19) xenial; urgency=medium - If we're using SUBPROJECT=minimized, and tzdata is not installed, remove files that have been left behind. This is a workaround for a bug that should be fixed in tzdata. + * Factor out grub-related diversions and use them consistently, so we + don't end up with wrong os-probe output in our grub.cfg. [ Balint Reczey ] * Mount using --make-rslave to ensure safe unmounts for rbind mounts diff --git a/live-build/ubuntu-cpc/functions b/live-build/ubuntu-cpc/functions index 6e2cd034..897fe905 100644 --- a/live-build/ubuntu-cpc/functions +++ b/live-build/ubuntu-cpc/functions @@ -281,3 +281,32 @@ replace_grub_root_with_label() { sed -i -e "s,root=[^ ]\+,root=LABEL=cloudimg-rootfs," \ "$CHROOT_ROOT/boot/grub/grub.cfg" } + + +# When running update-grub in a chroot on a build host, we don't want it to +# probe for disks or probe for other installed OSes. Extract common +# diversion wrappers, so this isn't reinvented differently for each image. +divert_grub() { + CHROOT_ROOT="$1" + + chroot "$CHROOT_ROOT" dpkg-divert --local \ + --rename /usr/sbin/grub-probe + chroot "$CHROOT_ROOT" touch /usr/sbin/grub-probe + chroot "$CHROOT_ROOT" chmod +x /usr/sbin/grub-probe + + chroot "$CHROOT_ROOT" dpkg-divert --local \ + --divert /etc/grub.d/30_os-prober.dpkg-divert \ + --rename /etc/grub.d/30_os-prober +} + +undivert_grub() { + CHROOT_ROOT="$1" + + chroot "$CHROOT_ROOT" rm /usr/sbin/grub-probe + chroot "$CHROOT_ROOT" dpkg-divert --remove --local \ + --rename /usr/sbin/grub-probe + + chroot "$CHROOT_ROOT" dpkg-divert --remove --local \ + --divert /etc/grub.d/30_os-prober.dpkg-divert \ + --rename /etc/grub.d/30_os-prober +} diff --git a/live-build/ubuntu-cpc/hooks/032-disk-image.binary b/live-build/ubuntu-cpc/hooks/032-disk-image.binary index 7cde62f6..85fb1281 100755 --- a/live-build/ubuntu-cpc/hooks/032-disk-image.binary +++ b/live-build/ubuntu-cpc/hooks/032-disk-image.binary @@ -120,7 +120,9 @@ if [ "${should_install_grub}" -eq 1 ]; then echo "partuuid found for root device; forcing it in Grub" mkdir -p mountpoint/etc/default/grub.d echo "GRUB_FORCE_PARTUUID=$partuuid" >> mountpoint/etc/default/grub.d/40-force-partuuid + divert_grub mountpoint chroot mountpoint update-grub + undivert_grub mountpoint fi fi diff --git a/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary b/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary index 2e98e356..b303e6cd 100755 --- a/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary +++ b/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary @@ -119,10 +119,10 @@ EOF chroot mountpoint grub-install --target=i386-pc "${loop_device}" fi - chroot mountpoint dpkg-divert --local --rename /etc/grub.d/30_os-prober + divert_grub mountpoint chroot mountpoint update-grub replace_grub_root_with_label mountpoint - chroot mountpoint dpkg-divert --remove --local --rename /etc/grub.d/30_os-prober + undivert_grub mountpoint chroot mountpoint apt-get -y clean diff --git a/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary b/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary index 884626e8..7891f639 100755 --- a/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary +++ b/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary @@ -50,10 +50,10 @@ EOF --boot-directory=/boot \ --target=powerpc-ieee1275 - chroot mountpoint dpkg-divert --local --rename /etc/grub.d/30_os-prober + divert_grub mountpoint chroot mountpoint update-grub replace_grub_root_with_label mountpoint - chroot mountpoint dpkg-divert --remove --local --rename /etc/grub.d/30_os-prober + undivert_grub mountpoint umount_partition mountpoint rmdir mountpoint