On Jun 14, 2009, at 2:57 AM, Thomas Tempelmann wrote:
Despite reading Amit Singh's book "OS X Internals" and searching the
web, I still am missing some details about how the OS X boot process
works. Maybe someone here can enlighten me?
The gap I am trying to fill is how the basic kexts are loaded and initialized:
When the kernel starts, it appears to need a few drivers which are
implemented in external kexts. Only later, when all is set up, there's
a daemon which dynamically loads other kexts. I like to understand the
binding of the former type of drivers.
I understand that there's a kextcache, which binds the kernel with a
set of kexts and stores it in
/System/Library/Caches/com.apple.kernelcaches/
Question 1: What rule specifies which kexts get linked to that kernel?
See the OSBundleRequired property.
Question 2: What if this file does not exist, can the system still
boot, and which component is then taking care of finding the kexts
(e.g. is it boot.efi or the kernel or what?)
The bootloader is capable of parsing extension plists.
Now to the Extensions.mkext. I understand that this gets automatically
created from a running OS X in the background whenever it detects
changes to the Extensions folder (or at least in most such cases).
Question 3: Does this mkext contain _all_ kexts from the Extensions
folder then, or does it sort them out somehow (by what rule)?
See the answer to 1 above.
Amit writes that the boot loader (boot.efi) loads the kernel and
Extensions.mkext. Is he referring to the prebound kernel cache file
here? Provided that file does not exist (question 2), it probably
loads the mktext file and kernel (from the root dir) separately.
However, due to Amit's book, the boot_args struct does not provide for
passing a reference to the mkext file to the kernel.
Question 4: How does the mkext, if loaded separately, get linked to
the kernel? (i.e. does the boot loader contain a linker that works
like the kextcache command?)
The kernel contains a linker that handles this.
Question 5: How do these basic kexts get initialized then? Does the
boot loader init them before calling the kernel, or does the kernel
find them somehow and init them?
The kernel finds them.
Note that Amit's book predates the introduction of the kernelcache, which is a single file containing a fully linked and ready-to-run copy of the kernel and extensions used on the previous boot; see /System/Library/Caches/com.apple.kernelcaches.