What you need to know to boot your kernel

It's important to notice how Virtualization.framework seems to be a work in progress framework. I thank the Apple team to have prioritized the Virtualization features in macOS.

This post will be a sum up of personal findings I found while playing with Virtualization.framework and a custom EFI Kernel. The thread will be updated as soon as I find any particular information about building a custom kernel and trying to load in Virtualization.framework. Naturally, it's not endorsed by anyone.

Before starting...

Before a list of "what to do", it's important to say that there are few details about how Virtualization.framework works under the hood. You might be a little demotivated, and creating a custom kernel for aarch64/x86_64 is very hard. Give a look for resources and do not loose your head!

Custom Kernel

To boot a custom kernel for Virtualization.framework, you need:

  • UEFI compliant bootloader: pick the one you prefer. Among the popular options, there is GRUB, Limine, BootBoot. It's fundamental to be sure that bootloader is for UEFI and can load your kernel. You might want to try to run qemu for the architecture you're looking for.

  • VirtIO support. This probably is a little bit difficult task. The devices (such as network, graphics, sound) can be retrieved using the PCI bus. Look at Intel or ARM documentation to specifically know how to write to I/O ports (e.g. ARM has its devices memory mapped, while on Intel you need to dig a little bit). Another note is about graphics. Some bootloader such as GRUB or Limine supports the framebuffer protocol and can ask directly to UEFI where the screen device is (returning an address that you can use to write pixel.)

The VirtIO support is based on PCI drivers. I can suggest at first to load an hello world kernel, building the fundamental parts of OS for memory, and then start to implement PCI drivers. Once you did that, you can start to think about VirtIO and its queue.

How to run it

To boot the custom kernel, usually developers prefer to deploy it as a valid ISO image that contains the correct bootloader and kernel, or as a RAW image of the disk. It's important to notice that you need to build a VM machine with VZEFIBootLoader that creates a UEFI bootloader.

RAW image of the disk MUST BE a valid APFS image. ISO image should be prepared with xorriso or anything similar: you have to be sure that the ISO respects the DOS format and is bootable. TL;DR: any ISO uefi-compatible should be runnable in Virtualization.framework. In case of any issues, or questions you can post a question in this forum.

Resources include:

  • the documentation for Virtualization.framework
  • ARM/Intel assembly manuals
Post not yet marked as solved Up vote post of seekbytes Down vote post of seekbytes
511 views