Xorg/Configuration

From Gentoo Wiki
Jump to: navigation, search
Other languages:
English • ‎español • ‎français • ‎日本語 • ‎한국어

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.

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, 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 X.org Project

The X.org 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

Before you can install Xorg, you need to prepare your system for it. First, we'll set up the kernel to support input devices and video cards. Then we'll prepare /etc/portage/make.conf so that the right drivers and Xorg packages are built and installed.

Input driver support

By default, Xorg uses evdev[1], 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.

KERNEL Enabling evdev in the kernel
Device Drivers --->
  Input device support --->
  <*>  Event interface

Kernel modesetting

Modern open-source video drivers rely on kernel modesetting (KMS). KMS provides an improved graphical boot with less flickering, faster user switching, a built-in framebuffer console, seamless switching from the console to Xorg, and other features. KMS conflicts with legacy framebuffer drivers, which must remain disabled in your kernel configuration.

First, prepare your kernel for KMS. You need to do this step regardless of which Xorg video driver you're using.

KERNEL Configuring framebuffers
Device Drivers --->
  Graphics support --->
    Support for frame buffer devices --->
    ## (Disable all drivers, including VGA, Intel, nVidia, and ATI)
 
    ## (Further down, enable basic console support. KMS uses this.)
    Console display driver support --->
      <*>  Framebuffer Console Support

Next, configure your kernel to use the proper KMS driver for your video card. Intel, nVidia, and AMD/ATI are the most common cards, so follow code listing for your card below.

For Intel cards[2]:

KERNEL Intel settings
Device Drivers --->
  Graphics support --->
    /dev/agpgart (AGP Support) --->
    <*>  Intel 440LX/BX/GX, I8xx and E7x05 chipset support
    Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
    <*>  Intel 8xx/9xx/G3x/G4x/HD Graphics
    [*]    Enable modesetting on intel by default

For nVidia cards:

KERNEL nVidia settings
Device Drivers --->
  Graphics support --->
    Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) --->
    <*>    Nouveau (nVidia) cards

For newer AMD/ATI cards (RadeonHD 2000 and up), you will need to emerge x11-drivers/radeon-ucode or sys-kernel/linux-firmware. Once you have installed one of these packages, configure your kernel as detailed in the firmware section of Radeon page:

KERNEL AMD/ATI settings
## (Setup the kernel to use the radeon-ucode firmware)
Device Drivers --->
  Generic Driver Options --->
  [*]  Include in-kernel firmware blobs in kernel binary
  ## # ATI card specific, (see Radeon page for details of firmware to include)
   (radeon/<YOUR-MODEL>.bin ...)
  ## # all:
   (/lib/firmware/) Firmware blobs root directory
 
## (Enable Radeon KMS support)
Device Drivers --->
  Graphics support --->
  <*>  Direct Rendering Manager --->
  <*>    ATI Radeon
  [*]      Enable modesetting on radeon by default
  [ ]      Enable userspace modesetting on radeon (DEPRECATED)
Note
Old Radeon cards (X1900 series and older) don't need the x11-drivers/radeon-ucode package or any firmware configuration. Just enable the Direct Rendering Manager and ATI Radeon modesetting.
Note
Linux kernel >= 3.9 does not have the Enable modesetting on radeon by default anymore as it is already implied by default.

Now that you're done setting up KMS, continue with preparing /etc/portage/make.conf in the next section.

make.conf configuration

Now that your kernel is prepared, you have to configure two important variables in the /etc/portage/make.conf file before you can install Xorg.

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 of video card you have. The most common settings are nouveau for nVidia cards or radeon for ATI cards. Both have actively developed, well-supported open-source drivers.

Note
You may also try the proprietary drivers from nVidia and AMD/ATI, nvidia and fglrx respectively. However, setting up the proprietary drivers is beyond the scope of this guide. Please read the Gentoo Linux nVidia Guide and Gentoo Linux ATI FAQ. If you don't know which drivers you should choose, refer to these guides for more information.

The intel driver may be used for desktops or laptops with common Intel integrated graphics chipsets.

Note
VIDEO_CARDS may contain more than one driver, each separated with a space.

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[1] 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.

Decide which drivers will be used and add necessary settings to the /etc/portage/make.conf file:

