What happens in the Mac OS X boot process?

Jan 22, 2007 - 36 Comments

Finder icon

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 mkext and 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/Extensions for extensions that are needed in the current scenario (as determined by the value of the OSBundleRequired property in the Info.plist file of the extension’s bundle.
  • The init routine 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_init maintains mappings between service names and the Mach ports that provide access to those services.

From here on, the startup becomes user-level:

  • mach_init starts /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), GetPID(), purgedir() (deletes directory contents only, not the structure), etc.

  • rc.boot figures out the type of boot (Multi-User, Safe, CD-ROM, Network etc.). In case of a network boot (the sysctl variable kern.netboot will be set to 1 in which case), it runs /etc/rc.netboot with a start argument.

/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.boot figures out if a file system consistency check is required. Single-user and CD-ROM boots do not run fsck. SafeBoot always runs fsck. rc.boot handles the return status of fsck as well.
  • If rc.boot exits successfully, /etc/rc, the multi-user startup script is then run. If booting from a CD-ROM, the script switches over to /etc/rc.cdrom (installation).
  • /etc/rc mounts local file systems (HFS+, HFS, UFS, /dev/fd, /.vol), ensures that the directory /private/var/tmp exists, and runs /etc/rc.installer_cleanup, if one exists (left by an installer before reboot).
  • /etc/rc.cleanup is run. It “cleans” a number of Unix and Mac specific directories/files.
  • BootCache is started.
  • Various sysctl variables are set (such as for maximum number of vnodes, System V IPC, etc.). If /etc/sysctl.conf exists (plus /etc/sysctl-macosxserver.conf on Mac OS X Server), it is read and sysctl variables contained therein are set.
  • syslogd is started.
  • The Mach symbol file is created.
  • /etc/rc starts kextd, the daemon process that loads kernel extension on demand from kernel or client processes.
  • /usr/libexec/register_mach_bootstrap_servers is run to load various Mach bootstrap based services contained in /etc/mach_init.d
  • portmap and netinfo are started.
  • If /System/Library/Extensions.mkext is older than /System/Library/Extensions, /etc/rc deletes the existing mkext and creates a new one. It also creates one if one doesn’t exist.
  • /etc/rc starts /usr/sbin/update, the daemon that flushes internal file system caches to disk frequently.
  • /etc/rc starts the virtual memory system. /private/var/vm is set up as the swap directory. /sbin/dynamic_pager is 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).
  • /etc/rc starts /usr/libexec/fix_prebinding to fix incorrectly prebound binaries.
  • /etc/rc executes /etc/rc.cleanup to clean up and reset files and devices.
  • /etc/rc finally launches /sbin/SystemStarter to handle startup items from locations such as /System/Library/StartupItems and /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 Description, Provides, Requires, OrderPreference, start/stop messages etc. You can run SystemStarter -n -D as root to have the program print debugging and dependency information (without actually running anything).
  • The CoreGraphics startup item starts the Apple Type Services daemon (ATSServer) as well as the Window Server (WindowServer).

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!

.

Related articles:

Posted by: OSXDaily in Mac OS

36 Comments

