Building XNU kernel on Snow Leopard
XNU kernel Source for Mac Os X 10.6 Snow Leopard has ben release on opensource.apple.com
Building xnu requires some open source (but not pre-installed) tools. Darwinbuild is the most reliable way for building these dependencies and xnu itself. Until that is ready, you can build the tools manually as follows:
make a dir in desktop or some where else (eg Kernel)
Open Terminal and type
cd ~/desktop/Kernel
(if you created a Kernel dir in desktop)
- Download the build tools source(s)
$ curl -s -O http://www.opensource.apple.com/tarballs/cxxfilt/cxxfilt-9.tar.gz
$ curl -s -O http://www.opensource.apple.com/tarballs/dtrace/dtrace-78.tar.gz
$ curl -s -O http://www.opensource.apple.com/tarballs/kext_tools/kext_tools-177.tar.gz
$ curl -s -O http://www.opensource.apple.com/tarballs/bootstrap_cmds/bootstrap_cmds-72.tar.gz - Unpack the tools
$ tar zxf cxxfilt-9.tar.gz
$ tar zxf dtrace-78.tar.gz
$ tar zxf kext_tools-177.tar.gz
$ tar zxf bootstrap_cmds-72.tar.gz
- Build cxxfilt
$ cd cxxfilt-9
$ mkdir -p obj sym dst
$ make install RC_ARCHS="i386 x86_64" RC_CFLAGS="-arch i386 -arch x86_64 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
...
$ sudo ditto $PWD/dst/usr/local /usr/local
Password:
$ cd ..
- Build dtrace
$ cd dtrace-78
$ mkdir -p obj sym dst
$ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
...
$ sudo ditto $PWD/dst/usr/local /usr/local
Password:
$ cd ..
- Build kext_tools
$ cd kext_tools-177
$ mkdir -p obj sym dst
$ xcodebuild install -target kextsymboltool -target setsegname ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
...
$ sudo ditto $PWD/dst/usr/local /usr/local
Password:
$ cd ..
- Build bootstrap_cmds
$ cd bootstrap_cmds-72
$ mkdir -p obj sym dst
$ make install RC_ARCHS="i386" RC_CFLAGS="-arch i386 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
...
$ sudo ditto $PWD/dst/usr/local /usr/local
Password:
$ cd ..
- Download the xnu source
$ curl -s -O http://www.opensource.apple.com/tarballs/xnu/xnu-1456.1.26.tar.gz
- Unpack xnu
$ tar zxf xnu-1456.1.26.tar.gz
- Build xnu
$ cd xnu-1456.1.26
$ make ARCH_CONFIGS="I386 X86_64" KERNEL_CONFIGS="RELEASE"
...
$ file BUILD/obj/RELEASE_*/mach_kernel
BUILD/obj/RELEASE_I386/mach_kernel: Mach-O executable i386
BUILD/obj/RELEASE_X86_64/mach_kernel: Mach-O 64-bit executable x86_64
Original Post : here
To build a modified XNU with a .diff of an XNU kernel you need to:
1. Download and Apply the patch
download the .diff file and place it in your kernel folder (eg. ~/desktop/Kernel/patch.diff )
Patch the source with :
cd ~/desktop/Kernel/
patch -p0 -i patch.diff
2. build the kernel (make sure you have remove the BUILD folder in xnu-1456.1.26 folder i you have try to build before
$ cd xnu-1456.1.26
$ make ARCH_CONFIGS=”I386 X86_64″ KERNEL_CONFIGS=”RELEASE”
(for i386 and x86_64 build)
or
$ cd xnu-1456.1.26
$ make ARCH_CONFIGS=”I386″ KERNEL_CONFIGS=”RELEASE”
(for i386 build only (legacy kernel))
Hello,
I was able to build xnu for snow leopard following your instructions. But, now that I’ve installed Lion, kext_tools-251 for xnu-1699.22.73 is missing kextsymboltool and setsegname. Therefore, xcodebuild fails because of this. Do you have any suggestions on building xnu for Lion? I’m wondering if there are different instructions for building the Lion kernel?
“Boeaja | Building XNU kernel on Snow Leopard” ended up being really pleasurable and instructive!
In modern world honestly, that is very hard to deliver.
With thanks, Hazel
Your tutorial is better than Apple’s tutorial. Any chance you can add a tutorial on building Mac OS 10.2′s kernel?