Wednesday, October 23, 2013

Building xnu for OS X 10.9 Mavericks

The OS X kernel source (xnu) has been released for OS X 10.9 Mavericks: here

Building xnu requires Xcode and some additional open-source (but not pre-installed) dependencies. You can build xnu manually by doing:

  1. Install OS X Mavericks and Xcode 5.0.1, make sure the Xcode license has been agreed-to with "sudo xcodebuild -license"
  2. Download the source for the dtrace and AvailabilityVersions projects, which are required dependencies, as well as xnu itself
    $ curl -O
    $ curl -O
    $ curl -O
  3. Build and install CTF tools from dtrace
    $ tar zxf dtrace-118.tar.gz
    $ cd dtrace-118
    $ mkdir -p obj sym dst
    $ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local /usr/local
    $ cd ..
  4. Install AvailabilityVersions
    $ tar zxf AvailabilityVersions-6.tar.gz
    $ cd AvailabilityVersions-6
    $ mkdir -p dst
    $ make install SRCROOT=$PWD DSTROOT=$PWD/dst
    $ sudo ditto $PWD/dst/usr/local `xcrun -sdk / -show-sdk-path`/usr/local
    $ cd ..
  5. Build xnu
    $ tar zxf xnu-2422.1.72.tar.gz
    $ cd xnu-2422.1.72


Unknown said...
This comment has been removed by the author.
Unknown said...

Thank you very much for your guide! It helped a lot!

Unknown said...
This comment has been removed by the author.
Thomas Tempelmann said...

I'm building on 10.9.2 with the latest Xcode (5.1.1). I get several errors when building xnu:

it complains about a mismatch of the define: testing "_KERN_EXTMOD_STATISTICS_H_" but defining "_KERN_EXTMODE_STATISTICS_H_".

Getting this message on several files:
"ERROR: ctfconvert: file does not contain dwarf type data (try compiling with -g)"

Lots of errors around "vlan" functions, such as:
"/Development/Darwin/xnu/bsd/net/if_vlan.c:267:1: error: unused function 'vlan_parent_flags_clear_supports_vlan_mtu'

Any idea what's going wrong?
(Yes, I am building "xnu-2422.1.72", I just renamed the dir to "xnu", but that can hardly be the cause of these errors).

Thomas Tempelmann said...
This comment has been removed by the author.
Thomas Tempelmann said...

BTW. I am using:

$ cc --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

Have you tried building xnu with Xcode 5.1 on 10.9.2? Does it work for you? If not, I might just try to install Xcode 5.0.1 in a VM and see if that helps.

Thomas Tempelmann said...

Turns out it's a problem with Xcode 5.1.1 - I have installed a clean 10.9.2 with Xcode 5.0.2 - that one built the kernel fine, even though I got the "ctfconvert" errors there as well.
Then I installed Xcode 5.1.1 and did another make - that one then failed again.

So, for anyone trying to build xnu Darwin 13.1.0 - get the older Xcode 5.0.2 from Apple's "Additional Tools" Downloads page (

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Unknown said...

I was able to compile this with Xcode 5.1, after removing the occurrences of -Werror from makedefs/MakeInc.def

Anonymous said...


Great tutorial! I've been building xnu this way for quite a while. I built and installed the kernel just fine, however, what I noticed is that, this kernel is not being loaded by the kernelcache file. I tested this by comparing the boot time between the stock kernel and this kernel in verbose mode. The stock kernel boots in approximately 6-8 seconds. This kernel however, takes 30-40 seconds to boot. I'm presuming that the kernel built from your guide is not a `prelinked' kernel.

The system is definitely not loading the kernelcache file when I boot with the kernel created from your guide.

I'm somewhat new to building prelinked mach_kernels. Do you have any ideas on how to go about doing anything like this, or; i.e., is there some other way to get this kernel to use the already existing kernelcache file that the stock kernel uses? Or, is that a bad idea?

The primary reason that I'm wanting to do this is because I want to rectify the extremely slow boot with this self-compiled kernel. I've tried rebuilding the caches, etc... and that does nothing, as far as affecting the speed up.

Any suggestions would be greatly appreciated.


Unknown said...

Thank you very much! This works with Yosemite (10.10) running XCode 6.1 as well. The only difference is the package version numbers you build.


Unknown said...

Oh, and the command to compile xnu for Yosemite is slightly different as well:

make TARGET_CONFIGS="release x86_64 default" SDKROOT=/Applications/

Unknown said...

I would love to know if I could build all the versions mentioned here with One OS and current Xcode !

Or at least all the downward versions of xnu from what I've for OS version.

In my case, it is 10.9.5, Xcode 6.1.1 - so what version(s) could I possibly build with this ?


Unknown said...

Why iMac Macbook production before Maverick Osx no internet recovery
this an answer

Unknown said...

Hello, do you know if modern xnu (included in OSX) is compiled with clang or with gcc? thanks!

Joko Sastrowidodo said...

Good and very useful article. Thanks a lot!

octavevalenzuela said...

MgmD | MgmD
The MgmD is an innovative 통영 출장샵 and exciting social platform and 천안 출장샵 betting app. The 수원 출장안마 MgmD is 제천 출장샵 an innovative and 경주 출장마사지 exciting social platform and betting app. Rating: 4.4 · ‎3,254 reviews