What happens in the Mac OS X boot process?
Ever wondered what happens during the Mac OS X boot and startup process? With Mac OS X it’s a bit more complicated than things once were, and long gone are the days of Classic Mac OS (System 9, 8, 7, 6), where watching our Macs boot up with a series of extensions and control panels that we could always identify by their icon alone, and then go dig around in the Extensions folder to easily adjust what is loading and occurring on Mac boot. Today with the Unix underpinnings of Mac OS X, many users are entirely unaware of what is going on behind the scenes.
So what exactly happens during the Mac OS X boot process? You can always get a better look by booting a Mac in Verbose Mode, but that doesn’t necessarily explain all of what you see. Fortunately an excellent explanation is available via segment at KernelThread, which carefully lists the sequence of Mac OS X boot events, from start to finish. It is fairly thorough and worth a read, repeated below for the inquisitive Mac users out there.
Note: As a reader pointed out, PPC uses OF (Openfirmware), i386 uses EFI (Extensible Firmware Interface)
So what happens during the Mac OS X boot process? You turn on your Mac, and this is what happens:
- Power is turned on.
- OF or EFI code is executed.
- Hardware information is collected and hardware is initialized.
- Something (usually the OS, but also things like the Apple Hardware Test, etc.) is selected to boot. The user may be prompted to select what to boot.
- Control passes to
/System/Library/CoreServices/BootX, the boot loader. BootX loads the kernel and also draws the OS badges, if any.
- BootX tries to load a previously cached list of device drivers (created/updated by
/usr/sbin/kextcache). Such a cache is of the type
mkextand contains the info dictionaries and binary files for multiple kernel extensions. Note that if the mkext cache is corrupt or missing, BootX would look in
/System/Library/Extensionsfor extensions that are needed in the current scenario (as determined by the value of the
OSBundleRequiredproperty in the
Info.plistfile of the extension’s bundle.
initroutine of the kernel is executed. The root device of the booting system is determined. At this point, Firmware is not accessible any more.
- Various Mach/BSD data structures are initialized by the kernel.
- The I/O Kit is initialized.
- The kernel starts
/sbin/mach_init, the Mach service naming (bootstrap) daemon.
mach_initmaintains mappings between service names and the Mach ports that provide access to those services.
From here on, the startup becomes user-level:
/sbin/init, the traditional BSD init process. init determines the runlevel, and runs
/etc/rc.boot, which sets up the machine enough to run single-user.
During its execution,
rc.boot and the other
rc scripts source
/etc/rc.common, a shell script containing utility functions, such as
CheckForNetwork() (checks if the network is up),
purgedir() (deletes directory contents only, not the structure), etc.
rc.bootfigures out the type of boot (Multi-User, Safe, CD-ROM, Network etc.). In case of a network boot (the
kern.netbootwill be set to
1in which case), it runs
/etc/rc.netboot handles various aspects of network booting. For example, it performs network and (if any) local mounts. It also calls
/usr/bin/nbst to associate a shadow file with the disk image being used as the root device. The idea is to redirect writes to the shadow file, which hopefully is on local storage.
rc.bootfigures out if a file system consistency check is required. Single-user and CD-ROM boots do not run fsck. SafeBoot always runs fsck.
rc.boothandles the return status of fsck as well.
/etc/rc, the multi-user startup script is then run. If booting from a CD-ROM, the script switches over to
/etc/rcmounts local file systems (HFS+, HFS, UFS,
/.vol), ensures that the directory
/private/var/tmpexists, and runs
/etc/rc.installer_cleanup, if one exists (left by an installer before reboot).
/etc/rc.cleanupis run. It “cleans” a number of Unix and Mac specific directories/files.
- BootCache is started.
sysctlvariables are set (such as for maximum number of vnodes, System V IPC, etc.). If
/etc/sysctl-macosxserver.confon Mac OS X Server), it is read and
sysctlvariables contained therein are set.
- The Mach symbol file is created.
kextd, the daemon process that loads kernel extension on demand from kernel or client processes.
/usr/libexec/register_mach_bootstrap_serversis run to load various Mach bootstrap based services contained in
/System/Library/Extensions.mkextis older than
/etc/rcdeletes the existing mkext and creates a new one. It also creates one if one doesn’t exist.
/usr/sbin/update, the daemon that flushes internal file system caches to disk frequently.
/etc/rcstarts the virtual memory system.
/private/var/vmis set up as the swap directory.
/sbin/dynamic_pageris started with the appropriate arguments (swap filename path template, size of swap files created, high and low water alert triggers specifying when to create additional swap files or delete existing ones).
/usr/libexec/fix_prebindingto fix incorrectly prebound binaries.
/etc/rc.cleanupto clean up and reset files and devices.
/sbin/SystemStarterto handle startup items from locations such as
/Library/StartupItems. A StartupItem is a program, usually a shell script, whose name matches the folder name. The folder contains a property list file containing key-value pairs such as
OrderPreference, start/stop messages etc. You can run
SystemStarter -n -Das root to have the program print debugging and dependency information (without actually running anything).
CoreGraphicsstartup item starts the Apple Type Services daemon (
ATSServer) as well as the Window Server (
And then your Mac is booted!
You can see a little of this activity yourself with Verbose Mode (which you can boot into Verbose Mode per boot, or you can even set a Mac to always boot in Verbose Mode if you want to always see the unix style boot), but this is a pretty thorough explanation.
Apple also has some documentation available on the Mac boot process available here at their developer documentaiton library here.
Note the original URL providing the above information is no longer active, thus that post has been included above for posterity via cache. The original source was a thread on KernelThread at the following url: http://www.kernelthread.com/mac/osx/arch_startup.html which is currently offline and does not redirect to a new location.
If you have any tidbits or other additions to add to the Mac OS X boot sequence, share in the comments!