XNU Linux: Full OS X GUI Userspace on Linux

Hacker News by 7 min read 510x views
XNU Linux: Full OS X GUI Userspace on Linux

Share Post

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) inner 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 identical CPUs, alongside no hypervisor between them. Linux lends XNU its memory, timers, files, network and GPU through a small interface component (fki.ko).

With a inventory Ubuntu kernel, insmod xnu.ko boots a macOS 27 scheme disk made by Apple's own installer to the desktop: loginwindow, WindowServer, Dock, Finder, Safari and Chrome.

macOS and Linux userspace flank by side

One system, two userspaces. Left: a Terminal in the hosted macOS 27.2.1 (sw_vers, the Darwin kernel, launchd, WindowServer, Dock and Finder running). Right: from that macOS, an SSH meeting into the Linux it runs inner (Ubuntu, Linux 7.0, the xnu and fki modules loaded, and the insmod xnu.ko procedure the macOS kernel runs in). Straight from the hosted framebuffer, 1280×800.

The hosted macOS desktop

The hosted desktop at the end of a 30-minute emphasis run, rendered on the CPU (no GPU bridge).

Safari in the hosted macOS: Wikipedia's part on XNU, kernel.org and the Linux repository on GitHub, complete the hosted system's network nexus through Linux, alongside the GPU extend on (GPU=auto).

 macOS processes (launchd, WindowServer, Safari...) Linux processes (systemd, sshd, xnudrmd...) ────────────────────────────────────────────────── ──────────────────────────────────────────── XNU (source-built, LINUX64 device layer, kexts) │ ↕ linux64 presenter calls (xnu-patches/include/linux64_abi.h) xnu.ko (APSL side: loads and runs the kernel collection) ↕ FKI, the abroad kernel interface (fki_*) fki.ko (GPL side: CPUs, memory, faults, IPIs, files, network, presenter calls) Linux kernel (stock distro kernel, 4K pages, PAC) 
  • CPUs: all 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 elimination vectors, and fki.ko forwards the faults and person exceptions of XNU code to XNU's handlers.
  • Memory: XNU gets one physically adjacent obstacle from Linux (CMA) and manages it alongside its own pmap; XNU and Linux share the person fractional of the location area layout (4K pages).
  • Devices: kexts in kexts/ provision macOS a disk (a document on the Linux side), a display (a framebuffer Linux reads), a keyboard and pointer, an Ethernet nexus (a Linux network interface), a keystore and a GPU bridge.
  • GPU: Metal in the hosted macOS runs on gpu/xnu-cpu-metal (metal2vulkan complete Vulkan). Vulkan reaches the Linux host's GPU through the DRM extend (kexts/XnuDrm → presenter call → gpu/xnu-drm/xnudrmd → the Linux render node), using Mesa's Venus driver; without a GPU it falls rear to Mesa lavapipe on the CPU.

Working, on an Apple Silicon Mac operating an arm64 Linux VM (krunkit) alongside 1 to 6 hosted CPUs:

  • macOS 27.2.1 boots to the desktop alongside auto-login in 31–48 s (an Apple Virtualization macOS VM on the identical Mac: 49 s).
  • Apps open and quit, Spotlight and the document scheme work; a 30-minute emphasis run (40 rounds of Safari, Notes, Calculator, TextEdit, System Settings, Spotlight and a disk walk) finishes alongside no panic and no collision report.
  • Runs as a systemd service: started at boot, stopped cleanly alongside the VM, restarted following a hosted-kernel panic, each run's log kept in /var/log/xnulinux/.
  • The GPU extend gives hosted apps the presenter GPU (Virtio-GPU Venus (Apple M5 Max)) and is enabled by default (GPU=auto) whenever a Linux render node is present, falling rear to CPU rendering (GPU=off) otherwise.

