#802717 nexpected os-prober when setting up grub in a disk image

Package:
grub-pc
Source:
grub2
Description:
GRand Unified Bootloader, version 2 (PC/BIOS version)
Submitter:
Joey Hess
Date:
2015-10-22 20:12:10 UTC
Severity:
normal
#802717#5
Date:
2015-10-22 20:10:06 UTC
From:
To:
I'm creating a disk image, which I want to be bootable using grub.
Unexpectedly, update-grub runs os-prober which probes the host system
and adds unwanted entries for it.

In the transcript below, /mnt is a loop mounted filesystem from my disk image.
I used kpartx to set up the loop device for the partition inside the disk image.

I bind mount /dev from the host system because this seems to be
necessary to let update-grub figure out that it's being run in a disk
image (by giving it access to /dev/mapper etc).
(Also because vmdebootstrap does it..)

root@darkstar:/mnt>mount --bind /dev dev
root@darkstar:/mnt>chroot .
root@darkstar:/# mount -t sysfs sys /sys
root@darkstar:/# mount -t proc proc /proc
root@darkstar:/# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.2.0-1-amd64
Found initrd image: /boot/initrd.img-4.2.0-1-amd64
Found Windows 8 (loader) on /dev/sda2
Found Debian GNU/Linux (stretch/sid) on /dev/sda3
done
root@darkstar:/mnt>grub-install /dev/loop2
Installing for i386-pc platform.
Installation finished. No error reported.

The result is, grub boots fine using this disk image, but the menu has
unexpected entries, from os-prober, for the system where it was built.

I think the only reason that vmdebootstrap images don't experience this
problem is because it doesn't install os-prober by default. However, I'd
like to include os-prober on my image, if possible.

Could the os-prober hook perhaps notice when the root is a loopback
image, and avoid probing the host system?

Temporary workaround: chmod -x /etc/grub.d/30_os-prober