How to boot Linux to command-line mode instead of GUI

bootcommand linerhel

I am using 32-bit Red Hat Linux in my VM. I want to boot it to command-line mode, not to GUI mode. I know that from there I can switch to GUI mode using startx command. How do I switch back to command-line mode?

Best Answer

Update: The answer below is now obsolete

For a lot of distros now, the default is systemd rather than sysvinit. The answer below was written with sysvinit in mind. The more-up-to-date answer (and the one you should use if you have systemd as your init system) is golem's answer.

sysvinit answer (obsolete on most current distros):

You want to make runlevel 3 your default runlevel. From a terminal, switch to root and do the following:

[user@host]$ su
Password:
[root@host]# cp /etc/inittab /etc/inittab.bak #Make a backup copy of /etc/inittab
[root@host]# sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab #Make runlevel 3 your default runlevel

Anything after (and including) the second # on each line is a comment for you, you don't need to type it into the terminal.

See the Wikipedia page on runlevels for more information.

Explanation of sed command

  • The sed command is a stream editor (hence the name), you use it to manipulate streams of data, usually through regular expressions.
  • Here, we're telling sed to replace the pattern id:5:initdefault: with the pattern id:3:initdefault: in the file /etc/inittab, which is the file that controls your runlevles. The general syntax for a sed search and replace is s/pattern/replacement_pattern/.
  • The -i option tells sed to apply the modifications in place. If this were not present, sed would have outputted the resulting file (after substitution) to the terminal (more generally to standard output).

Update

To switch back to text mode, simply press CTRL+ALT+F1. This will not stop your graphical session, it will simply switch you back to the terminal you logged in at. You can switch back to the graphical session with CTRL+ALT+F7.

Related Question