XNU Linux: Running macOS Userspace on Linux ~ Ibrahim Kaya
×
Operating Systems

XNU Linux: Running macOS Userspace on Linux

İbrahim Kaya Published: Updated: 2 min read
XNU Linux: Running macOS Userspace on Linux
Contents

The XNU Linux project compiles XNU, Apple's open-source Darwin kernel, and loads it into a standard arm64 Linux kernel as a module (xnu.ko). This approach bypasses the hypervisor layer, allowing macOS processes to run alongside Linux processes on bare metal.

Dual-Kernel Architecture: How It Works

The hosted XNU kernel controls CPU execution and the MMU directly. Linux provides memory, hardware timers, block storage, network interfaces, and GPU resources to XNU through an interface module named fki.ko (Foreign Kernel Interface).

The setup relies on three main parts:

  • CPU Pinning: Each hosted XNU core maps to a Linux kernel thread pinned to an active physical CPU. Linux handles primary exception vectors, while fki.ko forwards faults and system traps to native XNU handlers.
  • Memory Subsystem: Linux allocates a contiguous physical block using the Contiguous Memory Allocator (CMA). XNU manages this block with its internal pmap layer using a 4K page layout.
  • Virtual Kexts: Custom kernel extensions link macOS storage, display, networking, and input needs to Linux host resources.

GPU Bridging and Metal Acceleration

Desktop acceleration relies on a graphics pipeline that bridges Metal to Vulkan. macOS Metal calls route through gpu/xnu-cpu-metal using metal2vulkan. The XnuDrm kext hands these calls to the xnudrmd daemon running on Linux.

bash
# Booting macOS directly within the running Linux kernel
sudo insmod fki.ko
sudo insmod xnu.ko

Using Mesa's Venus driver, Vulkan commands reach the host GPU render node. On systems without Vulkan hardware acceleration, rendering falls back to CPU-based lavapipe emulation.

Current State and Licensing Safeguards

On Apple Silicon hardware running arm64 Linux, the system boots into an interactive macOS desktop (including WindowServer, Finder, and Safari) in roughly 31 to 48 seconds. The project remains experimental. Using 4K pages instead of the 16K pages standard on Apple Silicon affects memory latency, and security layers like SIP and AMFI require relaxed configurations.

To prevent license conflicts between the GPL Linux kernel and Apple's APSL-2.0 code, the two environments stay separated. The xnu.ko binary loads as an external module and communicates only through the public FKI interface without linking directly against internal GPL symbols.