Previous Section  < Day Day Up >  Next Section

Recipe 7.2. Changing Runlevels After Bootup

7.2.1 Problem

Somewhere during the installation of your Linux system, you selected either "boot to text mode" or "boot to graphical mode." Maybe you didn't quite understand what these options meant—or maybe you did, but now you want a nice graphical interface instead of a boring text-only console. Or you're having problems with the graphical interface, and want to drop to a runlevel with minimal services for troubleshooting.

7.2.2 Solution

Use init. First, check what runlevel you are in:

# /sbin/runlevel

N 5

The N means you have not previously booted to a different runlevel. If you had, the number of the runlevel would be displayed. You must be root to change the runlevel:

# /sbin/init 3

This will stop all runlevel 5 services, then start up the runlevel 3 services. It's like doing a partial reboot. All users will be logged out.

Sometimes you need to change to runlevel 1 to get out of trouble:

# /sbin/init 1

This stops X and drops you to a root shell, with limited services and no X. On Red Hat, you don't need to supply the root password after dropping to runlevel 1, so don't give any sudo users init access.

7.2.3 Discussion

In Red Hat, Fedora, Mandrake, and Slackware, changing runlevels is one way to kill an X session, because runlevel 3 boots to a text console. However, it's rather drastic, as it stops and restarts all services and boots out all logged-in users.

Why change runlevels with init? Here are some good reasons:

  • To drop to runlevel 1 for troubleshooting and repairs.

  • To stop or reboot the system when normal methods don't work.

  • To restart all services, or to switch to a different set of services.

Bad reasons include:

  • To change from a text console session to an X session, because init must be run as root, and running an X session as root is a very bad idea. It's insecure, and it's too easy to inadvertently make mistakes and mess up your system.

  • To exit an X session.

There are other, better ways to manage switching between X sessions and console sessions, as you'll see in Recipe 7.4, Recipe 7.4.

telinit works too, as it's simply a hard link to init ("tell init"—more clever geek wordplay):

$ ls -al /sbin/telinit

lrwxrwxrwx    1 root    root    4 Oct 31 07:51 /sbin/telinit -> init

7.2.4 See Also

  • init(8)

  • Recipe 7.4

  • Chapter 5 of Running Linux, by Matt Welsh, Mattias Dalheimer, Terry Dawson, and Lar Kaufman (O'Reilly)

  • Chapter 10 of LPI Linux Certification in a Nutshell

    Previous Section  < Day Day Up >  Next Section