back to home
(An Attempt At) Building OS X Snow Leopard on Debian
A complete disaster and failure
Preamble
Some time ago I decided it would be a great idea (it wasn't) to build my own version of OS X Snow Leopard which includes modern drivers, extended support for non-Mac systems and more modern/refreshed software in general. I picked Snow Leopard specifically because I enjoyed the design language of the OS and it wasn't as outdated as some of the other OSes whilst still having a load of internal software be open-source.
One of the biggest challenges that I'll probably experience throught this will probably be dodging the proprietary and trying to substitute something else in instead. Even if OS X is just a BSD distro at its bare core, there's still a lot of things that Apple shoved in to make the OS work specifically on their devices, which is why Hackintosh is only possible on specific range of hardware ever since macOS was initially released for Intel CPUs. I predict that I'll have to use OpenCore quite a bit in this project too, which will spoof some of the proprietary features of Apple branded hardware.
The reason why I'm building this on something like Debian is because it'll be more accessible to the average person to redo what I did (if they ever want to for whatever reason) than something like a macOS system/VM. Also macOS is a pain in the ass to work with, at least for me.
The timeline for the project will most likely be something like this: Gather source tarballs > Extract official SDK > Point proprietary tools to FOSS Linux tools > Build XNU kernel & test in QEMU until no panics> Shove in runtimes into root > Boot into shell > Try FreeBSD/OpenBSD drivers & bundle Homebrew > Display the Aqua GUI > Try to install modern apps/replacements > Polish and sweep
Gathering
As mentioned before, most of the source code for tools in Snow Leopard has been released by Apple already, we can combine this with the OS X 10.6 SDK found inside older versions of Xcode.
The first tarballs that I downloaded and extracted initially were the following:
- CF 550.43
- Libc 594.9.5
- objc4 437.3
- dyld 132.13
- libdispatch 84.5.5
- launchd 329.3.3
- xnu 1504.15.3
- Not a tarball but Xcode 4.2 (official Apple link is 403 for whatever reason)
All these tarballs were placed into one directory and extracted (make sure each one is in its own folder though).
First Attempt at Building XNU (don't follow as guide)
After untaring the tarballs, we can begin more or less setting stuff up.
Setting up the SDK
Firstly, I used p7zip to extract the dmg file from Xcode, 7z x xcode_4.2_for_snow_leopard.dmg
. This should give out 3 folders and a pdf. What we're interested in is Packages/MacOSX10.6.pkg
which I'd advise to copy to a different directory. In the new directory, you run 7z x MacOSX10.6.pkg
, giving out a file named something like Payload~
, we run 7z on it again, 7z x Payload~
. At last this gives us a folder named SDKs which contains thousands of files that'll be helpful to us. Move the folder inside of it to /opt/ or another folder if you want, sudo mv SDKs/MacOSX10.6.sdk /opt/
.
Looking into the compiler
The README in the XNU source states that the syntax is the following:
$ . SETUP/setup.sh
$ make all
In our case, make all
will mean that the compiler will search for headers in the default location on OS X, but we aren't using OS X, so we have to specify said headers with SDKROOT=/opt/MacOSX10.6.sdk
before all
.
Another helpful option to put in is TARGET_CONFIGS="X86_64-RELEASE"
which will mean that the compiler will skip over PowerPC, 32-bit Intel and ARM (although it'd be interesting to compile Snow Leopeard for ARM someday). This is optional but it'll be less of a pain in the ass in the future since we can avoid irrelevant compiler errors.
After running make SDKROOT=/opt/MacOSX10.6.sdk TARGET_CONFIGS="X86_64-RELEASE" all
, I got the following errors:
make: /usr/bin/xcrun: No such file or directory
make: /usr/bin/xcrun: No such file or directory
make: [path\]/xnu-xnu-1504.15.3: Permission denied
sysctl: cannot stat /proc/sys/hw/logicalcpu: No such file or directory
expr: syntax error: unexpected argument '2'
sysctl: cannot stat /proc/sys/hw/logicalcpu: No such file or directory
expr: syntax error: unexpected argument '2'
The xcrun
it's looking for is a tool that's found in macOS to find and execute developer tools quickly and safely. As we're not on macOS we don't have the option of using xcrun so we'll have to figure out a way of figuring out what its trying to look for and lead it to the right path.
As for the weird permission error, it might be because it's trying to execute a directory as a file and thus failing.
sysctl
cannot find the /proc/sys/hw/logicalcpu
directory because it's not even meant to in the first place. This command is handled differently between macOS and Linux, where in macOS it's a kernel syscal while in Linux it looks in /proc/sys
. expr
is a tool to evaluate an expression, or in other words, do math (try running expr 9 + 12
!), I guess the output that sysctl
passes onto expr
is essentially garbage.
Going a slightly different path with XNU
I realised pretty early on that it'd be too much of a pain to do everything by hand with default normal tools, which is why I decided to use something like osxcross which is a toolchain to compile OS X stuff on Linux.
I deleted the pkg folder in /opt/ as I don't think it was needed anymore and redownloaded Xcode. Then I installed the dependencies + dmg2img, cloned the master branch, went into the osxcross directory and ran sudo ./tools/mount_xcode_image [path to xcode dmg]
and followed the instructions given in the terminal afterwards. This will give us MacOSX10.6.pkg
that isn't a directory but an actual package. Move it to the tarballs directory inside of osxcross.
Then I ran ./build.sh
, we don't need to build clang or Apple's special clang since we should already have it installed I believe but if you're following this for whatever reason, you can check if you have clang installed by simply running clang
in your terminal. Building might take a while but once you're done, I'd advise you to add the built binaries to $PATH with export PATH=$PATH:~/osxcross/target
(check where your osxcross directory is first though).
One issue I had with building this was for whatever reason it didn't want to extract MacOSX10.6.pkg and no matter what I did I couldn't get it to work. Which is where I decided to give up on trying Debian and decided to try from scratch on a modern version of macOS.