From a5e27120c0260ba8189ab9526cdd306d9de43552 Mon Sep 17 00:00:00 2001 From: Steve Langasek Date: Wed, 4 Oct 2017 22:33:41 -0700 Subject: [PATCH] Factor out grub-related diversions and use them consistently, so we don't end up with wrong os-probe output in our grub.cfg. --- debian/changelog | 7 +++++ live-build/functions | 29 +++++++++++++++++++ .../ubuntu-cpc/hooks/032-disk-image.binary | 2 ++ .../hooks/033-disk-image-uefi.binary | 4 +-- .../hooks/034-disk-image-ppc64el.binary | 4 +-- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 894485ae..70092110 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +livecd-rootfs (2.466) UNRELEASED; urgency=medium + + * Factor out grub-related diversions and use them consistently, so we + don't end up with wrong os-probe output in our grub.cfg. + + -- Steve Langasek Wed, 04 Oct 2017 22:31:40 -0700 + livecd-rootfs (2.465) artful; urgency=medium * Skip installation of kernel headers for all minimal images diff --git a/live-build/functions b/live-build/functions index 7fe52f30..c421d2d7 100644 --- a/live-build/functions +++ b/live-build/functions @@ -283,3 +283,32 @@ replace_grub_root_with_label() { sed -i -e "s,root=[^ ]\+,root=LABEL=${fs_label}," \ "$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 bb8bfc11..006f289b 100755 --- a/live-build/ubuntu-cpc/hooks/032-disk-image.binary +++ b/live-build/ubuntu-cpc/hooks/032-disk-image.binary @@ -125,7 +125,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 932484ea..023228ae 100755 --- a/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary +++ b/live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary @@ -110,10 +110,10 @@ install_grub() { 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 62a02094..649843e4 100755 --- a/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary +++ b/live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary @@ -52,10 +52,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