- Reference 29.1<br>System Initialization
- Reference 29.2<br>User Session
- Reference 29.3<br>Sleep Modes, Logout, and Shutdown
- Reference 29.4<br>Startup Shortcuts
- Reference 29.5<br>System Initialization Troubleshooting
- Reference 29.6<br>User Session Troubleshooting
- Exercise 29.1<br>Examine System Startup
- Exercise 29.2<br>Use Single-User Mod
Exercise 29.2
Use Single-User Mode
Prerequisite
If your computer has a Retina display, a magnifying glass may be necessary to read the text in single-user mode.
If your computer has a Retina display, a magnifying glass may be necessary to read the text in single-user mode.
When troubleshooting OS X startup issues that seem to be software-related, you might need to troubleshoot with the operating system started up in verbose or single-user mode. Verbose mode displays additional information about the startup and shutdown process, but does not change the normal operations of the computer. Single-user mode is a very primitive state of the operating system. The operating system has loaded only enough services to allow you to interact with it from the command line. It hasn’t even mounted the startup disk read/write yet. Single-user mode is a low-level maintenance mode that allows you to bring the system up, look at log files, edit or replace configuration files, and so on. In this exercise, you will start up your computer in verbose mode and then single-user mode, and then proceed to the user interface and identify various files used during startup.
If your computer has a Retina display, you may find that the text is too small to read easily in both verbose and single-user modes. In this case, using a magnifying glass is recommended.
Start up in Verbose Mode
- Before restarting in verbose mode, review the sequence you observed at the beginning of Exercise 29.1. In verbose mode, the basic startup sequence is the same, but what you will see on the screen is different.
- Restart your computer, and immediately hold down Command-V. Continue holding Command-V until you see text appear on the screen. When you reach the login window, log in as Chris Johnson.
- Fill in the table below with the sequence of cues you observe during a verbose startup, and contrast it with what you saw during a normal startup.
- Shut down your computer.
Normal startup |
Verbose startup |
Startup chime |
|
Gray screen with Apple logo |
|
Gray screen with Apple logo and spinning gear |
|
Arrow pointer appears |
|
Login screen |
|
Desktop and Dock appear |
|
During the verbose segment of the startup process, you will see messages from the kernel and LaunchDaemons describing what they are doing and any problems they encounter. The messages can be somewhat cryptic if you are not familiar with the details of the kernel and LaunchDaemon’s operations. What can you discern about what is happening “behind the scenes” as your computer starts up?
As your computer shuts down, you will see that it reenters verbose mode for a few moments. This occurs after the WindowServer shuts down, but before the kernel shuts down.
Use Single-User Mode
- Restart your computer, and immediately hold down Command-S. Continue holding Command-S until you see text appear on the screen.
- To force a check of the file system’s integrity, type in the command “/sbin/fsck -fy” and press Return.
- To remount the startup disk with write access enabled, type “/sbin/mount –uw /” and press Return.
- Test network connectivity from your computer to itself with the command “ping -c2 127.0.0.1”. Here, the -c2 means to try twice, and 127.0.0.1 is the address reserved for each computer to talk to itself with. The results look something like this:
- Get a process listing with the command “ps -ax”.
- Examine the system log file with the command “less +G /var/log/system.log”. Note that the command line is generally case sensitive, so it is important to capitalize the +G.
- When you are through examining the log, press “q” to exit.
Single-user mode starts off a lot like verbose mode, displaying information about the startup process. But unlike verbose mode, the startup process halts just after the system launchd starts. The graphical user interface does not start; instead, it gives you a full-screen command-line interface.
When your computer finishes starting up into single-user mode, OS X displays instructions on how to remount the startup disk read/write and how to continue the startup process to multiuser mode, the usual run mode of OS X or any other UNIX system.
Singleuser boot — fsck not done Root device is mounted read-only If you want to make modifications to files: /sbin/fsck -fy /sbin/mount -uw / If you wish to boot the system: exit :/ root#
The last line is a prompt for you to enter a command. Note that the user name in the prompt is “root” and the prompt ends with a # instead of the more usual $. This tells you that you are logged in as the super user (root, or System Administrator). You have unrestricted access to the startup volume and the rest of the system.
The computer runs a file system consistency check, correcting any errors that it finds and is able to repair. This is essentially the same as doing a Repair Disk in Disk Utility. On today’s large disks, this can take awhile, especially if there are many files and folders in the file system. This is one of the advantages of file-system journaling. Most of the time, a complete fsck does not need to occur, so startup is much faster.
If fsck displays “The volume Macintosh HD appears to be OK”, you may proceed to the next step. If its final message is “The filesystem was modified”, it found and fixed at least one issue, and you should re-run it to make sure there are no additional issues.
You are given a new prompt a few seconds later. This command enables you to make changes to the disk.
This command should not generate any output if all runs correctly. If it generates an alert, double-check your typing. The most common errors with this command are to leave off the trailing “/”, or to not have spaces where they are needed.
PING 127.0.0.1 (127.0.0.1): 56 data bytes ping: sendto: No route to host ping: sendto: No route to host Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 --- 127.0.0.1 ping statistics --- 2 packets transmitted, 0 packets received, 100.0% packet loss
Your computer cannot even reach itself via the network because networking has not been started.
You see a much shorter list than you previously saw in Activity Monitor. At process ID 1, you see the system launchd. Process ID 2 is launchctl, which launchd uses in this case to manage the startup process. Process ID 3 is the command shell with which you are interacting. The last process is your ps command. The OS is in a very minimal state.
The +G option to less tells it to start at the end of the file (that is, show the most recent log events). Usually, when you need to examine logs in single-user mode, it is because you want to find out what happened just before the system crashed, so starting at the end is more convenient than starting at the beginning. You can scan through the log by pressing “b” to move backward in the file, and pressing the Space bar to move forward.
Unfortunately, it does not know how large the screen is, so the display can get confused as you move backward and forward. The best way to fix this is to force it to redisplay the part you are interested in by backing up past it with the “b” key, then pressing the Space bar to display forward to the part you want to read.
Create a New Administrator Account
If you lose the password to your administrator account, you now know several ways to reset its password; but if the account becomes completely unusable, this will not allow you to regain control of the computer. In this section, you will see how to use single-user mode to create a new administrator account.
- Move to the /var/db folder with the command “cd /var/db”.
- Start typing the command “rm .AppleSe” (be sure to capitalize the “A” and “S”), but do not press Return yet.
- Press Tab.
- If the command autocompleted correctly, press Return to run it.
- If you see a message starting with “override”, type “y” and press Return.
- If you see the message “rm: .AppleSetupDone: Read-only file system”, the mount command in step 3 of the previous section did not work; reenter that command, and then try again from step 2 of this section.
- If the rm command does not display an error, exit single-user mode with the command “exit”.
- Step through the Setup Assistant screens (see Exercise 3.1 for detailed instructions). When you reach the “Create Your Computer Account” screen, enter the following information:
- Open System Preferences and select the Users & Groups pane.
- Quit System Preferences.
Your prompt changes to “:db root#”, indicating that you are now in a folder named “db.” If it does not match this, the command did not work right and you must try again before proceeding. This section of the exercise involves deleting files, and since you are running as the root user, you are capable of deleting anything (or everything). It is important to be careful when you are running commands as the root user.
If you typed the command correctly, it autocompletes to “rm .AppleSetupDone ”. If pressing Tab does not make it autocomplete, you have not typed the command correctly and must correct it and try again. Note that you cannot use the mouse to select text to change, although you can use the Left and Right Arrow keys to move backward and forward on the command line.
If you cannot get the command to autocomplete, something is still wrong and you should not proceed with the exercise. You can always press Control-C, and then use the command “exit” to exit single-user mode.
The /var/db/.AppleSetupDone file is a placeholder file, which indicates that the Setup Assistant has run on this computer; deleting it makes the computer re-run the Setup Assistant the next time it starts up.
The computer exits single-user mode and continues starting the operating system. With the .AppleSetupDone file gone, it runs the Setup Assistant again just as though this were a new computer.
Full Name: New Admin
Account Name: newadmin
If you are performing this exercise in a class, enter newadminpw in the Password and Verify fields. If you are performing this exercise on your own, you should select a more secure password for the New Admin account.
After you finish the Setup Assistant, you are automatically logged in to the New Admin account.
All of your old accounts are still there; New Admin has simply been added to them.