Setting up dual monitors with Ubuntu

Configuring a dual screen setup isn’t as easy in Ubuntu as it is in Windows, but it’s not too much harder. All you need to do is edit a text file and be willing to use a terminal.

The text file we will be editing is called xorg.conf and is the configuration file for the X server. An X server is the program that interfaces between the computer and user, providing input and output functions, so this file is used when tweaking many input and output devices.

First we need to navigate to the directory where xorg.conf can be found. At the terminal, enter:

cd /etc/X11

You can use the ls function to list all of the files in the directory, and see that xorg.conf is there.

Next, make a copy of the current version of xorg.conf. This can be restored to get things working again if things go wrong later. We are working in a protected area of the operating system and so we need to use the sudo command. Enter the following:

sudo cp xorg.conf xorg.conf.backup

Now we can start editing xorg.conf. Ubuntu’s basic graphical text editor is called gedit, so at the terminal type:

sudo gedit xorg.conf

The xorg.conf file will open in a new window.

First look for the section with heading Section "Monitor". Mine looks like this:

Section "Monitor"
Identifier "SDM-S73"
Option "DPMS"
EndSection

Copy this section and paste it just below. Change the identifiers in both sections, so that we have SDM-S73 #1 and SDM-S73 #2. This will give you something like:

Section "Monitor"
Identifier "SDM-S73 *#1*"
Option "DPMS"
EndSection

Section "Monitor"
Identifier "SDM-S73 *#2*"
Option "DPMS"
EndSection

Next, repeat with the section headed Section "Device". This represents your graphics card. Copy and paste, and change the identifiers to add #1 and #2. This time, we also need to add a couple of lines to each section. To both, we need to add the line:

BusID "PCI:1:0:0"

This tells the X server where this graphics card can be found. This is the correct entry for my system, where one NVIDIA graphics card is running both monitors, which is in the only AGP slot on the motherboard. If your setup is different from this and the above is not working, you can discover the bus locations of any of your graphics cards by typing lspci -X at a terminal. Look for those with labels that describe something like your graphics card(s).

In this section, we also need to add a Screen line. To the first copy, add Screen 0; to the second, Screen 1. You should have something along the lines of this:

Section "Device"
Identifier "NVIDIA Corporation NV36.2 [GeForce FX 5700] *#1*"
Driver "nvidia"
*BusID "PCI:1:0:0"*
*Screen 0*
EndSection

Section "Device"
Identifier "NVIDIA Corporation NV36.2 [GeForce FX 5700] *#2*"
Driver "nvidia"
*BusID "PCI:1:0:0"*
*Screen 1*
EndSection

Next, we need to change Section "Screen" part. Again, copy and paste this section. In the first one, change the identifier by adding #1 to the end. You also need to add #1 to the end of the entries for Device and Monitor. In the second copy of this section, do exactly the same, but add #2 to Identifier, Device and Monitor. This should look a little like this:

Section "Screen"
*Identifier "Default Screen #1"*
*Device "NVIDIA Corporation NV36.2 [GeForce FX 5700] #1"*
*Monitor "SDM-S73 #1"*
DefaultDepth 24
SubSection "Display"
Depth 1
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 4
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 8
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 15
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 16
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
EndSection

Section "Screen"
*Identifier "Default Screen #2"*
*Device "NVIDIA Corporation NV36.2 [GeForce FX 5700] #2"*
*Monitor "SDM-S73 #2"*
DefaultDepth 24
SubSection "Display"
Depth 1
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 4
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 8
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 15
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 16
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1280x1024" "1024x768" "832x624" "800x600" "720x400" "640x480"
EndSubSection
EndSection

Finally, we need to edit the Section "ServerLayout" part of the file. It needs to specify the positions of the screens, and turn the xinerama option on (this manages dual screens). You need to change this section to read something like the following:

Section "ServerLayout"
Identifier "Default Layout"
*Screen "Default Screen #1"*
*Screen "Default Screen #2" RightOf "Default Screen #1"*
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
InputDevice "stylus" "SendCoreEvents"
InputDevice "cursor" "SendCoreEvents"
InputDevice "eraser" "SendCoreEvents"
*Option "xinerama" "on"*
*Option "clone" "off"*
EndSection

When this is done, hit the save button and exit gedit.

Finally, we need to restart the X server to apply the changes. To do this, simply press ctrl+alt+backspace and wait. Hopefully things start up again and you have your desktop spread across two monitors!

What if things go wrong?

If things do go wrong (you’ll see a blue screen with an error message), don’t panic! Things are certainly not beyond repair, in fact you have two options to fix things. First of all, press return a few times to get rid of the error messages and logs and get back to a command prompt. You’ll then need to type your user name and password to log in.

If you are fairly confident using the terminal at this point, you can edit xorg.conf from here. Simply navigate to the /etc/X11 folder, and use the nano editor. This is a basic text editor that you can use to tweak your xorg.conf file. At the terminal, type the following.

sudo nano xorg.conf

Then make some changes, and use ctrl-X to save and exit.

If you’re much happier editing in a graphical interface, we can restore the backup copy of xorg.conf we made earlier. This is also useful if things are so far gone that you want to start again. At the terminal, change directory to /etc/X11. Then enter the following to restore the backup:

sudo cp xorg.conf.backup xorg.conf

When you have either finished editing or have restored the backup, you will need to start the X server up again. To do this, type startx at the terminal and hit enter.

Leave a Reply