Getting X to work on Linux

Introduction

Unlike Windows where applications simply call some API to send stuff to the screen, GUI-based applications in Linux require an X server that takes care of handling keyboards and monitors. In other words, in X, applications are clients connecting to the X server to receive keyboard events and outputing data to the monitor.

Until around 2005, Linux distros typically shipped with the XFree86 server, which has since then been replaced with a fork called X.org.

Possible Issues

Low resolution, eg. 800x600@60Hz while your graphic card + monitor can handle much higher resolutions

Picture incorrectly left- or right-aligned, ie. there's some bit missing on either side

Proprietary drivers (Nvidia) vs. open-source (nv, Nouveau)

Investigating

Run X once, then check its /var/log/Xorg.0.log file for information on your hardware.

Make sure Linux has the right driver for your video card

If Xorg can't figure out the right settings for your display (monitor and video card), create and fine-tune its xorg.conf file.

You can also use "gtf" (command-line) and "xvidtune" (X application) to get hardware information.

If you are double-booting, you can use the Windows shareware PowerStrip to get the capabilities of your graphic card and monitor, and use those to fix issues you might have in X.

CTRL-ALT-Fx to switch to/from X and text mode

To kill X in case "init 3" or CTRL-ALT-Backspace are disabled: Either through a script in /etc/init.d/, or "ps aux | grep X ; kill <pid of X>"

Various information

Solutions

Using open-source "nouveau" driver for Nvidia

In a running X session, open an xterm console:

  1. $ setxkbmap fr (for French keyboard)
  2. $ sudo passwd (to enable root access)
  3. $ su -
  4. # lspci | grep VGA (to check what hardware you have)
  5. $ su - (in a text-mode console)
  6. # loadkeys fr (for French keyboard)
  7. # apt-get update
  8. # apt-get install openssh-server
  9. # apt-get install joe
  10. # joe /etc/profile

    stty erase '^H' (make sure your terminal emulator sends this for Backspace instead of ^?)

    alias ll='ls -al'
     
  11. # source /etc/profile
  12. # apt-get install python-software-properties
  13. # apt-get install xresprobe (to add "ddcprobe")
  14. # add-apt-repository ppa:bjfs/ppa
  15. # apt-get update
  16. # apt-get install linux-headers-$(uname -r) linux-libc-dev kernel-package build-essential

    (ALT-F1 to switch to console; Must be done at the console, not through SSH)
     
  17. $ su -
  18. # /etc/init.d/slim stop (or whatever command available to stop Xorg)


    (This part can be done through SSH)
     
  19. # apt-get --purge remove xserver-xorg-video-nv
  20. # apt-get install xserver-xorg-video-nouveau

    //If already ran this command, use this to start afresh:
    # aptitude purge dkms

  21. # depmod (important!)
  22. //Back at the console

    # /etc/init.d/slim start

    It should start with the Nouveau driver, and you might not need to do anything more to get a correct display.

Configuring X with xorg.conf

Note that xorg 7.3 uses "xrandr" to set the resolution to what it thinks it should be (apparently, xrandr reads the DCC information from the monitor), and "gtf" is part of the xserver-xorg-core package.

