26

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?

10 Answers 10

23

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.

  • Thanks for the answer. Also, when I switch to GUI using startx how can I switch back to command line? – Don't You Worry Child Sep 13 '13 at 19:19
  • 1
    @0xF1 Added an explanation for the sed command. – Joseph R. Sep 13 '13 at 19:31
  • 1
    I would generally advise against using sed on configuration files, unless you know exactly what you are doing. The line in question might be also a comment and yet would still be changed. Hence the regular expression should be more precise, at least require the string id:... to be at the beginning of the line. Since the man page doesn't say anything about how white spaces are treated, you probably want to use s/^ *id:5:initdefault: (which doesn't include Tab character, by the way). – peterph Sep 14 '13 at 8:19
  • 1
    This answer is no longer valid, at least on my current OS. Take a look at @golem's answer below. That worked for me. I'm using fedora 27. – Lance Mar 22 '18 at 14:52
  • 1
    @Lance Very good point. Thanks for the notice. I have updated my answer to reflect that. – Joseph R. Mar 22 '18 at 20:05
24

Update for RedHat/CentOS 7 that has switched from sysvinit to systemd.

To switch from GUI to CLI: systemctl isolate multi-user.target

To switch from CLI to GUI: systemctl isolate graphical.target

To set the CLI as a default runlevel (target in systemd terminology): systemctl set-default multi-user.target. Analogously for GUI: systemctl set-default graphical.target

*CLI = Command Line Interface = command-line mode

11

First switch user to root.

su -
Password:

Enter root password.

Use your favorite editor to modify this line in /etc/inittab:

id:5:initdefault:

Change the 5 to 3. When you (re)boot the computer it will take you to the command line rather than to the GUI.

  • Please include instructions about how the OP should do this as root and to which file. This answer, as it stands, is not fit to help someone who's new to Linux. – Joseph R. Sep 13 '13 at 19:06
  • 1
    Thank you for pointing out my oversight. I have edited the answer accordingly. – Timothy Martin Sep 13 '13 at 19:20
  • Does this mean that the GUI is not running, or is it hidden? – Aaron Franke Jan 12 '18 at 8:57
  • @AaronFranke For Redhat systems in run level 3 the GUI is not enabled (or turned off in the case of a system which was switched from runlevel 5 to 3 without a reboot). – Timothy Martin Jan 12 '18 at 9:10
3

Apart from changing /etc/inittab, you can also tell the kernel on its command line what target runlevel should be passed to init once it is started. This is done by simply appending the desired runlevel to the command line (it has to be the last argument I believe).

You can do this either as a one-off thing during boot, provided your bootloader allows you to change the kernel command line, or you can duplicate entry in the bootloader configuration and pick the right one when booting (useful when you are booting into various runlevels often).

For systems using systemd the process is similar, but means more typing since the magic string appended to the kernel command line is in the form of systemd.unit=desired.target.

As for startx, it can also start additional sessions by giving it an unused X display number (numbering starts from 0): startx -- :1 will start X server on display :1, locating it at the first unused VT (often VT8, since first 6 are usually Linux consoles and 7 is used by the first running X session). Note that the X server usually needs root privileges so you either have to do this as root (which is not a good idea), or the binary has to be setuid root (the need for this is normally removed by using a display manager).

  • +1 Great answer. Not very newbie friendly, though. – Joseph R. Sep 14 '13 at 8:19
  • Yes, changing inittab makes much more sense, since one usually wants to bring up the system to the same state all the time. – peterph Sep 14 '13 at 8:21
2

On a side note, if you've already booted into graphical mode and would like to switch to text mode, you could just press Ctrl + Alt + F1 and back again to graphical mode by Ctrl + Alt + F7.

Linux has by default 6 text terminals and 1 graphical terminal. You can switch between these terminals by pressing Ctrl + Alt + Fn. Replace n with 1-7. F7 would take you to graphical mode only if it booted into run level 5 or you have started X using startx command; otherwise, it will just show a blank screen on F7.

  • show this work in RHEL 7? – javapowered Nov 8 '14 at 8:37
0

After replace the default runlevel to id:3:initdefault: in /etc/inittab using your preferred text editor (as said previously), it's very important check if there's some plymouth (splash screen) installed in your system. In this case, will be need to remove the installation of it, or just remove the splash keyword from you /boot/grub/grub.cfg using your preferred text editor (vim, pico, or others). To remove plymouth:

sudo apt-get remove --purge plymouth

Edit your grub.cfg:

sudo vim /boot/grub/grub.cfg

Finally, upgrade the grub configuration:

sudo update-initramfs -u

In next boot, you'll have just text mode login screen. That's it.

Enjoy Linux box!

0

Even being a quite old thread, may be useful. On system using systemd, /etc/inittab is no longer in use. The method is quite simple:

Terminal mode

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

Graphic Mode

ln -sf /lib/systemd/system/graphical.target  /etc/systemd/system/default.target
-1

The oracle-linux 7 installation by defaults takes minimal installation option . You must change it to installation with GUI mode at the time of installation .This has solved my issue on not able to use the graphical user mode .

  • It seems you have the OP's request backwards. The OP appears to be struggling to get to the CLI, not to the GUI. – HalosGhost Feb 11 '15 at 13:32
-1

I've tried systemctl, update-rc.d and even editing the GRUB config, but nothing worked. Then I commented out the default display manager in /etc/X11/default-display-manager, rebooted and finally: the terminal!!!! It's as simple as that!

-1

Use

systemctl set-default multi-user.target

and reboot the VM. The VM will get into CLI mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.