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?
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.
sedcommand is a stream editor (hence the name), you use it to manipulate streams of data, usually through regular expressions.
- Here, we're telling
sedto 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
sedsearch and replace is
sedto apply the modifications in place. If this were not present,
sedwould have outputted the resulting file (after substitution) to the terminal (more generally to standard output).
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.
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
First switch user to root.
su - Password:
Enter root password.
Use your favorite editor to modify this line in
Change the 5 to 3. When you (re)boot the computer it will take you to the command line rather than to the GUI.
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
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).
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.
After replace the default runlevel to
/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!
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:
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
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 .
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!
systemctl set-default multi-user.target
and reboot the VM. The VM will get into CLI mode.