What is motionless a stopgap is listed in docs/production.md. Notably: the OS cryptex is merged into the scheme volume, AMFI is patched and SIP relaxed, and recollection admission is slower than a native VM (4K pages vs 16K).

  • An arm64 Linux presenter alongside PAC (Apple Silicon M1 or afterward in a VM: krunkit for GPU access, or tart), 4K pages, ~24 GB of RAM (8 GB of it reserved for the hosted kernel).
  • A Mac alongside Xcode to create the scheme disk and build the GPU parts.
  • A macOS 27 facility (an Apple Virtualization VM disk) of your own. No Apple binaries are in this repository or distributed by it: the kexts Apple ships, the macOS scheme disk and its rely cache arrive from your own installation.
  1. scripts/vm-xnu-build.sh (in the Linux VM, once): sets up the macOS-DroidVM Linux toolchain and builds XNU (xnu-12377.121.6) natively on arm64.
  2. scripts/vm-xnu-rebuild.sh: applies xnu-patches/, builds the kernel and kexts/, and links the kernel collection with Apple's kexts from your macOS installation.
  3. scripts/mk-macvm-disk.sh (on the Mac): turns a macOS VM disk made by Apple's installer into the hosted system's disk and copies it into the Linux VM.
  4. scripts/xnulinux-boot.sh (in the Linux VM): builds fki.ko and xnu.ko against the operating kernel, brings up the network (and the GPU extend whenever there is a render node) and boots the hosted system. Its console is scripts/xnu-console.sh, its display tools/hosted/fb2png.py, input tools/hosted/xnu-input.py.
  5. scripts/install-service.sh (in the Linux VM): runs it as xnulinux.service, configured in /etc/xnulinux.conf (CPUs, memory, disk, GPU). On the Mac, scripts/install-krun-agent.sh keeps the VM itself running.
  6. GPU (optional, on the Mac): gpu/venus/build-darwin.sh builds the hosted Vulkan driver, gpu/xnu-cpu-metal/ the Metal plugin (see its README).

Repository layout and licenses

The Linux flank and the XNU flank are kept distinct by licence and encounter lone at FKI. Every origin document carries an SPDX-License-Identifier; the licence texts are in LICENSES/.

Path License What
fki-ko/, linux/ GPL-2.0-only FKI: the out-of-tree component for inventory kernels, and the identical as an in-tree driver
xnu-ko/ APSL-2.0 xnu.ko: loads XNU's kernel gathering and runs it; calls Linux lone through fki_*
xnu-patches/ APSL-2.0 The LINUX64 device tier and the another changes to XNU's sources, and their shared headers
kexts/ APSL-2.0 The hosted system's kexts (CPU, disk, keystore, Metal accelerator, DRM bridge)
kexts/XnuDisplay/, kexts/XnuEthernet/, kexts/XnuInput/ BSD-2-Clause-Patent Derived from macOS-DroidVM's kexts
gpu/xnu-cpu-metal/ GPL-2.0-or-later The Metal plugin complete metal2vulkan (GPL-2.0-or-later); XnuCpuMetalShim.h is BSD-2-Clause-Patent (from AdrenoMetal)
gpu/xnu-drm/ GPL-2.0-only, MIT xnudrmd (the Linux end of the DRM bridge) is GPL; the protocol header and darwin/ (built into Mesa) are MIT
gpu/venus/ GPL-2.0-only; patches MIT Build scripts and tests; the patches to Mesa and virglrenderer are under their upstream licence (MIT)
gpu/xnu-cpu-metal/patches/ upstream's Patches to Mesa (MIT) and metal2vulkan (GPL-2.0-or-later)
scripts/, tools/, tests/, docs/ GPL-2.0-only Build, disk, boot, debugging and test tools; documentation

xnu.ko is on the XNU flank of the line: it runs XNU's code in its own location space, so it is APSL-2.0 akin XNU, and Linux reports it as a non-GPL component (MODULE_LICENSE("Proprietary"), which taints the kernel as ZFS does). It must not include Linux headers beyond the component ABI, call Linux functions another than fki_*, or transport Linux code. Upstream code (XNU, macOS-DroidVM's toolchain, Mesa, metal2vulkan, the Vulkan loader, LLVM) is fetched at pinned revisions and patched at build time; it is never committed.

macOS, Metal and XNU are trademarks of Apple Inc. This project is not affiliated alongside or endorsed by Apple.

Copyright © 2026 Heyang Zhou and contributors.

Other Article Hacker News
↑
Close Right Ads
Close Left Ads