HeadlinesBriefing HeadlinesBriefing.com

Run macOS on Linux via XNU Kernel Module

Hacker News •
×

Run macOS userspace on Linux by loading the macOS kernel into it. xnulinux builds XNU, the open-source kernel of macOS, from Apple's published sources and runs it as a loadable kernel module (xnu.ko) inside an unmodified arm64 Linux kernel. 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. Linux lends XNU its memory, timers, files, network and GPU through a small interface module (fki.ko).

With a stock Ubuntu kernel, insmod xnu.ko boots a macOS system disk made by Apple's own installer to the desktop: loginwindow, Window Server, Dock, Finder, Safari and Chrome. One system, two userspaces. Left: a Terminal in the hosted macOS 27.2.1 (sw_vers, the Darwin kernel, launchd, Window Server, Dock and Finder running).

Right: from that macOS, an SSH session into the Linux it runs inside (Ubuntu, Linux 7.0, the xnu and fki modules loaded, and the insmod xnu.ko process the macOS kernel runs in). Straight from the hosted framebuffer, 1280x800. The hosted desktop at the end of a 30-minute stress run, rendered on the CPU (no GPU bridge).

Safari in the hosted macOS: Wikipedia's article on XNU, kernel.org and the Linux repository on GitHub, over the hosted system's network link through Linux, with the GPU bridge on (GPU=auto). macOS processes (launchd, Window Server, Safari...) Linux processes (systemd, sshd, xnu...) XNU (source-built, LINUX64 machine layer, kexts) linux64 host calls xnu.ko (APSL side: loads and runs the kernel collection) fki.ko (GPL side: CPUs, memory, faults, IPIs, files, network, host calls) Linux kernel (stock distro kernel, 4K pages, PAC) CPUs: each hosted CPU is a Linux kernel thread pinned to a Linux CPU. XNU runs on it until it calls the host(idle, I/O, a timer); Linux keeps its own exception vectors, and fki.ko forwards the faults and user exceptions of XNU code to XNU's handlers. Memory: XNU gets one physically contiguous block from Linux (CMA) and manages it with its own pmap; XNU and Linux Devices: kexts in kexts/ give macOS a disk (a file on the Linux side), a display (a framebuffer Linux reads), a keyboard and pointer, an Ethernet link (a Linux network interface), a keystore and a GPU bridge.

GPU: Metal in the hosted macOS runs on gpu/xnu-cpu-metal (metal2vulkan over Vulkan). Vulkan reaches the Linux host's GPU through the DRM bridge (kexts/Xnu Drm -> host call -> gpu/xnu-drm/xnu-drmd -> the Linux render node), using Mesa's Venus driver; without a GPU it falls back to Mesa lavapipe on the CPU. Status Working, on an Apple Silicon Mac running an arm64 Linux VM (krunkit) with 1 to 6 hosted CPUs: macOS 27.2.1 boots to the desktop with auto-login in 31-48 s (an Apple Virtualization macOS VM on the same Mac: 49 s).

Apps open and quit, Spotlight and the file system work; a 30-minute stress run (40 rounds of Safari, Notes, Calculator, Text Edit, System Settings, Spotlight and a disk walk) finishes with no panic and no crash report. Runs as a systemd service: started at boot, stopped cleanly with the VM, restarted after a hosted-kernel panic, each run's log kept in /var/log/xnulinux/. The GPU bridge gives hosted apps the host GPU (Virtio-GPU Venus (Apple M5 Max)) and is enabled by default (GPU=auto) when a Linux render node is present, falling back to CPU rendering (GPU=off) otherwise.

Source: Hacker News · Summarized by HeadlinesBriefing