How to Disable GUI and Boot into Text Mode in RHEL 6 for Shell Scripting Practice


2 views

In Red Hat Enterprise Linux 6, system initialization is controlled by runlevels. The default GUI mode runs at runlevel 5, while pure text mode operates at runlevel 3. Here's how to verify your current runlevel:

# Check current runlevel
$ runlevel
N 5

# List all available runlevels
$ chkconfig --list | grep runlevel

To permanently disable the GUI and boot into text mode:

# Edit the /etc/inittab file
$ sudo vi /etc/inittab

# Change this line:
id:5:initdefault:
# To:
id:3:initdefault:

# Save and reboot
$ sudo reboot

If you need occasional access to text mode without permanent changes:

# Stop the GUI service (GNOME example)
$ sudo service gdm stop

# Or for KDE
$ sudo service kdm stop

# To restart GUI later
$ sudo service gdm start

After reboot, confirm you're in text mode:

# Check current runlevel
$ runlevel
N 3

# Verify no X server is running
$ ps aux | grep X

For pure shell scripting practice, consider:

# Create minimal .bashrc for scripting
$ cat > ~/.bashrc_clean <

If you need to restore the GUI later:

# Edit /etc/inittab again
$ sudo vi /etc/inittab

# Change back to:
id:5:initdefault:

# Reboot or start GUI service
$ sudo service gdm start

In Red Hat Enterprise Linux 6, the system uses traditional SysV init with defined runlevels. The key runlevels for this purpose are:

Runlevel 3 - Multi-user mode with networking (command line)
Runlevel 5 - Graphical mode with networking (default for most installations)

To permanently disable the GUI and boot directly to command line:

  1. Open the /etc/inittab file with your preferred text editor:
  2. vi /etc/inittab
    
  3. Locate the line specifying the default runlevel (typically near the top):
  4. id:5:initdefault:
    
  5. Change the number 5 to 3:
  6. id:3:initdefault:
    
  7. Save the file and exit
  8. Reboot for changes to take effect:
  9. reboot
    

If you want to switch to command line temporarily without changing the default runlevel:

init 3

To return to graphical mode later:

init 5

You can check your current runlevel with:

runlevel

Or more detailed system information with:

who -r

To prevent GUI services from starting even in runlevel 3:

chkconfig gdm off
chkconfig prefdm off

To verify these services are disabled:

chkconfig --list | grep -E 'gdm|prefdm'

Note that later RHEL versions use systemd. For completeness, here's the systemd equivalent:

systemctl set-default multi-user.target  # For command line
systemctl set-default graphical.target   # To revert back