a few days ago apple finally released the source for mac os x mavericks 10.9.1 and 10.9.2! i’m happy about it as I had massive problems to run my custom kernel with the kernel source of 10.9.
building the kernel is sometimes an adventure so here you get short introduction how to build it for your machine.
if you are completely new in building your custom kernel I suggest to have a look at http://shantonu.blogspot.de/ . sen also shows the steps even for older systems.
for 10.9.2 you need following sources:
and the latest source of today, for me
store all the tar.gz’s in a single folder and deflate all with “tar zxf….”.
cd into each of the created directories and create following folders by executing “mkdir -p obj sym dst”
lets now cd in to the dtrace folder to build ctf* tools.
the build command: “xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS=”x86_64″ SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst“. in order to work with those tools you need to register/copy them at the correct location. that is done by “sudo ditto $PWD/dst/usr/local /usr/local“.
2nd step is to build the AvailiabilityVersions, again change into the appropriate directory and enter the build command: “make install SRCROOT=$PWD DSTROOT=$PWD/dst“. same here register/copy the files with “sudo ditto $PWD/dst/usr/local `xcrun -sdk / -show-sdk-path`/usr/local“.
if that all was successful, we can finally start building our own kernel. a last time we cd to the xnu kernel source directory where we trigger the build process by typing “make ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE“. alternatively you can change the kernel config to DEBUG but be careful!!!! that changes the behaviour of the kernel definitively so you should know what do…
depending on what xcode you use for source code compiling the build process might abort due to a few warning/errors. you can get around that if you modify you build command like following:
“make ARCH_CONFIGS=X86_64 KERNEL_CONFIGS=RELEASE CWARNFLAGS_STD=”-Wall” CXXWARNFLAGS_STD=”-Wall””
hopefully the build process finishs now without any problems! if you are lucky you will find the mach kernel binary after the build process in the BUILD directory within the kernel source directory.
last few steps to activate your custom kernel:
1. make a copy of your original kernel, running right now ( trust me, you will hate yourself if you skip that step 😉 )
2. ensure that you have on a native machine a recovery partion to boot from or on a virtual machine a snapshot of your current state ( after successfully build the kernel.. )
3. replace the original kernel with yours ( “sudo cp …..BUILD/…./mach_kernel /” )
4. reboot and cross fingers!
in worst case, if you system is not booting anymore you will have to use the recovery partion to restore the original kernel ( you can use terminal app which comes with rec partition ) or revert back to the previous snapshot and search the problem.
nevertheless if your system starts then you have now the full power to implement whatever you want to analyse the kernel and instrument it statically. this helped me a lot to track down issues while i developed kernel extensions and played with hardware.
enjoy your custom XNU!