Chapter 2. StartupThe most striking difference between Mac OS X and other flavors of Unix is in how Mac OS X handles the boot process. Gone are /etc/inittab, /etc/init.d, and /etc/rc.local from traditional Unix systems. In their place is a BSD-like startup sequence sandwiched between a Mach[5] foundation and the Aqua user interface.
This chapter describes the Mac OS X startup sequence, beginning with the BootX loader and progressing to full multiuser mode, at which time the system is ready to accept logins from normal users. The chapter also covers custom startup items, network interface configuration, and Mac OS X's default cron jobs. 2.1. Booting Mac OS XWhen the computer is powered up, the firmware is in complete control. After the firmware initializes the hardware, it hands off control to the BootX loader, which bootstraps the kernel. After a trip into Mach, the control bubbles up into the BSD subsystem, and eventually into the Aqua user interface. By default, Mac OS X boots graphically. If you'd like to see console messages as you boot, hold down -V as you start the computer. To boot in single-user mode, hold down -S as you start the computer. 2.1.1. The BootX LoaderBootX is located in /System/Library/CoreServices. It draws the Apple logo on the screen and proceeds to set up the kernel environment. BootX first looks for kernel extensions (drivers, also known as kexts) that are cached in the mkext cache. If this cache does not exist, BootX loads only those extensions in /System/Library/Extensions that have the OSBundleRequired key in their Info.plist file. Each extension lives in a folder (ExtensionName.kext), and the Info.plist file is an XML document that resides in its Contents subfolder. Example 2-1 is an excerpt from the /System/Library/Extensions/System.kext/Contents/Info.plist file. Example 2-1. A portion of a kernel extension's Info.plist file<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <!-- multiple keys and strings omitted --> </dict> </plist> After the required drivers are loaded, BootX hands off control to the kernel (/mach_kernel). 2.1.2. InitializationThe kernel first initializes all the data structures needed to support Mach and BSD. Next, it initializes the I/O Kit, which connects the kernel with the set of extensions that correspond to the machine's hardware configuration. Then, the kernel finds and mounts the root filesystem. The kernel next loads mach_init, which starts Mach message handling. mach_init then launches the BSD init process. In keeping with Unix conventions, init is process ID (PID) 1, even though it was started second. mach_init is given PID 2, and its parent PID is set to 1 (init's PID). 2.1.3. The rc ScriptsThe init process launches the /etc/rc.boot and /etc/rc shell scripts to start the system. Both rc scripts (and all startup items) source the /etc/rc.common script, which sets the initial environment, defines some useful functions, and loads the /etc/hostconfig file. /etc/hostconfig controls which system services need to be started and defines such things as the AppleTalk hostname. Example 2-2 is an excerpt from the hostconfig file. Example 2-2. A portion of /etc/hostconfigSSHSERVER=-YES- WEBSERVER=-YES- APPLETALK_HOSTNAME=*427269616e204a6570736f6ed57320436f6d7075746572* This excerpt shows that sshd and httpd will be started on "Brian Jepson's Computer" (the decoded AppleTalk hostname) at startup. The AppleTalk hostname is encoded as a sequence of hexadecimal bytes (for example, 42=B, 72=r, 69=i, 61=a, and 6e=n). After rc.boot has loaded in values from /etc/rc.common, it determines whether the system is booting from a CD. Next, rc.boot tests to see whether the system is booting in single-user mode. If the system is neither in single-user mode nor booting from a CD, then rc.boot performs a check of the filesystem (fsck). If the fsck fails, then rc.boot tries an fsck -y, which assumes a "Yes" answer to all the questions that fsck asks. If that fails, the system reboots (and may end up trying an fsck -y over and over again). TIP: If you find yourself in an fsck loop, you should boot from the Mac OS X installation CD. You can boot from a CD by holding down the C key at startup. When the Installer appears, choose Disk Utility from the Installer menu and use it to inspect and repair the damaged disk. If rc.boot succeeds, init drops into a shell (for single-user mode) or launches /etc/rc (for installation or multiuser mode). In single-user mode, only the root user may log in. In multiuser mode, the system is fully functional and ready to accept logins from normal users. If /etc/rc determines that the system is booting from a CD, it starts the Mac OS X installation program. (If you booted from a CD in single-user mode, you'll get dropped into a shell and /etc/rc won't get run.) Otherwise, /etc/rc mounts local filesystems and starts kextd, the kernel extension daemon. After that, it starts the Window Server and the update process (which flushes the filesystem buffers every 30 seconds). Finally, /etc/rc enables the swap file, sets the language for the system, and hands off control to /sbin/SystemStarter. 2.1.4. SystemStarterSystemStarter examines /System/Library/StartupItems and /Library/StartupItems for applications that should be started at boot time. /Library/StartupItems contains items for locally installed applications; you can also put your own custom startup items there. /System/Library/StartupItems contains items for the system. You should not modify these or add your own items here. Table 2-1 lists Mac OS X's available startup items. Table 2-1. Mac OS X default startup items
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|