The X Server Configuration HOWTO Sven Vermeulen Xorg is the X Window server which allows users to have a graphical environment at their fingertips. This HOWTO explains what Xorg is, how to install it and what the various configuration options are. 1.23 2009-12-08 What is the X Window Server?
Graphical vs Command-Line

The average user may be frightened at the thought of having to type in commands. Why wouldn't he be able to point and click his way through the freedom provided by Gentoo (and Linux in general)? Well, *big smile*, of course you are able to do this. :-) Linux offers a wide variety of flashy user interfaces and environments which you can install on top of your existing installation.

This is one of the biggest surprises new users come across: a graphical user interface is nothing more than an application which runs on your system. It is not part of the Linux kernel or any other internals of the system. It is a powerful tool that fully enables the graphical abilities of your workstation.

As standards are important, a standard for drawing and moving windows on a screen, interacting with the user through mouse, keyboard and other basic, yet important aspects has been created and named the X Window System, commonly abbreviated as X11 or just X. It is used on Unix, Linux and Unix-like operating systems throughout the world.

The application that provides Linux users with the ability to run graphical user interfaces and that uses the X11 standard is Xorg-X11, a fork of the XFree86 project. XFree86 has decided to use a license that might not be compatible with the GPL license; the use of Xorg is therefore recommended. The official Portage tree does not provide an XFree86 package anymore.

The Project

The project created and maintains a freely redistributable, open-source implementation of the X11 system. It is an open source X11-based desktop infrastructure.

Xorg provides an interface between your hardware and the graphical software you want to run. Besides that, Xorg is also fully network-aware, meaning you are able to run an application on one system while viewing it on a different one.

Installing Xorg
Kernel configuration

By default, Xorg uses evdev, a generic input driver. You'll need to activate support for evdev by making a change to your kernel configuration. (Read the Kernel Configuration Guide if you don't know how to setup your kernel.)

Device Drivers --->
  Input device support --->
  <*>  Event interface
make.conf configuration

Before you install Xorg, you have to configure two important variables in the /etc/make.conf file.

The first variable is VIDEO_CARDS. This is used to set the video drivers that you intend to use and is usually based on the kind and brand of card you have. The most common settings are nvidia for Nvidia cards or fglrx for ATI Radeon cards. Those are the proprietary drivers from Nvidia and ATI respectively. If you would like to use the open source nVidia driver, use nv rather than nvidia in the variable, but bear in mind that using this driver means no 3D acceleration at all. The free radeon and radeonhd drivers are available for ATI cards, and are more or less the equal of the proprietary fglrx driver. The intel driver may be used for desktops or laptops with common Intel integrated graphics chipsets. VIDEO_CARDS may contain more than one driver, in this case list of them should be separated with spaces.

The second variable is INPUT_DEVICES and is used to determine which drivers are to be built for input devices. In most cases setting it to evdev should work just fine. If you use alternative input devices, such as a Synaptics touchpad for a laptop, be sure to add it to INPUT_DEVICES.

Now you should decide which drivers you will use and add necessary settings to the /etc/make.conf file:

(For mouse, keyboard, and Synaptics touchpad support)
INPUT_DEVICES="evdev synaptics"
(For Nvidia cards)
(OR, for ATI Radeon cards)
More instructions on how to configure nVidia and ATI cards can be found in the Gentoo Linux nVidia Guide and in the Gentoo Linux ATI FAQ. If you don't know which drivers you should choose, refer to these guides for more information.

If the suggested settings don't work for you, you should run emerge -pv xorg-server, check all the options available and choose those which apply to your system. This example is for a system with a keyboard, mouse, Synaptics touchpad, and a Radeon video card.

# emerge -pv xorg-server

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] x11-base/xorg-server-  USE="hal nptl xorg -debug
-dmx -ipv6 -kdrive -minimal -sdl -tslib" 0 kB
[ebuild   R   ]  x11-base/xorg-drivers-1.6  INPUT_DEVICES="evdev synaptics
-acecad -aiptek -citron -elographics -fpit -hyperpen -joystick -keyboard -mouse
-mutouch -penmount -tslib -virtualbox -vmmouse -void -wacom"
VIDEO_CARDS="radeon -apm -ark -ast -chips -cirrus -dummy -epson -fbdev -fglrx
(-geode) -glint -i128 (-i740) (-impact) (-imstt) -intel -mach64 -mga -neomagic
(-newport) -nv -nvidia -r128 -radeonhd -rendition -s3 -s3virge -savage
-siliconmotion -sis -sisusb (-sunbw2) (-suncg14) (-suncg3) (-suncg6) (-sunffb)
(-sunleo) (-suntcx) -tdfx -tga -trident -tseng -v4l (-vermilion) -vesa -via
-virtualbox -vmware (-voodoo) (-xgi)" 0 kB

