Skip to content

Booting from LibreToy into Images

Why GRUB

The menu is a GRUB configuration, and that is the whole interface: everything that can be expressed as a GRUB menu entry can be offered. The choice of mechanism is therefore open. We could start the kernel directly, generate an entry per distribution, or fall back to the trick Ventoy uses.

Two principles decide what we actually implement. The mechanism should be as simple as possible and still robust, and it should cover many standard images with a small amount of code. A special case deserves its own code only when it is common.

Of the solutions we evaluated, grub-iso-multiboot comes closest to that.

flowchart LR
  libretoy["LibreToy (GRUB)"] --> a["ISO with GRUB<br/>loopback.cfg"]
  libretoy --> b["ISO with isolinux"]
  libretoy --> c["any other target<br/>GRUB can start"]

grub-iso-multiboot

An ISO is a filesystem image of an optical disc: one file that contains a complete directory tree — the distribution's kernel and the configuration that starts it. It stays a single file on the stick; nothing is unpacked.

At boot, grub-iso-multiboot looks for *.iso files in the root of every partition and in /iso, and adds a menu entry for each one. It supports two kinds of ISO.

  • Loopback. Many ISOs ship a GRUB configuration meant for exactly this case, a file called loopback.cfg. GRUB mounts the ISO as a loopback device — a file used as if it were a disk — and starts that configuration, which then boots the ISO's kernel. When the file exists, this is the preferred path: the distribution knows best how to start itself.
  • isolinux. Other ISOs use isolinux, a different bootloader. GRUB can read isolinux's configuration and translate its menu entries into GRUB entries, so the same menu appears, this time built by GRUB.

If an ISO has neither, it gets no entry and is skipped.

Handing Kernel Arguments to the ISO

Starting the kernel is only half of it. The kernel has to find the ISO again, because that is where its root filesystem is — and the ISO is not on a partition of its own: it is a file on the stick, in the root of a partition or in /iso. Each distribution expects a different kernel argument for this: findiso=, iso-scan/filename=, isofrom=, img_dev= and several more.

grub-iso-multiboot collects them: it appends one line per family to the GRUB variable $linux_extra and passes that variable to the ISO's bootloader. All of them go to every ISO; the kernel picks the one it understands.

GRUB's own configurations expand the variable. isolinux knows nothing about it, so GRUB has to write it into the menu entry it generates from the isolinux configuration. grub-iso-multiboot ships a one-line patch that makes GRUB print $linux_extra into the generated linux line; we apply it to both GRUB variants, so BIOS and EFI behave the same.

What LibreToy Adds

The script itself is vendored, not rewritten: the lines we changed inside it are marked libretoy:. Around it, we add three things.

  • A reproducible build. GRUB with the patch and the configuration come out of one build, so the same input gives the same bytes.
  • Configuration instead of editing. The argument list above is fixed in upstream's script. Here it is reachable through Nix module options (libretoy.image.bootloader.autoisoExtra), so an image can add its own arguments without forking the script.
  • Work on images upstream cannot boot. We pin upstream at a known commit, so its behaviour only changes when we decide to update it. Images that start through something else — systemd-boot is the case we have in mind — need new code, and that code lives here.