@qwerty__cs: macOS 的完整桌面在 Linux 里跑起来了!macOS 的内核被做成了一个 Linux 内核模块,代码已经开源! 做法很野:用苹果公开的源码编出 XNU 内核,做成一个 xnu.ko,在没改过的 arm64 Linux 里 insm…
摘要
开源项目 xnulinux 把 macOS 的 XNU 内核编译成 Linux 内核模块(xnu.ko),在未修改的 arm64 Linux 上直接启动 macOS 27 到桌面,无需虚拟机管理程序,Metal 通过转译为 Vulkan 使用 Linux 主机的 GPU。
查看缓存全文
缓存时间: 2026/11/23 11:00
macOS 的完整桌面在 Linux 里跑起来了!macOS 的内核被做成了一个 Linux 内核模块,代码已经开源!
做法很野:用苹果公开的源码编出 XNU 内核,做成一个 xnu.ko,在没改过的 arm64 Linux 里 insmod 一下加载进去。XNU 直接管 CPU 和内存,macOS 的进程和 Linux 的进程在同一批 CPU 上并排跑,中间没有虚拟机管理程序。
一台普通 Ubuntu 内核的机器,加载之后直接把苹果安装器做出来的 macOS 27 系统盘启动到桌面:登录窗口、Dock、Finder 都在,Safari 和 Chrome 也能开。
开机到桌面 31 到 48 秒,同一台 Mac 上苹果自家的 macOS 虚拟机要 49 秒。连续开关 Safari、备忘录、系统设置折腾 30 分钟,没有崩。显卡也接上了,macOS 里的 Metal 转成 Vulkan,用的是 Linux 这边的 GPU。
现在只在苹果 M 系列芯片的 Mac 里的 Linux 虚拟机上跑通,要 16G 内存,还要一台装了 Xcode 的 Mac 和你自己的 macOS 安装来做系统盘,仓库里不带任何苹果的文件。
项目地址 https://github.com/AFK-surf/xnulinux…
AFK-surf/xnulinux
Source: https://github.com/AFK-surf/xnulinux
xnulinux
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 27 system disk made by Apple’s own installer to the
desktop: loginwindow, WindowServer, 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,
WindowServer, 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, 1280×800.

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).
How it works
macOS processes (launchd, WindowServer, Safari...) Linux processes (systemd, sshd, xnudrmd...)
────────────────────────────────────────────────── ────────────────────────────────────────────
XNU (source-built, LINUX64 machine layer, kexts) │
↕ linux64 host calls (xnu-patches/include/linux64_abi.h)
xnu.ko (APSL side: loads and runs the kernel collection)
↕ FKI, the foreign kernel interface (fki_*)
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.koforwards 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 share the user half of the address space layout (4K pages).
- 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/XnuDrm→ host call →gpu/xnu-drm/xnudrmd→ 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, TextEdit, 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.
What is still a stopgap is listed in docs/production.md. Notably: the OS cryptex is merged into
the system volume, AMFI is patched and SIP relaxed, and memory access is slower than a native VM (4K pages vs 16K).
Requirements
- An arm64 Linux host with PAC (Apple Silicon M1 or later in a VM: krunkit for GPU access, or tart), 4K pages, 16 GB of RAM (8 GB of it reserved for the hosted kernel).
- A Mac with Xcode to make the system disk and build the GPU parts.
- A macOS 27 installation (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 system disk and its trust cache come from your own installation.
Building and running
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.scripts/vm-xnu-rebuild.sh: appliesxnu-patches/, builds the kernel andkexts/, and links the kernel collection with Apple’s kexts from your macOS installation.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.scripts/xnulinux-boot.sh(in the Linux VM): buildsfki.koandxnu.koagainst the running kernel, brings up the network (and the GPU bridge when there is a render node) and boots the hosted system. Its console isscripts/xnu-console.sh, its screentools/hosted/fb2png.py, inputtools/hosted/xnu-input.py.scripts/install-service.sh(in the Linux VM): runs it asxnulinux.service, configured in/etc/xnulinux.conf(CPUs, memory, disk, GPU). On the Mac,scripts/install-krun-agent.shkeeps the VM itself running.- GPU (optional, on the Mac):
gpu/venus/build-darwin.shbuilds the hosted Vulkan driver,gpu/xnu-cpu-metal/the Metal plugin (see its README).
Repository layout and licenses
The Linux side and the XNU side are kept apart by license and meet only at FKI. Every source file carries an
SPDX-License-Identifier; the license texts are in LICENSES/.
| Path | License | What |
|---|---|---|
fki-ko/, linux/ | GPL-2.0-only | FKI: the out-of-tree module for stock kernels, and the same as an in-tree driver |
xnu-ko/ | APSL-2.0 | xnu.ko: loads XNU’s kernel collection and runs it; calls Linux only through fki_* |
xnu-patches/ | APSL-2.0 | The LINUX64 machine layer and the other 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 over 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 license (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 side of the line: it runs XNU’s code in its own address space, so it is APSL-2.0 like XNU, and
Linux reports it as a non-GPL module (MODULE_LICENSE("Proprietary"), which taints the kernel as ZFS does). It must not
include Linux headers beyond the module ABI, call Linux functions other than fki_*, or carry 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.
Acknowledgements
- macOS-DroidVM and UniXNU: the 4K-page XNU base, the Linux-hosted XNU toolchain, and the display, Ethernet and input kexts these are derived from.
- metal2vulkan, Mesa (Venus, lavapipe), virglrenderer and krunkit.
- Apple’s open-source XNU.
macOS, Metal and XNU are trademarks of Apple Inc. This project is not affiliated with or endorsed by Apple.
Copyright © 2026 Heyang Zhou and contributors.
相似文章
XNU Linux:在 Linux 上运行完整 OS X 图形界面用户空间
xnulinux 是一个开源项目,它从源码构建 Apple 的 XNU 内核并将其作为内核模块(xnu.ko)加载,从而在未经修改的 arm64 Linux 内核上运行完整的 macOS 用户空间,让 macOS 进程与 Linux 进程在没有虚拟机监控程序的情况下原生并行运行。它能启动 macOS 27 桌面环境,Safari、Finder、WindowServer 均可正常工作,并通过 Vulkan/DRM 实现 GPU 桥接。
@alswl: 你知道 Linux 内核有一个 1997 年就引入的特性,让 Apple Silicon Mac 能高效运行 x86 容器吗? 它叫 binfmt_misc,Linux 2.1.43 引入,距今快 30 年了。 原理极其简单: Linux…
文章介绍了Linux内核自1997年引入的binfmt_misc特性,它允许通过注册规则将二进制文件交给指定解释器执行,如今在Apple Silicon Mac上结合Rosetta实现高效运行x86容器,性能接近原生70-90%。
@nos_ult:我对 NVIDIA 的 DLSS 代码进行了逆向工程,让它能在 APPLE METAL 上原生运行。NETAL 现已公开。NVIDIA 官方支持的 DLL……
开发者通过逆向工程 NVIDIA 的 DLSS 代码,构建了可在 Apple Metal 上原生运行的开源项目 Netal,实现了超分辨率和神经帧生成,并已在 M3 Max 上通过 CrossOver 运行《生化危机 Requiem》。该项目目前仍处于实验阶段,需要用户自备 NVIDIA DLL 和模型权重。
@geekbb: 在 Apple Silicon 的 macOS 上实现 NTFS 读写,无需内核扩展、无需关闭 SIP。 这其实是运行了一个 libkrun 微型虚拟机(基于 anylinuxfs,内部跑 ntfs-3g)来完成真正的 NTFS 写入,再…
ntfsmac is an open-source tool that enables NTFS read/write on Apple Silicon macOS by using a libkrun microVM running ntfs-3g, avoiding kernel extensions and SIP modifications. It provides both CLI and a GUI menu-bar app.
@QingQ77: 一个用 Rust 和 C 编写的开源项目,通过 JIT 编译技术在 macOS 上直接运行 Linux 容器。 https://github.com/ricccrd/dd 它不需要虚拟机、hypervisor 或 Linux 内核,而是将…
dd is an open-source tool written in Rust and C that runs Linux containers on macOS without a VM by using JIT compilation to translate container instructions and handle syscalls in userspace. It implements the Docker Engine API, supports arm64 and x86-64 Linux images, and offers performance comparable to or better than VM-based solutions.


