Minimal GRUB Configuration To Boot A Multiboot2 Kernel With Boot Modules

Published by Philipp Schuster on

TLDR: for Multiboot2 you use module2 and for Multiboot1 module in GRUB config files.

One of my projects of the last months was to build a prototype setup for kernels written in Rust. The kernel is Multiboot2-compliant and boots on x86_64 with UEFI as firmware. To test everything, I create a standalone GRUB in a directory, which contains the kernel (an 64-bit ELF) and a minimal grub.conf. The “standalone GRUB” is a regular EFI-application, which can be booted by every UEFI implementation. You can find out how to create a standalone GRUB and what the (memdisk) is in my previous blog post.

It’s no rocket science to let GRUB provide boot modules but it is extremely bad documented, as large parts of GRUB. 🙁 The official documentation doesn’t mention it at all. A boot module is a BLOB in memory and can for example be an initial ram disk with essential drivers.

In my example, I create a GRUB standalone application with a minimal configuration and two files packed into the internal (memdisk). One is the Multiboot2-kernel and one an example boot module.

grub-mkstandalone \ 
  -O x86_64-efi \
  -o ".volume-out/EFI/BOOT/BOOTX64.EFI" \
  "/boot/grub/grub.cfg=./grub.cfg" \
  "/boot/multiboot2-binary.elf=./multiboot2-kernel.elf" \

The minimal GRUB configuration looks like this:

set timeout=0
set default=0
# apparently not required, but useful if you are in the GRUB shell
# set root=(memdisk)
# set debug=all

menuentry "Phips Multiboot2-compliant Rust Binary" {
    multiboot2 /boot/multiboot2-binary.elf

    # Load a module for Multiboot2 kernels. A module is a BLOB and can for example be some
    # initial ramdisk with essential drivers
    module2    /foobar/some_boot_module --test cmdline-option

    # not required, unless you type these lines on the GRUB shell
    # boot

I executed everything inside QEMU and printed out the MBI. Down below in the penultimate line you can see a screenshot, where the module was loaded and its command line string.

Screenshot from QEMU. Boot module is available and cmdline-string too.

Philipp Schuster

Hi, I'm Philipp and interested in Computer Science. I especially like low level development, making ugly things nice, and de-mystify "low level magic".


Leave a Reply

Your email address will not be published. Required fields are marked *