» Comments RSS Feed

  1. Ma(r)c says:

    The cost of OSX updates DVD’s are around 30 euro’s but only to be used on Apple machines. But actually the cost of 30 euro’s should be the price of any full os. Fair and balanced. Period. Back to the original thought.

  2. tripleX says:

    I like my tv, radio, dvd-player, my fridge, my cooker. Very useful. But I love my car and I love my Mac.

  3. utahnix says:

    OS X has some great things about it, but not all of us think it’s the cat’s meow. OS X is no more *the* OS than XP, Vista or 7 is. It’s a choice. Nothing more – at least in my opinion.

    I like that OS X was originally built atop many open components – i.e. CUPS, KHTML, BSD, Samba, etc, etc… but I don’t like how Apple has caked a thick, proprietary layer atop it.

    In my mind, the question is… is OS X really open, or very closed? Both? Neither? It’s hard to say, IMO.

    While I will give Apple cudos for realizing that open-source code is high-quality stuff, and that it generally does the job really well, I find many of their marketing claims a bit hypocritical. The so-called “Redmond, start your photocopiers” bit they did when Tiger was released was particularly hypocritical. Copying ideas (Microsoft) is one thing… copying source code, line by line (Apple), is another.

    And the debate on security… well, is debatable. There is no way to conclusively prove what OS is more secure, regardless of what opinions may exist on either side.

    The way I see it, a lot of the best features from OS-X (IMHO) came from the OSS community, not Apple. And Microsoft, they just buy their competition’s products and then slap MS logos on them… or litigate the competition out of existence.

    And Linux… well, Linux isn’t for everyone either. It can be hard to configure, and getting software to install isn’t always a walk in the park, especially when you run into dependency problems. Hardware support (thanks to cheap hardware and companies that refuse to play nice) can be tricky. But it’s transparent, and that’s why I like it. But then again I don’t expect any of you to agree with me. I believe there is no such thing as “best” per-se.

    I suppose I see Apple and Microsoft as players in a large game of economics… where either will take whatever control of the market they can get, and will do whatever they can to get it, whether it’s good for the consumer or not. I think both companies have had their share of hypocrisy.

    And to be honest, companies like Novell and RedHat want their share of the pie and will do almost anything to get it as well. But I think Apple and Microsoft are worse.

    That’s my two cents. I’m sure there will be rebuttals to my comments. I’m expecting it.

  4. homs says:

    once you go mac you never look back

  5. internet says:

    This all is no longer true. In the Leopard everything changed and the mentioned scripts no longer exists. Over time unix-like features stolen from BSD-Unix became more and more crippled. Fare well OSX …

  6. alex says:

    To search for a file through the entire actual partition, you can use:

    $ find / -name “file.ext”

    where file.ext is the name and extension of the file to be searched.

    It’s the same as in other *NIX system, I think.
    Alex

  7. big bob says:

    simple question…you know how in windows you can search for a file on the entire hard drive by typing dir *.doc /s does anyone how to do this from terminal?

  8. chunky_woman says:

    1.42Ghz,768MB,80GB- -nice comp

    how do u start in the mac os x 10.5?

  9. Jack says:

    Now that Mac OS X is based on the i386 platform, I’m thinking of switching to it from XP. Any advice?

  10. mzfniamm says:

    Mac OS X is the best in the world! It needs not so much resources and not so much time to install. I think over the years will improve.

  11. screwer says:

    is there a way to force osx to boot instead of os 9 cus i ive just selected to boot os 9 on my powerbook g4 and when tried to boot jus get an hapy face icon blinking

  12. […] read more | digg story […]

  13. […] What happens in the Mac OS X boot process: […]

  14. Nick says:

    If anyone has any ideas and cares to share I would appreciate (I know this is not a tech forum….just covering all my bases). I look after 2 computer labs with 25 eMacs each (G4 1.42Ghz,768MB,80GB,Tiger10.4.8) at a school. At any point in time to a couple of random machines, they will refuse to boot…..they get to the grey apple logo and either locks up before the spinner appears or the spinner just spins indefinatly. It usually takes about 3 or 4 forced power offs or a netboot to get them to finally boot properly. Like I said, it happens at random times to any one (or couple) of the 50 computers and it doesn’t follow any pattern (eg. if a computer refuses to boot and you finally get it to boot, it might work perfectly for months before anything else goes wrong and there are others that do it on a weekly basis). Our head tech has not got a clue and has tried everything he knows. Does anybody know of random booting issues that might occur in a network environment? Thanks.

  15. Stripes says:

    “Interesting to note that launchd is the more more modern approach, but from what I read init actually has advantages, mainly with the kernel.”

    I can’t think of any kernel level advantage of init vs. launchd. init runs a lot more processes, the rc scripts typically start programs serially. launchd allocates more network (and mach ports) then init, and then starts a bunch of stuff more or less all at once (and in many cases starts fewer things then the rc scripts).

    On some unix and unix like systems adopting a launchd like startup might cause a lot more disk thrashing and could result in a slower boot. On OS X there is some boot-time disk replay logic that pretty much keeps the disk from thrashing.

    launchd does use more kernel facilities then init did, but that is more because it pretty much does the job of /etc/rc, inetd and mach_init. None of those facilities are unusual (say select, or kqueue), just not used by init.

    I would far rather have launchd on OS X. On a system without a boot cache, it might not be as useful for fast booting (but it does have other advantages).

  16. […] OS X Daily » What happens in the Mac OS X boot process? – Mac OS X Apps, Tips, Tricks, News, Updates, Everything Mac OS X (tags: macosx) […]

  17. Spiderman Was Here says:

    Folks , You have too much free time to worry about this.

  18. […] final fantasy unlimited-vivid mp3 Long gone are the days of OS 9, watching our Macs boot up with a series of extensions and control panels that we could always identify. Today with the Unix underpinnings of 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? final fantasy hentai englishread more | digg story […]

  19. Alpharetta says:

    Interesting to note that launchd is the more more modern approach, but from what I read init actually has advantages, mainly with the kernel.

    I really don’t know anything

  20. Bush says:

    Say, Bill. Would you rub some of this powder on my lips?

  21. Digg sucks says:

    Yes, Digg SPAM! Go to a website, copy its contents, paste it into your BLOG, then SPAM DIGG and watch the money roll in as Diggtards click on Yahoo ads. Oh bummer, Diggtards don’t click on ads, they just show up en mass and then leave again.

    Next time, just link to the author, rather than ripping off his writing. What an asshole

  22. durin42 says:

    IIRC this is the boot sequence as of 10.3 machines – 10.4 doesn’t use init, but rather uses launchd in its place:
    imladris:~ durin$ ps axwwu | grep init
    durin 775 0.0 0.0 27364 436 p1 R+ 1:31PM 0:00.00 grep init
    imladris:~ durin$ ps axwwu | grep launchd
    root 35 0.0 0.2 28576 1756 ?? Ss 10:34PM 0:00.89 /usr/sbin/mDNSResponder -launchdaemon
    durin 777 0.0 0.0 27364 440 p1 S+ 1:31PM 0:00.00 grep launchd
    root 1 0.0 0.1 28352 560 ?? S

  23. jack says:

    Personal mac powerbook pro OS/X boots to logon panel in 18 seconds, less than 5 seconds to usable computer. Office Win 2k boots to logon panel in about 5 minutes, at least 3 more minutes to the desktop. you choose!!!

  24. winston smith says:

    Retard.

  25. Edwin says:

    OSX is very fast in loading up, unlike Windows Xp which takes forever. I hope Vista does a better job in this.

  26. The reason it’s good to know this is so that when something goes wrong very early in the boot process, you can get an idea of what’s wrong.

    For example, if the Apple logo doesn’ t show up, you never made it to BootX and the drive maybe bad.

  27. does any of this matter? its not like you can change anything really? I mean I guess the only difference between this and the way windows starts up is more of the components have a recognized name.

  28. sasi says:

    So , is it faster or better than upstart way of booting. as in Ubuntu?

  29. Hugh says:

    launchd?

  30. janson says:

    Anon, yes the intel uses EFI.

  31. anon says:

    are intel macs still using OF? I thought we were on EFI

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site