Managing Graphical Interfaces in CentOS 6.x
In older distributions like CentOS 6, system states are managed via runlevels. Runlevel 3 represents a multi-user command-line environment with networking, while runlevel 5 includes the X Window System for graphical output.
Temporary Runlevel Switching
To drop from a graphical session to a terminal-only session without rebooting, use the init command:
# Switch to command-line mode immediately
sudo init 3
# Switch back to graphical mode
sudo init 5
Persistent Configuration
To ensure the system boots into a specific mode by default, you must modify the initialization table located at /etc/inittab. Open the file with a text editor and locate the line defining the default runlevel:
# Find this line:
id:5:initdefault:
# Change it to 3 for command-line only:
id:3:initdefault:
Manual GUI Execution
If the system is in command-line mode and you need to launch the desktop environment manually for a single session, execute:
startx
Installing Desktop Environments
If your system was installed as a minimal server and lacks a GUI, you can install the necessary group packages using yum:
yum groupinstall "X Window System" -y
yum groupinstall "GNOME Desktop" "Graphical Administration Tools" -y
Managing Graphical Interfaces in CentOS 7.x
CentOS 7 utilizes systemd rather than SysVinit. While it still supports runlevel commands for backward compatibility, the standard approach involves managing "targets" and service units.
Disabling the Display Manager Service
The graphiccal login screen is typically handled by GDM (GNOME Display Manager). You can stop and disable this service to prevent the GUI from loading.
1. Switch to a virtual console using Ctrl + Alt + F2 and log in.
2. Stop the current display manager session:
sudo systemctl stop gdm
3. Prevent the service from starting automatically on boot:
sudo systemctl disable gdm
Using Systemd Targets (Recommended)
The idiomatic way to switch between CLI and GUI modes in CentOS 7 is by changing the default target.
# Set command-line mode (multi-user) as default
sudo systemctl set-default multi-user.target
# Set graphical mode as default
sudo systemctl set-default graphical.target
Re-enabling the Graphical Interface
To restore the desktop environment after it has been disabled via service management, run the following commmands:
sudo systemctl enable gdm
sudo systemctl start gdm
After enabling and starting the service, the GDM login screen should appear on your primary display (usually TTY1).