Subject: [bug#41350] [PATCH 0/3] Use native qemu to build vm-image.

From: Mathieu Othacehe <[email-masked]>
Date: Wed, 20 May 2020 16:03:41 +0200

Hey,

> The conclusion here is that, I think that we very few adaptations to
> your branch, we should be able to produce Hurd ISO images or Hurd EFI
> compatible disk-images. Maybe it would be a first step.
>
> Then, we could find a way to create "MBR compatible" Hurd and Linux
> disk-images in (gnu system image).

Ok, I made further progress. Turns out the Hurd EFI solution was a
dead-end, because I have a "no console will be available to os" message
in Qemu, instead of Hurd console output. I don't feel like debugging
this.

So, back to the MBR solution. I had another look to what OpenWrt is
doing. They found a really nice work-around! As I stated, we cannot use
"grub-install", but this command is in reality a wrapper around
"grub-mkimage" and "grub-bios-setup".

--8<---------------cut here---------------start------------->8---
#######################################
#     #            #                  #
# MBR # MBR-GAP    # FIRST PARTITION  #
#     #            #                  #
#######################################
--8<---------------cut here---------------end--------------->8---

grub-mkimage generates a Grub image, small enough so that it can fit in
the MBR-GAP (the space between the MBR and the first partition).

It cannot contain all Grub modules, but that's not an issue, because
Grub will be able to find missing modules from the first partition when
started.

They also patched grub-bios-setup[1] so that it can work on a raw
disk-image, and install the previously generated "grub.img".

So with the following commands:

--8<---------------cut here---------------start------------->8---
grub-mkimage -O i386-pc -o core.img  biosdisk part_msdos ext2
echo "(hd0) /tmp/my-disk-image" > device.map
grub-bios-setup -m device.map -r "hd0,msdos1" -d tmp /tmp/qemu-image2
--8<---------------cut here---------------end--------------->8---

I'm able to make a Guix system image bootable, without root
permissions. It then starts the Hurd kernel and crashes, but that's
another story :p

So, if it's ok for you, I can integrate this stuff cleanly, and we won't
need the vm-image stuff anymore.

WDYT?

Thanks,

Mathieu

[1]:
https://github.com/openwrt/openwrt/blob/master/package/boot/grub2/patches/100-grub_setup_root.patch