Frederic Cambus

Home · Archives · Text Mode · GitHub · Twitter · RSS

Booting OpenBSD kernels in EFI mode with QEMU

· OpenBSD

I've been working on stuff involving the EFI framebuffer lately, and needed a way to quickly test kernels without having to reboot my development machine each and every time.

As it turns out, it's possible to achieve using OVMF (Open Virtual Machine Firmware), a BSD licensed UEFI firmware implementation targetted at virtual machines. A prebuilt image can be downloaded here.

We will need to create two drives:

Thankfully, QEMU allows to create virtual drives with FAT filesystems from local directories, and we can easily create an FFS filesystem image using makefs(8).

We will start by creating a directory structure:

mkdir -p bootloader/efi/boot
mkdir -p kernel/etc

We then copy the OpenBSD EFI bootloader:

cp /usr/mdec/BOOTX64.EFI bootloader/efi/boot

Alternatively, an OpenBSD EFI bootloader can be downloaded here.

Then, we need to place the EFI firmware image at the root of our directory, and the OpenBSD kernel we want to boot in the kernel directory.

The directory structure should look as follow:

OVMF.fd
bootloader
bootloader/efi
bootloader/efi/boot
bootloader/efi/boot/BOOTX64.EFI
kernel
kernel/etc
kernel/bsd

We can now create the random.seed file and build the FFS filesystem image:

dd if=/dev/random of=kernel/etc/random.seed bs=512 count=1
makefs -t ffs kernel.img kernel

Finally, let's start QEMU:

qemu-system-x86_64 -s --bios OVMF.fd \
	-drive format=raw,file=fat:rw:bootloader,media=disk \
	-drive format=raw,file=kernel.img,media=disk

And boot our kernel:

boot> boot hd1a:/bsd