CODE Sample make.conf entries
## (For mouse, keyboard, and Synaptics touchpad support)
INPUT_DEVICES="evdev synaptics"
## (For nVidia cards)
VIDEO_CARDS="nouveau"
## (For AMD/ATI cards)
VIDEO_CARDS="radeon"

If the suggested settings does not work emerge the x11-base/xorg-drivers package(see the step below). Check all the options available and choose those which apply to the system. This example is for a system with a keyboard, mouse, Synaptics touchpad, and a Radeon video card.

root #emerge --ask --verbose --pretend x11-base/xorg-drivers
 
These are the packages that would be merged, in order:
 
Calculating dependencies... done!
[ebuild   R   ]  x11-base/xorg-drivers-1.9  INPUT_DEVICES="evdev synaptics
-acecad -aiptek -elographics% -fpit% -joystick -keyboard -mouse -penmount -tslib
-virtualbox -vmmouse -void -wacom"
VIDEO_CARDS="radeon -apm -ark -ast -chips -cirrus -dummy -epson -fbdev -fglrx
(-geode) -glint -i128 (-i740) (-impact) -intel -mach64 -mga -neomagic (-newport)
-nouveau -nv -nvidia -r128 -rendition -s3 -s3virge -savage -siliconmotion -sis
-sisusb (-sunbw2) (-suncg14) (-suncg3) (-suncg6) (-sunffb) (-sunleo) (-suntcx)
-tdfx -tga -trident -tseng -v4l -vesa -via -virtualbox -vmware (-voodoo) (-xgi)"
0 kB

First of all, make sure udev is added as a USE:

root #echo "x11-base/xorg-server udev" >> /etc/portage/package.use

After setting all the necessary variables Xorg can be installed:

root #emerge --ask x11-base/xorg-server
Note
The x11-base/xorg-x11 meta-package could be installed instead of the more lightweight x11-base/xorg-server. Functionally x11-base/xorg-x11 and x11-base/xorg-server are the same, however x11-base/xorg-x11 brings in many more packages that most systems will probably not require. Additional packages include a large assortment of fonts in many languages. They are not necessary for a working X11 framework.

When the installation is finished, some environment variables will need to re-initialized before continuing. Source the profile with this command:

root #env-update
root #source /etc/profile

NVidia users

For NVidia users it might be beneficial to run nvidia-xconfig in order to generate a working xorg.conf file for the selected graphics card. Without this step the xorg.conf file will need to be created manually as described below. Missing the xorg.conf will sometimes generate a "No screens found" error to the terminal when attempting to startx.

Also the NVidia driver will only work after a reboot, so be sure to restart the system after running nvidia-xconfig.

root #nvidia-xconfig

It is both possible and recommended to set the OpenGL renderer to the hardware renderer instead of a software renderer:

root #eselect opengl set nvidia

Configuring Xorg

The X server is designed to work out-of-the-box, with no need to manually edit Xorg's configuration files. It should detect and configure devices such as displays, keyboards, and mice.

Try using startx without editing any configuration files. If Xorg will not start, or there is some other problem, then manual configuration of Xorg will be needed. This is explained in the following section.

Note
If changes have been made to the kernel, do not forget to restart the system before using startx in order to be using the newly built kernel. If the kernel was updated to a newer version in the process this will most likely require the bootloader's configuration files to be updated as well.

The xorg.conf.d directory

Important
Configuring files in xorg.conf.d should be seen as a last resort option. If possible it is desirable to run Xorg without any special configuration.

Most of the configuration files for Xorg are stored in /etc/X11/xorg.conf.d/. Each file is given a unique name and ends in .conf. The file names in Xorg's configuration directory will read in alpha numeric order. For example, 10-evdev.conf will be read before 20-synaptics.conf; a-evdev.conf will be read before b-synaptics.conf, and so on. The files in this directory are not required to be numbered, but doing so will help keep them organize. Organization is helpful in when debugging faulty configuration files.

Note
Xorg provides example configurations in /usr/share/doc/xorg-server-${version}/xorg.conf.example.bz2. These can be used to create custom configuration files in /etc/X11/xorg.conf.d/. The examples are heavily commented, but if more documentation regarding the syntax is needed man xorg.conf is always available. Other examples can be found in the Resources chapter at the end of this guide.

Using startx

Try startx to start up the X server. startx is a script that executes an X session; that is, it starts the X server 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. The value of XSESSION can be set in the /etc/env.d/90xsession file to make a default session for all 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 Xfce. Remember to run env-update after making changes to 90xsession.
user $startx

