LockerGnomeTech news and nostalgia for today's technology professionals
Subscribe

Search

Hacks & Builds

xnulinux Loads the macOS Kernel Into Linux With insmod and Boots the Mac Desktop

Heyang Zhou's project builds on two earlier hobby kernels, boots in about the time of a stock Mac VM, and still asks you to bring your own copy of macOS.

A man in a work apron sits in profile at a laptop showing a tidy desktop and dock, with a larger open computer board nested beneath it.
Illustration: LockerGnome

The screenshot that sells the project is a split screen. On the left, a Terminal runs sw_vers and reports macOS 27.2.1. On the right, an SSH session leaves that Mac and lands in the Ubuntu machine it’s running inside, where the process list includes insmod xnu.ko. The Mac’s kernel is sitting in Linux’s process table like a browser tab someone forgot to close.

Heyang Zhou’s xnulinux builds XNU, the open-source kernel of macOS, from Apple’s published sources and loads it into an unmodified arm64 Linux kernel as a module. “The hosted XNU drives the CPU and MMU directly, so macOS processes run natively next to Linux processes on the same CPUs, with no hypervisor between them,” the README says. Loginwindow, WindowServer, the Dock, Finder, Safari and Chrome all come up on a stock Ubuntu kernel.

Each hosted CPU is a Linux kernel thread pinned to a Linux CPU. XNU runs on it until it needs the outside world (idle, I/O, a timer), then calls the host. Linux keeps its own exception vectors, and a second module, fki.ko, forwards XNU’s faults and user exceptions to XNU’s handlers. Memory arrives as one physically contiguous block from Linux, which XNU manages with its own pmap. It’s a houseguest that asks for the whole spare room and then rearranges the furniture.

The rest of the hardware is borrowed the same way. macOS’s disk is a file on the Linux side, its display is a framebuffer Linux reads, and its Ethernet is a Linux network interface. One README screenshot shows Safari inside the hosted Mac loading Wikipedia’s article on XNU over that link, which is a kernel reading about itself through a network card it doesn’t own.

Graphics take a longer road. Metal in the hosted macOS runs on a metal2vulkan layer over Vulkan, which reaches the Linux host’s GPU through a DRM bridge built on Mesa’s Venus driver. The status notes name the GPU hosted apps see on an M5 Max Mac as Virtio-GPU Venus (Apple M5 Max). With no supported bridge, rendering falls back to Mesa lavapipe on the CPU.

The numbers are better than a stunt needs. In an arm64 Linux VM on an Apple Silicon Mac, running under krunkit with one to six hosted CPUs, macOS 27.2.1 boots to the desktop with auto-login in 31 to 48 seconds. Apple’s own Virtualization VM on the same Mac takes 49. A 30-minute stress run, 40 rounds of Safari, Notes, Calculator, TextEdit, System Settings, Spotlight and a disk walk, finished with no panic and no crash report. It runs as a systemd service that restarts after a hosted-kernel panic and keeps each run’s log in /var/log/xnulinux/.

Then there’s the bare-metal run. On an NVIDIA DGX Spark running Ubuntu 24.04.5, the full desktop boots with 4 CPUs and 8 GiB of RAM reserved for XNU, reachable over macOS Screen Sharing and SSH. About This Mac there reports Chip: Unknown and hw.cpufamily: 0, so the Mac has no idea what it’s running on (an identity crisis with a Dock). It renders on the CPU because the bridge only forwards virtio-gpu calls today, and hardware GPU pass-through on the Spark’s GB10 still waits on a new DRM bridge backend.

Expect the GPU bridge to decide where this goes next. It forwards only virtio-gpu today, so any Linux box without that path renders the Mac desktop on its CPUs. A backend for real GPUs like the Spark’s is the line between a curiosity and something you’d leave running.

Watch the page-size gap too. XNU’s 4K pages against the 16K pages of native Macs are the README’s stated reason memory runs slower than in a native VM, and anything that closes it should show up in those 31-to-48-second boot times first. And watch Apple’s source drops. The whole trick rests on XNU being published, so each macOS release tells you what the next version costs the project in patches.

A homelab that lists a Mac guest beside its containers is a short step from here. The licensing split is the other tell: it was drawn so both sides can ship without touching each other’s code, which suits a project meant to be forked. Sixty-five people already have.

Linux rented the Mac a room. It brought its own Dock.

More Hacks & Builds

Every Hacks & Builds story →