After setting all the necessary variables you can install the Xorg package.

# emerge xorg-server
You could install the xorg-x11 metapackage instead of the more lightweight xorg-server. Functionally, xorg-x11 and xorg-server are the same. However, xorg-x11 brings in many more packages that you probably don't need, such as a huge assortment of fonts in many different languages. They're not necessary for a working desktop.

When the installation is finished, you will need to re-initialise some environment variables before you continue. Just run env-update followed by source /etc/profile and you're all set.

# env-update
# source /etc/profile
Configuring Xorg
Using HAL

Recent X server versions are designed to work out-of-the-box, with no need to manually configure Xorg's configuration files.

You should first try starting X without creating /etc/X11/xorg.conf.

If Xorg won't start (if there's something wrong with the screen, or with your keyboard/mouse), then you can try fixing problems by using the right configuration files.

By default, Xorg uses HAL (Hardware Abstraction Layer) to detect and configure devices such as keyboards and mice.

HAL comes with many premade device rules, also called policies. These policy files are available in /usr/share/hal/fdi/policy/. Just find a few that suit your needs most closely and copy them to /etc/hal/fdi/policy/.

Do not edit the files in /usr/share/hal/fdi/! Just copy the ones you need, and edit them once they're placed in the proper /etc location.

For example, to get a basic working keyboard/mouse combination, you could copy the following files to /etc/hal/fdi/policy/:

# cp /usr/share/hal/fdi/policy/10osvendor/10-input-policy.fdi /etc/hal/fdi/policy
# cp /usr/share/hal/fdi/policy/10osvendor/10-x11-input.fdi /etc/hal/fdi/policy

There are several other HAL policies in /usr/share/hal/fdi/ that may interest you, such as laptop configurations, storage device handling, power management, and more. Just copy any of the policies to /etc/hal/fdi/policy/.

You can edit the policy files in /etc/hal/fdi/policy to your liking. You may want to make a few tweaks or to expose additional functionality. Let's go through an example of tweaking a HAL policy.

One very convenient trick is to kill the X server entirely by pressing Ctrl-Alt-Backspace. This is useful when your X server is malfunctioning, frozen, etc. It's not as extreme as rebooting the whole machine with Ctrl-Alt-Del.

Recent X server versions disabled this key combination by default. However, you can reenable it by copying 10-x11-input.fdi to /etc/hal/fdi/policy and editing it. You'll need to add just one line to the appropriate section, as shown below:

(Open the file in your preferred editor)
# nano -w /etc/hal/fdi/policy/10-x11-input.fdi
(Find the "input.keys" section)
(Add the "terminate" merge string as shown)
      <merge key="input.x11_driver" type="string">keyboard</merge>
      <merge key="input.xkb.options" type="string">terminate:ctrl_alt_bksp</merge>
        <merge key="input.x11_driver" type="string">evdev<merge>

There, now you have a handy way of killing an unresponsive X server. This is useful when programs have frozen your display entirely, or when configuring and tweaking your Xorg environment. Be careful when killing your desktop with this key combination -- most programs really don't like it when you end them this way, and you may lose some (or all) of what you were working on.

Hopefully just working with the HAL policy files results in a working X desktop. If Xorg still won't start, or there's some other problem, then you'll need to manually configure xorg.conf as shown in the next section.

The xorg.conf file Configuring xorg.conf should be seen as a "last resort" option. It really desirable to run without one if possible, and to do all your configuration via HAL policy files. If you still can't get a working configuration, then read on.

The configuration file of Xorg is called xorg.conf and it resides in /etc/X11. Xorg provides an example configuration as /etc/X11/xorg.conf.example which you can use to create your own configuration. It is heavily commented, but if you are in need of more documentation regarding the syntax, don't hesitate to read the man page:

$ man 5 xorg.conf
Automatic Generation of xorg.conf

Xorg itself is able to guess most parameters for you. In most cases, you will only have to change some lines to get the resolution you want up and running. If you are interested in more in-depth tweaking, be sure to check the resources at the end of this chapter. But first, let us generate a (hopefully working) Xorg configuration file.

# Xorg -configure

Be sure to read the last lines printed on your screen when Xorg has finished probing your hardware. If it tells you it failed at some point, you're forced to manually write an xorg.conf file. Assuming that it didn't fail, it will have told you that it has written /root/ ready for you to test. So let's test. :)

