grub-install has a --root-directory parameter. It's clearly designed so you can have an instance of Linux running to which you have mounted something you wish to update into say, /mnt
The documentation shows this.
However, grub-mkconfig invokes grub-probe which is hard coded to look at the host.
Therefore grub-mkconfig also needs a --root-directory parameter
There's a DIFF for 2.02 beta3, which Alpine Linux uses at the moment
Alpinevc:~#
diff /usr/sbin/grub-mkconfig /usr/sbin/grub-mkconfig2
---
/usr/sbin/grub-mkconfig
+++
/usr/sbin/grub-mkconfig2
@@
-19,13 +19,13 @@
prefix="/usr"
exec_prefix="/usr"
-datarootdir="/usr/share"
+datarootdir="/mnt/usr/share"
prefix="/usr"
exec_prefix="/usr"
sbindir="${exec_prefix}/sbin"
bindir="${exec_prefix}/bin"
-sysconfdir="/etc"
+sysconfdir="/mnt/etc"
PACKAGE_NAME=GRUB
PACKAGE_VERSION=2.02~beta3
host_os=linux-musl
@@
-132,11 +132,11 @@
fi
#
Device containing our userland. Typically used for root= parameter.
-GRUB_DEVICE="`${grub_probe}
--target=device /`"
+GRUB_DEVICE="`${grub_probe}
--target=device /mnt`"
GRUB_DEVICE_UUID="`${grub_probe}
--device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" ||
true
#
Device containing our /boot partition. Usually the same as
GRUB_DEVICE.
-GRUB_DEVICE_BOOT="`${grub_probe}
--target=device /boot`"
+GRUB_DEVICE_BOOT="`${grub_probe}
--target=device /mnt/boot`"
GRUB_DEVICE_BOOT_UUID="`${grub_probe}
--device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`"
|| true
#
Filesystem for the device containing our userland. Used for stuff
like