In my previous blog post I mentioned that the tooling was mostly interested in using UEFI based images only and hence did not consider supporting legacy BIOS based boot. I received a mail from Noah Meyerhans, member of Debian Cloud team about an open merge request adding mkosi build support for Debian Cloud Images. The merge request does not completely replace entire image build process using mkosi, it only replaces rootfs build with mkosi. The reason which I grasped from the MR on why not full replace were
- mkosi does not support bootloader installation for all architectures we need.
- mkosi uses systemd-repart to partition and populate disk images, but it does not support our partition layouts.
- mkosi does not support our /boot hierarchy (e.g. the UEFI system partition is mounted on /efi).
- mkosi generates GRUB configuration itself, and it doesn't match what grub-mkconfig produces.
I got curious about these reasons and dug into them with agy to see if they were actually blockers for mkosi. Here is what I found:
Partition Layout with Slots
Debian Cloud Images use slot-based partitioning where p1 is always the root partition, while p14 and p15 hold the BIOS boot and EFI partitions. The main reason this exists is backwards compatibility: if existing users or scripts hardcode /dev/sda1 or /dev/vda1 as root, moving root to p2 or p3 would break them. Technically, neither growpart/growfs nor modern cloud platforms require root to be p1 — as long as root is physically the last partition on disk (e.g. p3 after boot and EFI), it grows just fine. I'm still open to hearing if there is another reason this layout must be kept.
That said, it is true that systemd-repart does not support arbitrary out-of-order slot numbers (p14/p15 before p1), since it follows the Discoverable Partitions Specification and assigns partitions sequentially.
Bootloader Installation for All Architectures
Debian supports several architectures beyond x86_64 and arm64 where UEFI is not the standard, notably ppc64el and s390x. However, it is not quite true that mkosi cannot install bootloaders for them. With a couple of hooks and systemd-repart rules, we got both working cleanly.
ppc64el
OpenPOWER firmware (SLOF) looks for a PReP (PowerPC Reference Platform) GPT partition with no filesystem on it, and loads a raw ELF binary directly from the start of that partition.
How we solved it:
- mkosi.postinst.d/40-ppc64el-grub.sh runs grub-mkimage inside the target rootfs (via qemu-user-static) to build core.elf with the btrfs and part_gpt modules baked in, along with an embedded load.cfg pointing to /boot/grub/grub.cfg on the Btrfs @ default subvolume.
- core.elf is padded to a 512-byte boundary.
- systemd-repart creates an 8 MiB PReP partition and uses CopyBlocks= to write core.elf raw into that partition.
(Separately, for the ``x86_64`` ``bios`` profile, since my host uses ``systemd-boot`` and has no GRUB packages installed, *mkosi's ToolsTree=yes feature pulls grub-pc-bin into an isolated build sandbox without touching the host.)*
s390x
On s390x, IBM Z firmware (IPL - Initial Program Load) has no filesystem drivers at all and cannot use GRUB or an ELF boot partition. Instead, the firmware reads a tiny IPL record from sector 0 of the disk, which points to the raw physical disk sectors of /boot/bootmap. That file in turn lists the raw sector ranges for the kernel, initrd, and kernel command line so the firmware can load them straight into memory. This entire block map is built by zipl from the s390-tools package.
Here is how we wired it up in mkosi:
- A small wrapper script /usr/local/sbin/zipl-install is included in the s390x profile to mount /boot, run zipl -V -c /etc/zipl.conf, and power off.
- mkosi.postinst.d/50-s390x-zipl.sh sets up /boot/vmlinuz and /boot/initrd.img symlinks and writes /etc/zipl.conf with the kernel, initrd, and command-line parameters.
- Because zipl cannot map physical blocks on Btrfs (due to CoW, subvolumes, and compression), systemd-repart creates a small ext4 partition for /boot (p1) while keeping / on Btrfs (p2).
- Finally, a mkosi.postoutput script boots the generated image.raw once in qemu-system-s390x with init=/usr/local/sbin/zipl-install. That runs zipl on the live disk, writes /boot/bootmap and the sector 0 IPL record, and exits cleanly.
It took me a while to wrap my head around this whole setup, but agy was patient enough to answer all my questions ;-).
As a bonus, we also maintained seamless kernel upgrades on both ppc64el and s390x (matching standard debian-cloud-images behaviour): link_in_boot = yes in /etc/kernel-img.conf keeps /boot/vmlinux / /boot/vmlinuz and /boot/initrd.img symlinks updated on apt upgrade, ppc64el's grub.cfg boots via those symlinks, and s390x's /etc/zipl.conf lets Debian's zipl kernel hook refresh /boot/bootmap automatically.
/boot Hierarchy and GRUB Config
Yes, mkosi defaults to /efi instead of /boot/efi, and upstream grub-install only auto-detects /boot/efi unless --efi-directory is explicitly passed. Since Debian's grub2 maintainer script invokes grub-install without --efi-directory, grub-efi-* packages expect /boot/efi. Switching UEFI images to systemd-boot + UKIs avoids this entirely.
As for the grub-mkconfig mismatch, I didn't need to deal with it either: UEFI images use systemd-boot + UKIs instead of GRUB, the x86_64 hybrid bios profile doesn't rely on /etc/default/grub.d/*.cfg drop-ins (so mkosi's built-in BiosBootloader=grub works fine), ppc64el builds its own grub.cfg and core.elf via grub-mkimage in our postinst hook, and s390x uses zipl so GRUB is not involved at all.
Conclusion
The goal of this experiment was to see if all of these cases could be handled cleanly using mkosi itself as the disk image builder. Aside from keeping the legacy p1/p14/p15 slot numbering, mkosi handled every case — including a hybrid UEFI + legacy BIOS profile for x86_64 — and every image booted cleanly under qemu-system-*.
I've pushed all the changes to the repository. I'm happy to hear about anything I missed or got wrong, and I will continue maintaining debian-cloud-mkosi as a standalone project alongside the official Debian Cloud images.