# X -config /root/

If all goes well, you should see a simple black and white pattern. Verify if your mouse works correctly and if the resolution is good. You might not be able to deduce the exact resolution, but you should be able to see if it's too low. You can exit any time by pressing Ctrl-Alt-Backspace.

Copying over xorg.conf

Let us copy over the to /etc/X11/xorg.conf now, so we won't have to continuously run X -config -- typing just startx is easier. :)

# cp /root/ /etc/X11/xorg.conf
Using startx

Now try startx to start up your X server. startx is a script that executes an X session, that is, it starts the X servers and some graphical applications on top of it. It decides which applications to run using the following logic:

  • If a file named .xinitrc exists in the home directory, it will execute the commands listed there.
  • Otherwise, it will read the value of the XSESSION variable and will execute one of the sessions available in /etc/X11/Sessions/ accordingly. You can set the value of XSESSION in /etc/env.d/90xsession to make it a default for all the users on the system. For example, as root, run echo XSESSION="Xfce4" > /etc/env.d/90xsession. This will create the 90xsession file and set the default X session to Xfce4.
  • If all of the above fail, it will fall back to a simple window manager, usually twm.
# startx

If you see an ugly, loathsome, repulsive, deformed window manager, that's twm. To finish the twm session, type in exit or Ctrl-D in the upcoming xterms. You can also kill the X session using the Ctrl-Alt-Backspace combination. This will however make X exit disgracefully -- something that you might not always want.

Tweaking X settings
Setting your Resolution

If you feel that the screen resolution is wrong, you will need to check two sections in your xorg.conf configuration. First of all, you have the Screen section which lists the resolutions, if any that your X server will run at. By default, this section might not list any resolutions at all. If this is the case, Xorg will estimate the resolutions based on the information in the second section, Monitor.

What happens is that Xorg checks the settings of HorizSync and VertRefresh in the Monitor section to compute valid resolutions. For now, leave these settings as-is. Only when the changes to the Screen section (which we will describe in a minute) don't work, then you will need to look up the specs for your monitor and fill in the correct values.

Do not "just" change the values of these two monitor related variables without consulting the technical specifications of your monitor. Setting incorrect values lead to out-of-sync errors at best and smoked up screens at worst.

Now let us change the resolutions. In the next example from /etc/X11/xorg.conf we add the Modes lines and the DefaultDepth so that our X server starts with 24 bits at 1440x900 by default. Don't mind the given strings -- they are examples and will most likely differ from the settings on your system.

Section "Screen"
  Identifier  "Default Screen"
  Device    "RadeonHD 4550"
  Monitor   "Generic Monitor"
  DefaultDepth  24
  # Skipping some text to improve readability
  SubSection "Display"
    Depth   24
    Modes   "1440x900"

Run X (startx) to discover it uses the resolution you want. :)

Configuring your keyboard

To setup X to use an international keyboard, you can copy the content of /usr/share/doc/hal-*/*/use-estonian-layout.fdi.bz2 to /etc/hal/fdi/policy/10-xinput-configuration.fdi:

# bzcat /usr/share/doc/hal-*/*/use-estonian-layout.fdi > /etc/hal/fdi/policy/10-xinput-configuration.fdi

Now you can just edit 10-xinput-configuration.fdi and change the Estonian keyboard layout (ee) to your own, such as Great Britain (gb) or Polish (pl).

When you're finished, run /etc/init.d/hald restart as root to make sure that HAL picks up your configuration file changes.

Finishing up

Run startx and be happy about the result. Congratulations, you now (hopefully) have a working Xorg on your system. The next step is to remove this ugly lightweight window manager (twm) and use a high-feature one (or even a desktop environment) such as KDE or GNOME, but that's not part of this guide.

Creating and Tweaking xorg.conf

First of all, man xorg.conf and man evdev provide quick yet complete references about the syntax used by these configuration files. Be sure to have them open on a terminal near you when you edit your configuration files!

Also, be sure to look at /etc/X11/xorg.conf.example; you may wish to copy this and use it as a foundation for writing your own xorg.conf.

You may find the FAQ provided on their website, in addition to their other documentation.

There are also many online resources on editing xorg.conf. We only list few of them here, be sure to Google for more.

Other resources

More information about installing and configuring various graphical desktop environments and applications can be found in the Gentoo Desktop Documentation Resources section of our documentation.

If you're upgrading to xorg-server-1.6 from an earlier version, then be sure to read the migration guide.