How to boot Linux to command-line mode instead of GUI?
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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
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:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f481879186b49c9b8780">[email protected]</a>]$ su Password: [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25574a4a51654d4a5651">[email protected]</a>]# cp /etc/inittab /etc/inittab.bak #Make a backup copy of /etc/inittab [<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d3f2222390d25223e39">[email protected]</a>]# 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 patternid:5:initdefault:
with the patternid:3:initdefault:
in the file/etc/inittab
, which is the file that controls your runlevles. The general syntax for ased
search and replace iss/pattern/replacement_pattern/
. - The
-i
option tellssed
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.
Method 3
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.
Method 4
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).
Method 5
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.
Method 6
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
Method 7
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!
Method 8
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 .
Method 9
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!
Method 10
Use
systemctl set-default multi-user.target
and reboot the VM. The VM will get into CLI mode.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0