Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Apple > Operating Systems

  • Print
  • + Share This
From the book Exercise 29.2

Exercise 29.2
Use Single-User Mode


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

  1. 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.
  2. 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.
  3. 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.
  4. 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?

  5. Shut down your computer.

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

  1. Restart your computer, and immediately hold down Command-S. Continue holding Command-S until you see text appear on the screen.
  2. 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:
    :/ 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.

  3. To force a check of the file system’s integrity, type in the command “/sbin/fsck -fy” and press Return.
  4. 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.

  5. To remount the startup disk with write access enabled, type “/sbin/mount –uw /” and press Return.
  6. 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.

  7. Test network connectivity from your computer to itself with the command “ping -c2”. Here, the -c2 means to try twice, and is the address reserved for each computer to talk to itself with. The results look something like this:
  8. PING ( 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
    --- 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.

  9. Get a process listing with the command “ps -ax”.
  10. 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.

  11. 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.
  12. 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.

  13. When you are through examining the log, press “q” to exit.

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.

  1. Move to the /var/db folder with the command “cd /var/db”.
  2. 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.

  3. Start typing the command “rm .AppleSe” (be sure to capitalize the “A” and “S”), but do not press Return yet.
  4. Press Tab.
  5. 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.

  6. If the command autocompleted correctly, press Return to run it.
  7. If you see a message starting with “override”, type “y” and press Return.
  8. 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.
  9. If the rm command does not display an error, exit single-user mode with the command “exit”.
  10. 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.

  11. 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:
  12. 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.

  13. Open System Preferences and select the Users & Groups pane.
  14. All of your old accounts are still there; New Admin has simply been added to them.

  15. Quit System Preferences.
  • + Share This
  • 🔖 Save To Your Account