If no window manager has been installed a solid black screen will appear. Since this can also be a sign that something is wrong, the x11-wm/twm and x11-terms/xterm packages can be installed only to test X.

Once the programs are installed, run startx again. A few xterm windows should appear, making it easy to verify the X server is working correctly. Once satisfied with the results, unmerge x11-wm/twm and x11-terms/xterm if installed in the step above to remove the testing packages. They will not be needed to setup a proper desktop environment.

Tweaking X settings

Setting the screen resolution

If the screen resolution looks to be wrong, you will need to check two sections in your xorg.conf.d configuration. First of all, you have the Screen section which lists the resolutions that your X server will run at. 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.

Now let us change the resolution. In the next example from /etc/X11/xorg.conf.d/40-monitor.conf we add the PreferredMode line so that our X server starts at 1440x900 by default. The Option in the Device section must match the name of your monitor (DVI-0), which can be obtained by running xrandr. Install xrandr (emerge xrandr) just long enough to get this information. The argument after the monitor name (in the Device section) must match the Identifier in the Monitor section.

root #nano -w /etc/X11/xorg.conf.d/40-monitor.conf
Section "Device"
  Identifier  "RadeonHD 4550"
  Option      "Monitor-DVI-0" "DVI screen"
EndSection
Section "Monitor"
  Identifier  "DVI screen"
  Option      "PreferredMode" "1440x900"
EndSection

Run X (startx) to discover it uses the desired resolution.

Multiple monitors

More than one monitor in can be established in /etc/X11/xorg.conf.d/. Give each monitor a unique identifier, then list its physical position, such as "RightOf" or "Above" another monitor. The following example shows how to configure a DVI and a VGA monitor, with the VGA monitor as the right-hand screen:

root #nano -w /etc/X11/xorg.conf.d/40-monitor.conf
Section "Device"
  Identifier "RadeonHD 4550"
  Option     "Monitor-DVI-0" "DVI screen"
  Option     "Monitor-VGA-0" "VGA screen"
EndSection
Section "Monitor"
  Identifier "DVI screen"
EndSection
Section "Monitor"
  Identifier "VGA screen"
  Option     "RightOf" "DVI screen"
EndSection

Configuring the keyboard

To setup X to use an international keyboard create the appropriate config file in /etc/X11/xorg.conf.d/. This example features a Czech keyboard layout:

root #nano -w /etc/X11/xorg.conf.d/30-keyboard.conf
Section "InputClass"
        Identifier "keyboard-all"
        Driver "evdev"
        Option "XkbLayout" "us,cz"
        Option "XkbModel" "logitech_g15"
        Option "XkbRules" "xorg"
        Option "XkbOptions" "grp:alt_shift_toggle,grp:switch,grp_led:scroll,compose:rwin,terminate:ctrl_alt_bksp"
        Option "XkbVariant" ",qwerty"
        MatchIsKeyboard "on"
EndSection

The "terminate" command (terminate:ctrl_alt_bksp) lets users kill the X session by using the Ctrl+Alt+Backspace key combination. This will, however, make X exit disgracefully -- something that users might want to avoid. It can be useful when programs have frozen the display entirely, or when configuring and tweaking the Xorg environment. Be careful when killing the desktop with this key combination - most programs really do not like it when they are ended this way. Some, if not all, of the information that has not been written to the disk (information stored in "open documents") will be lost.

Finishing up

Run startx and be happy about the result. Congratulations, you now (hopefully) have a working Xorg! The next step is to install a useful window manager or desktop environment such as KDE, GNOME, or Xfce. Information on installing these desktop environments can be found here on the wiki.

See also

Wayland

External resources

Creating and editing config files

First of all, man xorg.conf and man evdev[1] provide quick yet complete references about the syntax used by these configuration files. Be sure to have them open on a terminal when editing Xorg configuration files!

There are also many online resources on editing config files in /etc/X11/. Only a few are listed here; use a choice favorite search engine to find 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.

When upgrading to xorg-server 1.9 from an earlier version, be sure to read the migration guide.

X.org provides many FAQs on their website, in addition to their other documentation.

References


This article is based on a document formerly found on our main website gentoo.org.
The following people have contributed to the original document: swift, nightmorph
They are listed here as the Wiki history does not provide for any attribution. If you edit the Wiki article, please do not add yourself here, your contributions are recorded on the history page.