Previous Page | Next Page

  1. Introduction
  2. Abbreviated Boot
  3. The Boot Process
  4. Startup and Run Levels
  5. Initialization Scripts
  6. Runlevel Scripts
  7. Login Process
  8. Bash Shell
  9. Filesystems
  10. LILO, Kernel and Root Filesystem
  11. The Kernel
  12. Passwords, Users, Groups, and Quotas
  13. The Environment
  14. The /etc/sysconfig directory
  15. The /proc filesystem
  16. Process Control
  17. Devices
  18. Daemons Services
  19. Inetd and Network Services
  20. Programs and Libraries
  21. Security and PAM
  22. The printer services
  23. Mouse support with gpm
  24. Mail
  25. News
  26. UUCP
  27. LDAP
  28. NFS and RPC
  29. Samba, NetBIOS, WINS, nmbd
  30. Identd (auth)
  31. Telnet and FTP
  32. Apache web server
  33. DNS and named
  34. How X Works
  35. X Scripts
  36. Support for Text
  37. Keymapping for Programs
  38. Keycode Table
  39. Example Keymap File
  40. Terminfo Commands
  41. VT100 ESC sequences
  42. Kernel Revisited
  43. Configuration Files
  44. Credits

How Linux X works

This section on X is a constantly changing section since there is much to understand about X. There are many scripts, configuration files, and binary programs involved in running X both on the client and server sides. This section has begun to touch on some of them, but much more is needed and will be added as time dictates. This section may be re-organized and broken into more sections as it grows.

X is many times referred to as X windows even though its proper name is "X". It runs a graphical interface for the user similar to the Microsoft Windows products, but X can run sessions on remote computers. X runs several programs many of which are called X clients. It also requires a server program to run at the terminal end. A server program runs on the side where the user is looking at the screen and using the keyboard and mouse. This program is called the server program and it may be a program that runs on any given operating system, but these programs in Linux are typically XF86_SVGA, Xserver, XF86_S3V, XF86S3. The one used depends on the user's OS, video card, and preferences. If run in Linux, most configurations of the user's server program are controlled by the file "/etc/XF86Config" or /etc/X11/XF86Config" or "$home/lib/X11/XF86Config". This file controls the mouse, keyboard and screen configurations. The connection between the client and server can be internal pipes if both run on one machine, or a serial or network connection. Server arguments are specified by a file $HOME/.xserverrc or /etc/X11/xinit/xserverrc.

On the side normally thought of as the server side, but in this case the client side, run one or more client programs along with an X font server. Some X clients are called windows managers and they are used to control the look and feel of the X session. These X clients are normally fvwm, gnome, kde and others. Any program that opens a window is an X client. The window manager along with other client programs used may be specified in one of many places. Client user resources in either $HOME/.Xresources, or /etc/X11/xinit/Xresources, or /usr/X11R6/lib/X11/xinit/Xresources. Client user modemap in $HOME/.Xmodmap, or /etc/X11/xinit/Xmodmap, or /usr/X11R6/lib/X11/xinit/Xmodmap. Client user keyboard map in $HOME/.Xkbmap, or /etc/X11/xinit/Xkbmap, or /usr/X11R6/lib/X11/xinit/Xkbmap. Three programs are used to set features based on these files. The programs are xrdb, xmodmap, setxkbmap respectively for Xserver resources, setxkbmap to set the keyboard, and xmodmap for modifying keymaps and pointer buttons.

Starting with the startx command

An X session is started by entering the command "startx". This script resides in "/usr/X11R6/bin". The script startx, provides a front end to the xinit program, also in /usr/X11R6/bin, that is used to provide a nicer interface for running a single X windows session. The startx script gets and provides client and server arguments to the xinit script. Startx can get client and server arguments from several files or the command line. The startx script invokes the xinit script with the following statement:

xinit $clientargs -- $display $serverargs

Startx typically runs without command line arguments, but command line arguments will override its normal behavior described below. It gets client arguments from one of:

  1. .xinitrc in the user's home directory, if the file exists.
  2. /etc/X11/xinit/xinitrc if the above file doesn't exist.
  3. /usr/X11R6/lib/X11/xinit/xinitrc by default if the above two files don't exist.

It gets server arguments from one of:

  1. .xserverrc in the user's home directory if it exists.
  2. /etc/X11/xinit/xserverrc if the above file doesn't exist.

The script startx passes client arguments, display arguments, and server arguments to the program xinit which resides in "/usr/X11R6/bin".

The xinit program

