start page | rating of books | rating of authors | reviews | copyrights

Book HomeMac OS X for Unix GeeksSearch this book

Chapter 2. Startup

Contents:

Booting Mac OS X
Adding Startup Items
Scheduling Tasks

The 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.

[5]Mach is a microkernel operating system developed at Carnegie Mellon University. The Mac OS X kernel, xnu, is a hybrid of Mach and BSD.

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 X

When 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 Figure -V as you start the computer. To boot in single-user mode, hold down Figure -S as you start the computer.

2.1.1. The BootX Loader

BootX 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. Initialization

The 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 Scripts

The 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/hostconfig

SSHSERVER=-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.

What Is kextd?

The kernel boots with the minimum set of extensions needed to mount the root filesystem on all supported hardware. Some of these extensions are not needed, so /etc/rc starts the kextd daemon (/usr/libexec/kextd) to unload unnecessary extensions. For example, the iPodDriver includes the OSBundleRequired key to support booting from your iPod. If you don't have your iPod plugged in, kextd can safely unload that driver. The kextd daemon is also responsible for loading and unloading extensions for the duration of the system's uptime.

2.1.4. SystemStarter

SystemStarter 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

Item

Description

Accounting

Starts the acct daemon, which collects process accounting records.

Apache

Starts the Apache web server. Enable this with the WEBSERVER entry in /etc/hostconfig or by turning on Web Sharing (System Preferences Figure Sharing).

AppServices

Starts the desktop database, input managers, and printing services.

AppleShare

Starts Apple file sharing. Enable this with the AFPSERVER entry in /etc/hostconfig or by turning on File Sharing (System Preferences Figure Sharing).

AppleTalk

Starts the AppleTalk protocol. Enable this with the APPLETALK entry in /etc/hostconfig.

AuthServer

Starts the authentication server. Enable this with the AUTHSERVER entry in /etc/hostconfig.

BIND

Starts named, the Internet domain name server, if DNSSERVER is set to -YES- in /etc/hostconfig.

ConfigServer

An empty startup script that maintains compatibility with earlier versions of Mac OS X, where this script was used to configure the network.

CoreGraphics

Starts the font and window server.

CrashReporter

Enables automatic crash report generation when an application crashes. Enable this with the CRASHREPORTER entry in /etc/hostconfig or by selecting Log crash information in the Crashes panel of the Console application's Preferences (the Console application is located in /Applications/Utilities).

Cron

Starts the cron daemon.

DirectoryServices

Starts lookupd, a daemon through which Directory Services is accessed.

Disks

Mounts local filesystems.

HeadlessStartup

Functions as a special startup routine used by headless servers, such as the XServe. Mac OS X Server only.

IPAliases

Sets up IP Aliasing (assigns multiple IP addresses to single physical adapter). Mac OS X Server only. Enable this with the IPALIASES entry in /etc/hostconfig. See the IPAliases(5) manpage.

IPFailover

Starts a service that allows a server to take over for another server in case it fails. Mac OS X Server only.

IPServices

Starts inetd and, optionally, the bootp service.

LDAP

Starts slapd, the standalone LDAP daemon.

LoginWindow

Does nothing except to note the point at which the system is ready to display the login window. This is a placeholder service.

mDNSResponder

Starts the multicast DNS responder, which is used by Rendezvous for configuration.

MySQL

Functions as a startup script for MySQL. Mac OS X Server only. Enable this with the MYSQL entry in /etc/hostconfig.

NFS

Starts the NFS client. The server is also started if NetInfo or /etc/exports has been configured to export one or more filesystems.

NIS

Starts the Network Information Service unless NISDOMAIN is set to -NO- in /etc/hostconfig.

NetInfo

Starts NetInfo. If the NETINFOSERVER entry is set to -YES- in /etc/hostconfig, this will start up the nibindd daemon, which will start one or more NetInfo servers. If the entry is set to -AUTOMATIC- (the default), this will not start nibindd and will only start the local NetInfo server.

Network

Configures network interfaces and the hostname. If IPFORWARDING is enabled in /etc/hostconfig, this script also enables IP forwarding.

NetworkExtensions

Loads various networking extensions.

NetworkTime

Starts the NTP client. Enable this with the TIMESYNC entry in /etc/hostconfig or with System Preferences Figure Date & Time Figure Network Time.

Portmap

Starts the portmap daemon. Enable this with the RPCSERVER entry in /etc/hostconfig.

PrintingServices

Starts the Common Unix Printing System (CUPS).

QuickTimeStreamingServer

Starts the QuickTime Streaming Server. Mac OS X Server only. Enable this with the QTSSERVER entry in /etc/hostconfig.

SNMP

Starts snmpd, the SNMP daemon. Mac OS X Server only. Enable this with the SNMPSERVER entry in /etc/hostconfig.

SSH

Starts sshd. Enable this with the SSHSERVER entry in /etc/hostconfig or by enabling remote login in System Preferences Figure Sharing.

Samba

Starts the Samba service, which provides file services to Windows clients.

SecurityServer

Starts security services.

Sendmail

Starts sendmail. Enable this with the MAILSERVER entry in /etc/hostconfig.

SerialTerminalSupport

Supports serial terminals for headless servers. Mac OS X Server only. See the SerialTerminalSupport script for configuration information.

ServerManagerDaemon

Starts the Server Manager daemon. Mac OS X Server only. Enable this with the SERVERMANAGERSERVER entry in /etc/hostconfig.

SystemLog

Starts syslogd.

SystemTuning

Tunes the system based on details of your hardware configuration (such as the amount of installed memory).

VPN

Starts the VPN server. Mac OS X Server only. Enable this with the VPNSERVER entry in /etc/hostconfig.

Watchdog

Starts the watchdog service, which monitors and restarts critical services when they quit unexpectedly. See the watchdog(8) manpage. Mac OS X Server only.

2.1.5. The Login Window

Once SystemStarter is finished, control is returned to init, which launches getty. In /etc/ttys, the console entry launches the Login Window (/System/Library/CoreServices/loginwindow.app). At this point, the system is fully functional and ready to accept logins.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.