LINFO

How to Change to Single User Mode



Single user mode, also referred to as maintenance mode and runlevel 1, is a way of running Linux or another Unix-like operating system that uses minimal system resources and provides only minimal functionality.

Single user mode can be useful for checking and repairing operating systems, particularly those that have been damaged and will not allow booting (i.e., starting up) into the default GUI (graphical user interface) or console (i.e., text-only) multi-user mode. For example, it is used for running fsck (which is used to check and repair filesystems) on a /usr partition because this requires that the partition be unmounted (i.e., not logically attached to the system). A partition is a logically independent section of a hard disk drive (HDD).

A runlevel is any of several operating states of a computer, each allowing the operation of a different set of services. By default Linux boots into either runlevel 3 or runlevel 5. The former permits the system to run all services except for a GUI. The latter allows all services including a GUI. The previous and current runlevels can be found at any time by running the runlevel command as follows:

/sbin/runlevel

There are several ways to change into single user mode. It is easiest to do while the computer is already in operation. All that is necessary is for the root (i.e., administrative) user to run the init command, which is used to change the runlevel, using the number the letter s or the number 1 as an option as follows:

/sbin/init 1

It will be obvious when single user mode has been entered. This is particularly true in the likely case that the user was working in a GUI, as the GUI will be shut down and the computer will be in console mode. Also, there will typically be a change in the shell from bash (the default on Linux) to sh, which features a small size and minimal functionality, and this will be indicated by a change in the command prompt (i.e., the short text message at the start of each line). A shell is a program that provides a text-only user interface and reads and executes commands that are typed in.

It is also possible to boot directly into single user mode, although this is slightly more complicated. If the GRUB (grand unified boot loader) is used (as is typical on modern versions of Linux), the first step is to wait for the GRUB splash screen (i.e., full-screen image) to appear and then (1) enter the letter p from the keyboard followed by the password if a password has been set for GRUB. This step can be ignored if no password has been set for GRUB (which is not wise for systems which might be physically accessible to unauthorized people, as this creates a serious security hole).

The second step is to (2) select the desired operating system or version of the desired kernel (i.e., the core of the operating system) for booting using the up and down arrow keys and then type the letter e. This results in a choice of lines of text appearing that start with the words root, kernel and initrd.

The third step is to (3) select the line that starts with the word kernel and type e again. This replaces the text with a new line that begins with grub edit>.

The next step is to (4) type a space followed by the word single at the end of the line starting with grub edit> and then press the ENTER key. This causes the previous text to reappear.

The final step is to (5) type the letter b. This causes the system to boot in what looks like a normal booting process. However, booting only continues to a level sufficient for the operation of single user mode.

It is very easy to return to the previous runlevel or continue booting into the default runlevel after the checks and/or repairs have been made. One way is to use the init command again, followed by the runlevel desired, as follows:

/sbin/init 5

Another way is to simultaneously press the CONTROL and d keys. In addition, a computer should return to its former runlevel when rebooted, although this can take substantially more time, which can be an important consideration on enterprise systems.






Created July 13, 2006.
Copyright © 2006 The Linux Information Project. All Rights Reserved.