The program xinit will run the client script program passed to it. If no "xinitrc" program is passed or exists, it will run "xterm -geometry +1+1 login -display :0" as a default. If no specific server program is given, xinit will use "X :0" as a default. This means that the default server program is called X and the default client program is xterm. It is assumed, that there is a program named X in the searchpath, normally in "/usr/X11R6/bin". This may be a softlink to another program. In my case it is a link to the program Xwrapper in the same directory.

The Xwrapper program

Root privileges are required by the system in order to access video hardware. In the past, x server programs were run with the setuid bit set which means they effectively were running with root privileges. Considering the size and variety of X servers and not being sure of any security loopholes in these current and future programs, running the server with root privileges became a security problem. The Xwrapper program was written so the X server program would not need to operate as root to access video hardware. The X server program could run without root privileges and access the video hardware using the Xwrapper program. The Xwrapper program is installed with the setuid bit set so it will run with root privileges.

The xinit program in the future will look for the Xwrapper program rather than the program called X. If the xinit program tries to start a X server without the Xwrapper program, the attempt will fail and errors will occur.

The xinitrc and xserverrc scripts

The xinit program will run the xserverrc (or .xserverrc) and xinitrc (or .xinitrc) scripts to help setup server and client arguments respectively. These scripts are the arguments passed to xinit from the startup script described earlier. The xinitrc will look in the users home directory for the following files prepended with a period, ".". Then it will look for those files in the directory /etc/X11/xinit.

  1. Xresources - Client resource files
  2. Xmodmap - Client mapping, used for mapping keys and possibly other items.
  3. Xkbmap - Client user keyboard map
  4. Xclients - A script that searches for files that help determine more client properties such as the preferred window manager client program.

There is not a xserverrc script program on my system so the defaults are used.

X clients

Programs that run under the X environment are called xclients. These include such things as xclock and xterm which are the types of programs I usually think of as application programs..
On most systems today, the xinitrc file will cause a window manager such as fvwm, gnome, or kde to be run. The window manager may be set up to invoke some client programs (applications) at startup such as xclock. Remember that these programs are called client programs because they expect services such as mouse and keyboard inputs to be provided from another program. Therefore they run on what would normally be thought of as the server side.
XFree86 (X11R6) uses a special video server dependent on the video card your system is using. Read instructions in /usr/X11R6/lib/X11/etc. You'll find just about everything you need under the /usr/X11R6/lib/X11/doc directory.
The program xfs is the xfont server
The program xdm is an X Display Manager which should be run beginning at system startup in order to be able to provide X services on a multi user system.


The display name sent to X is in the form "hostname:displaynumber.screennumber" where hostname specifies the name of the machine to which the display is connected. Displaynumber is the number of the monitor and keyboard on that machine starting with the number 0. Screen numbers are assigned starting with the number 0, and each number designates a separate window on the monitor.

In some of the startup scripts are statements like "exec fvwm". This is where a particular windows manager is started. Also statements like those shown below may be found:

xclock –geometry 100x100-5+5 &
xterm –geometry 80x50-50+150 &

These start the X programs xclock and xterm respectively. The geometry option specifies screen location and layout.

How to set up X managers for different users

Based on the analysis of the X startup scripts, it is quite easy to make a file, /etc/sysconfig/desktop, and put the string "KDE" or "GNOME" in it depending on the preferred system wide X manager. However this will not allow users to select their own favorite window manager. Note: This is exclusive of users who are running remote X services such as VNC as explained in the "Linux User's Guide". To allow users to select their own manager independent of system settings do the following:

  1. Copy the file "/etc/X11/xinit/Xclients" to the users home directory, renaming it with a period as its first character

    cp /etc/X11/xinit/Xclients /home/username/.Xclients

  2. Modify the following lines in /home/username/.Xclients from:
    if [ -f /etc/sysconfig/desktop ]; then
        if [ -n "`grep -i GNOME /etc/sysconfig/desktop`" ]; then
        elif [ -n "`grep -i KDE /etc/sysconfig/desktop`" ]; then
        elif [ -n "`grep -i AnotherLevel /etc/sysconfig/desktop`" ]; then


    if [ -f $HOME/.desktop ]; then
        if [ -n "`grep -i GNOME $HOME/.desktop`" ]; then
        elif [ -n "`grep -i KDE $HOME/.desktop`" ]; then
        elif [ -n "`grep -i AnotherLevel $HOME/.desktop`" ]; then
  3. Make a file, $HOME/.desktop, and put the string "KDE" or "GNOME" in it depending on the user's preferred X manager. The user can do this step.

Error Analysis

Sometimes you may get an error 111 message from your system when you try to start an X session. This is because your X server has either stopped working or has been unable to connect to your X client(s) for some reason. When starting the server,use the line:

startx <& xlog.txt

to start the server rather than "startx". This will send standard output and error output to the file xlog.txt so you can examine it to help find errors.