Why I can't use 'startx' command to start X Server on RHEL7 with "X window system" package group?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 7
  • xorg-x11-xinit-1.3.2-14.el7.x86_64

Issue

  • Can't start the X server using the startx command, while the basic xinit command works.

  • The server is running RHEL7, installed as a minimal server, only the core and "X window system" package group plus xterm are installed. But when try to run startx command, it fails with following error:

       xinit: connection to X server lost
    
       waiting for X server to shut down (EE) Server terminated successfully (0). 
       Closing log file.
    
  • xinit command without any options starts fine, but startx with the default RHEL7 system xinitrc script fails. What is causing this problem?

Resolution

Note: This solution only applies if you are intending to use 'twm' or 'mwm' graphical environments. For questions regarding installing a full-feature GUI, such as Gnome, please see How to install a graphical user interface (GUI) for Red Hat Enterprise Linux

  • Install "motif" package on system and replace /usr/bin/twm with /usr/bin/mwm in /etc/X11/xinit/xinitrc and /etc/X11/xinit/Xclients both files.
    Eg:

  • The /etc/X11/xinit/xinitrc file after replacing /usr/bin/twm with /usr/bin/mwm should have following entry:

    <snip>
    if [ -f $HOME/.Xclients ]; then
    exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients || \
    exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients elif [ -f /etc/X11/xinit/Xclients ]; then
    exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients || \
    exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients else
    # Failsafe settings.  Although we should never get here
    # (we provide fallbacks in Xclients as well) it can't hurt.
    [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
    [ -x /usr/bin/xclock ] && /usr/bin/xclock -geometry 100x100-5+5 &
    [ -x /usr/bin/xterm ] && xterm -geometry 80x50-50+150 &
    [ -x /usr/bin/mwm ] && /usr/bin/mwm
    fi
    </snip>
    
  • The /etc/X11/xinit/Xclients script file after replacing /usr/bin/twm with /usr/bin/mwm should have following entry:

        <snip>
        # Failsafe.
        # these files are left sitting around by TheNextLevel.
        rm -f $HOME/Xrootenv.0
     
        # Argh! Nothing good is installed. Fall back to twm {
        # gosh, neither fvwm95 nor fvwm2 is available; 
         # fall back to failsafe settings
         [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
    
         if [ -x /usr/bin/xclock ] ; then
    	 /usr/bin/xclock -geometry 100x100-5+5 &
         fi
         if [ -x /usr/bin/xterm ] ; then
            /usr/bin/xterm -geometry 80x50-50+150 &
         fi
         if [ -x /usr/bin/firefox -a -f /usr/share/doc/HTML/index.html ]; then
    	/usr/bin/firefox /usr/share/doc/HTML/index.html &
         fi
         if [ -x /usr/bin/mwm ] ; then
    	exec /usr/bin/mwm
         fi
         }
        </snip>
    
  • After above changes try to run startx command.

Root Cause

  • The startx script is a front end to xinit. To determine the client to run, startx first looks for a file called .xinitrc in the user's home directory. If that is not found, it uses the file xinitrc in the xinit library directory(/etc/X11/xinit/). The /etc/X11/xinit/xinitrc file have following entry:

       <snip>
    
       if [ -f $HOME/.Xclients ]; then
          exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients || \
          exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients
       elif [ -f /etc/X11/xinit/Xclients ]; then
          exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients || \
          exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients
       else
         # Failsafe settings.  Although we should never get here
         # (we provide fallbacks in Xclients as well) it can't hurt.
         [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
         [ -x /usr/bin/xclock ] && /usr/bin/xclock -geometry 100x100-5+5 &
         [ -x /usr/bin/xterm ] && xterm -geometry 80x50-50+150 &
         [ -x /usr/bin/twm ] && /usr/bin/twm
       fi
       </snip>
    

In above output we can see that /etc/X11/xinit/Xclients script is being called.

  • The /etc/X11/xinit/Xclients script have following entry:

      <snip>
      # Failsafe.
      # these files are left sitting around by TheNextLevel.
      rm -f $HOME/Xrootenv.0
      # Argh! Nothing good is installed. Fall back to twm
      {
      # gosh, neither fvwm95 nor fvwm2 is available; 
      # fall back to failsafe settings
      [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
      if [ -x /usr/bin/xclock ] ; then
          /usr/bin/xclock -geometry 100x100-5+5 &
       fi
       if [ -x /usr/bin/xterm ] ; then
           /usr/bin/xterm -geometry 80x50-50+150 &
       fi
       if [ -x /usr/bin/firefox -a -f /usr/share/doc/HTML/index.html ]; then
     /usr/bin/firefox /usr/share/doc/HTML/index.html &
       fi
       if [ -x /usr/bin/twm ] ; then
     exec /usr/bin/twm
       fi
       }
       </snip>
    
  • The above scripts have entry for /usr/bin/twm, which is deprecated in RHEL7. There is no package which provides this binary in RHEL7.

SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.