If Xorg is now using a definition that is higher than you'd like, eg. 1200x1024 instead of 1024x768:

  1. # /etc/init.d/slim stop
  2. # less /var/log/Xorg.0.log

    Search for "Supported detailed timing". Write down infos given on lines "Image Size", and "Ranges"
     
  3. # Xorg -configure (will start/stop Xorg, and create ~/xorg.conf.new)
  4. # cp ~/xorg.conf.new /etc/X11/xorg.conf
  5. # gtf 1024 768 75

    Copy Modeline returned by gtf
     
  6. # joe /etc/X11/xorg.conf

    Section "InputDevice"
            Identifier  "Keyboard0"
            Driver      "kbd"
            #For French keyboard layout
              Option      "XkbLayout"   "fr"
    EndSection

    Section "Monitor"
            Identifier   "Monitor0"
            VendorName   "Monitor Vendor"
            ModelName    "Monitor Model"

           #Given by Xorg.0.log above
          #CONSOLES LOCK UP
            DisplaySize  376 301
            HorizSync     24-80
            VertRefresh  50-75

          # BAD Modeline "1024x768_75.00"  81.80  1024 1080 1192 1360  768 769 772 802  -HSync +Vsync
           #Modeline "1024x768_75"  81.80  1024 1080 1192 1360  768 769 772 802  -HSync +Vsync
           #Option      "PreferredMode"      "1024x768_75"
    EndSection

    Section "Screen"
            SubSection "Display"
                Viewport   0 0
                Depth     24
                #Modes   "1024x768_75"
            EndSubSection

            #DefaultDepth   24
    EndSection
     
  7. # /etc/init.d/slim start
    (If it doesn't boot start, check /var/log/Xorg.0.log for more information)
  8. $ xvidtune
  9. Click on Fetch/Show and compare output with the one returned by "gtf"
  10. $ su -
  11. # xrandr -q (for more information)

Configuring X with HAL

  1. # dpkg -L hal | less

Disappearing mouse cursor when using KVM

# joe /etc/X11/xorg.conf:

Section "Device"
        ...
        Option "HWCursor" "off"
EndSection

"X Power Tools" Reading Notes

export DISPLAY=":0" means that the X server is running on the local computer, and should be reached through a local connection (eg. Unix domain socket), while export DISPLAY="localhost:0" will use TCP/IP.

RANDR: Stands for rotate and resize. Notifies clients when the display is resized to a new resolution or rotated.

X can be started manually by calling it directly "$ X", which is a symlink to Xorg. You can also add a configuration file with "-config myconfig.file". However, to get a client running, use "$ X -terminate & sleep 2; DISPLAY=:0 xterm" to get a terminal console.

A more user-friendly wrapper is available: $ startx /usr/bin/xterm -- :0 -config /etc/testconfig

If startx is launched without any argument, it will run clients listed in either ~/.xinitrc or /etc/X11/xinit/xinitrc.

CTRL-ALT-Backspace being a bit rough as a way to exit X, it's usually disabled through DontZap in xorg.conf.

A "display manager" is the GUI equivalent of the "login" program. Once the user has logged on, the display manager will usually present client applications such as a window manager, and a desktop environment (KDE, GNOME, XFCE, etc.) Major display managers are GDM (Gnome), KDM (KDE), and XDM (Xt; Old).

By default, Debian-based systems (including Ubuntu) start the display manager in all runlevels. You can easily disable the startup of the display manager in runlevel 3 by executing these commands:

  1. update-rc.d -f gdm remove
  2. update-rc.d gdm start 31 2 4 5 . stop 31 1 3 .

Enhances character-based applications like Midnight Commander or Joe use a curses library, which checks the TERM environment variable and uses a database to determine the capabilities supported by that terminal; those applications use the OS' termios interface to control input. Since X doesn't understand character-based applications, an application known as a terminal emulator is required to act as a bridge: xterm, gnome-terminal, konsole, etc.

Desktop environments are program suites to manage panels, desktop background, session manage, window manager, etc. As a lighter alternative, some window managers handle a subset of those features.

An X session = character-mode login

A session manager = saves/restores session state so the user can log out and log back in without losing information

The Xfce session manager is started using "startxfce4".

xorg.conf

Screen = Monitor + Device (video card)

ServerLayout = Input device (keyboard, mouse) + Screen

To find out which modes are available for a particular monitor and video card, run X once and check /var/log/Xorg.log.0. For instance, "NVIDIA(0): Default mode "1024x768": 78.8 MHz, 60.1 kHz, 75.1 Hz" means that the dot clock (speed at which pixels are sent to the display) runs at 78.8MHz, the horizontal refresh rate is 60.1kHz, and the vertical refresh rate is 75.1Hz.

The level of log detail can be adjusted using the -logverbose level command-line option, where level is a number from 0 to 9. The default is level 3; higher levels introduce a bit more detail, notably the actual contents of the EDID decoded into readable strings.

Output devices

Screen resolution can be set either dynamically by running "xrandr" within an X session, or statically by adding a Screen section in xorg.conf.

Use the VESA driver (Video Electronics Standard Association) if you don't know which driver to use to get started.

DPMS is a VESA standard that conserves energy by using the horizontal and vertical sync signals to select one of four power states. DPMS is enabled on a monitor-by-monitor basis by adding an option to the Monitor section of the config file: Option "DPMS"

DDC (Display Data Channel) is a VESA technology to probe the monitor's capabilities, and even control the monitor settings. Data blocks returned by the monitor are formatted according to the EDID (Extended Display Identification Data) format.

Note that DDC can't be used when the monitor is indirectly connected through a KVM, in which case, you need to specify the horizontal and vertical sync frequencies that will work with the monitor by adding two entries in the Monitor section: HorizSync and VertRefresh.

If you can't find the specs of your monitor, here's a basic rule:

HorizSync = VertRefresh * (VerticalResolution + 40) / 1000

You should use a range instead of discret values, eg. "HorzSync 59.6 - 61.6" and "VertRefresh 74.0 - 76.0".

Note that changing resolution from eg. 1280x1024 to 800x600 doesn't change the size of the screen image; You can then scroll the display using the mouse. You can change resolutions as set in the "Modes" line through CTRL-ALT-+ and CTRL-ALT--.

If you want to change the resolution and screen size at the same time, use "xrandr" to check what sizes are available, followed by "xrandr -s" to select a size, eg. "xrandr -s 3" or "xrandr -s 1280x800". Use the "r" option to change the vertical refresh rate, eg. "xrandr -r 70".

Input devices

Since recent Linux distros now use udev, you might need to use "/dev/input/mice" instead of "/dev/mouse".

Option "ZAxisMapping" is used to handle scrollwheels on mice.

The XKB extension save keyboard configuration in a keyboar map. On Debian/Ubuntu, this is located under /etc/X11/xkb/. Options are selected in xorg.conf through "Xkb..." variables.

You can change the keyboard settings in a session through the "setxkbmap" command.

To display the current keyboard layout: $ xkbprint $DISPLAY keyboard.ps

Utilities

xdpyinfo: information about the display

xwininfo: basic information about a window (xwininfo -root)

xset: to view/change X configuration settings

xkill: to kill the connection between X and a client, which usually stops the client application

xwd: to take a screenshot

xhost: to allow a remote client application to use the local display

xmodmap: to modify the keyboard map

Q&A

How to reset xorg.conf?

dpkg-reconfigure -phigh xserver-xorg

What does "dpkg-reconfigure -phigh xserver-xorg" do?

Why does Xorg ignore option ""XkbLayout"?

Still starts with US keyboard:

Section "InputDevice"
        Identifier  "Keyboard0"
        Driver      "kbd"
        Option      "XkbLayout"   "fr"
EndSection

Why is my screen too far to the left?

... even after pasting the output from gtf in /etc/X11/xorg.conf?

What is xrandr?

"The X Resize, Rotate and Reflect Extension (RandR) allows clients to dynamically change X screens, so as to resize, rotate and reflect the root window of a screen. The initial X11 design did not anticipate the need for dynamic resizing and it was necessary to restart the X server to bring about the changes. However, changing the screen resolution on the fly without changing the desktop size had been available under XFree86 since the beginning. RandR extension framework brought the ability to change display characteristics without restarting the X session."

What is HAL?

Resources