Mac OSX Boot Process
From:
![]()
http://developer.apple.com/techpubs/macosx/Essentials/SystemOverview/BootingLogin/index.html?http://developer.apple.com/techpubs/macosx/Essentials/SystemOverview/BootingLogin/The_Boot_Sequence.html
BootROM
When the power to a Macintosh computer is turned on, the BootROM firmwareis the first code activated. BootROM (which is part of the computer’s hardware)has two primary responsibilities: to initialize system hardware and to selectan operating system to boot. BootROM has two components to help it carryout these functions:
- POST (Power-On Self Test) initializes some hardware interfacesand verifies that sufficient RAM memory is available and is in a good state.
- Open Firmware initializes the rest of the hardware, builds theinitial device tree (a hierarchical representation of devices associatedwith the computer), and selects the operating system to use.
The same version of BootROM can start either Mac OS 9 or Mac OS X.
BootX
When BootROM (or the user) selects Mac OS X as the operating systemto boot, control passes to the BootX booter (located in /System/Library/CoreServices). BootX’s principal duty is to load the kernel environment. As it does this,BootX draws the “booting” image on the screen.
When loading the kernel environment, BootX first attempts to loada previously cached set of device drivers (called an mkext cache) for hardwarethat is involved in the boot process. If this cache is missing or corrupt,BootX searches /System/Library/Extensions for drivers and otherkernel extensions whose OSBundleRequired property is set to a valueappropriate to the type of boot (for example, local or network boot). Seethe kernel developer documentation for more on the OSBundleRequiredkey and the loading of device drivers during booting.
Once the kernel and all drivers necessary for booting are loaded,BootX starts the kernel’s initialization procedure. At this point, enoughdrivers are loaded for the kernel to find the root device. Also from thispoint, Open Firmware is no longer accessible.
The kernel initializes the Mach and BSD data structures and then initializesthe I/O Kit. The I/O Kit links the loaded drivers into the kernel, usingthe device tree to determine which drivers to link. Once the kernel findsthe root device, it roots BSD off of it.
Finally, the kernel starts the mach_init process. The mach_initprocess is the Mach bootstrap port server, which enables Mach messaging.
After the root file system is mounted, system initialization proceedsto run the system startup items and launch any system daemons (see “System Initialization”).
System Initialization
The mach_init process starts the BSD init process. This latter process, which has a process ID (PID) of 1, “owns” every otherprocess on the system. Despite its centrality, the init process issimple. It performs four principal tasks:
- It determines if the user wants single-user mode or is bootingfrom a CD-ROM. If either of these conditions apply, an advisory is printedand control is handed over to the user.
- It runs the system-initialization shell scripts—/etc/rc.bootand /etc/rc—which complete basic initialization tasks; for details,see “Therc.boot and rc Scripts”.
The /etc/rc script runs the SystemStarter program, which handles more specialized initialization tasks specified as “startupitems”; for details, see “StartupItems”.
- Via the getty command, init launches the loginwindowapplication, which displays the login window and manages the user login procedure;for details, see “Managing User Sessions”.
- As the parent of all processes, init handles all necessarycleanup of system processes as they terminate.
Although the init process owns every other process on thesystem, a distinction can still be made between user and system processes.Startup items and any applications run prior to the loginwindow applicationform the group of system processes. These applications provide services toall users of the system and are usually children of the init process.Processes created after the launching of loginwindow form the group of user processes. User processes are always associated with a particular user sessionand are usually children of the Window Manager process of the user’ssession.
Note: Not all user processes are children of the Window Manager process. Processes launched as root and some special systemprocesses are owned by the user but are children of the init process. You can use the Process Viewer application to determine the owner and parentof any process on the system.
Managing User Sessions
During the system initialization cycle, the init process launchesthe loginwindow application to manage user sessions. The loginwindow applicationdisplays the login window and provides several services on behalf of theuser. This section discusses those services and the user environment providedby loginwindow.
Logging In
The loginwindow application coordinates the login process and usersession, calling on other system services as needed. Depending on the user’slogin preferences, loginwindow may prompt the user for a valid login nameand password or use cached values to log the user in automatically. Whenthe user’s login name and password have been authenticated (see “Authenticating Users”), loginwindow proceeds to loadthe user environment.
When a user logs in, loginwindow does the following:
- Loads the user’s computing environment (including preferences,environment variables, device and file permissions, keychain access, andso on). See “Setting Up the User Environment” for more information.
- Launches the Dock, Finder, and SystenUIServer.
- Launches the Setup Assistant if an installation is in progress.
- Automatically launches applications specified in the Login ItemsSystem Preferences.
When all of the specified applications are launched and running, thelogin procedure is complete.
The loginwindow application uses Launch Services to launch all applications,including the Finder, Dock, SystemUIServer, and user-specified applications.Most applications in the user session run as child processes of the WindowManager process, not loginwindow.
If the Finder or Dock processes die for some reason, loginwindow automaticallylaunches them again. In the same vein, if the loginwindow application dies,the init process automatically restarts it.
Once the user session is up and running, loginwindow monitors thesession and user applications in the following ways:
- Manages the logout, restart, and shutdown procedures. See “Logging Out” for more information.
Authenticating Users
Mac OS X requires user authentication prior to accessing the system.Although the loginwindow application manages the user authentication process,it does not authenticate the user itself. The loginwindow application takesthe user information specified in the login screen and passes it to DirectoryServices for authentication. As soon as Directory Services authenticatesthe user, loginwindow initiates the user session.
The loginwindow application does not prompt the user for login informationif the “Enable automatic log in” option is selected. Only one user at a timemay enable this option from the Users pane of the Accounts System Preferences.From this same pane, the user must also enter a valid password by clickingthe Set Auto Login control.