Friday, August 10, 2007

Multiple Monitors in Linux

I had been using Red Hat Enterprise Linux 4 at work for about 6 months. It was truthfully a pain in the ass to use because the package management is based around rpm and a Red Hat tool called up2date. The default repositories up2date looks at are pitifully lacking substance. I'd found a useful repository of RPMs, but I found changing a bunch of .conf files to point to the new repo was still painful. Then recently my configuration tools like up2date, the screen settings, and the print settings wouldn't launch. For those of you in the Windows world, all of my "Control Panels" were unavailable. So, my desire for a nice GUI update/package manager combined with the non working control panels lead to one conclusion: scrap RHEL4, install Ubuntu. I decided to add another graphics card and monitor to my setup at this point too, hoping the Ubuntu install would pickup on the hardware and automagically set up multiple monitors. Unfortunately I was wrong.

Quick and Dirty secrets of xorg.conf
My Ubuntu install went off without a hitch, but the second monitor never came on. To be clear, I have a main AGP graphics card, and a much older crappy PCI one. They both connect to their monitors (two of the same model of Dell LCD) via VGA. It turns out the problem is with the X server, which is the thing that is the basis of every GUI on Linux, be it GNOME, KDE, Xfce, whatever. Configuring X is the first step in getting multiple monitors with the proper resolutions, color depths, etc. There is this file /etc/X11/xorg.conf that does the magic. If you have the right configuration settings here, you can make wondrous things happen. The first thing I thought was "Hey, Ubuntu probably has a really nice GUI multiple monitor configuration!". Turns out it doesn't so that means that I'd have to modify xorg.conf by hand. At first I tried setting up something called Xinerama using a forum post I found. No luck with this, even though I am convinced I did things exactly like they said. After digging around some more, I came up with the following, and it pretty much works. Where the Debian configuration of X failed to find and set up the second monitor, X's own configuration of itself does not. Try the following:

  1. Reboot into a failsafe shell/single user mode. This keeps X and your desktop environment from running. You need to do this to configure X (can't configure itself while its running). Failsafe mode usually involves stopping your boot loader by pressing some buttons during bootup, then picking the appropriate option. Note that you'll be root, so be careful.
  2. Make sure all graphics cards and monitors you want are hooked up and ready to go.
  3. Do a "X -configure". This gets you a local version of a configuration file called
  4. Now try it out: "X -config /root/". You should be greeted with some test patterns on both screens! The mouse will move back and forth across both screens too. Simple as pie.
  5. Now quit X: ctrl+alt+backspace. If you didn't get the test patterns...abandon all hope, I know not what else to do.
  6. Backup your working xorg.conf just in case: "cp /etc/X11/xorg.conf /etc/X11/xorg.conf.working"
  7. Copy over the new config file to where X expects its configuration file "cp /etc/X11/xorg.conf"
  8. Do a "reboot"
There you have it, you should have two desktops! If it didn't work, you'll get some scary fear if this happens. You'll be in a root shell, so just replace the file with your backup ("cp /etc/X11/xorg.conf.working /etc/X11/xorg.conf") then "reboot".

If it worked, this gets you a fresh, working start to editing xorg.conf. The two Desktops are still distinct and have no way of moving windows between them at this point, so one last thing to enable that is to open up your xorg.conf ("sudo gedit /etc/X11/xorg.conf") and add the following line:
Option "Xinerama" "true"
To the "ServerLayout" section. Save the file, then do a ctrl+alt+backspace to try it out! Remember if you screw things up, just go back to the backed up file you have. You might need to edit the "Screen" section some to support the display modes you want, and maybe comment (#) out the HorizSync and VertRefresh parts of the "Monitor" section. You can see your backed up copy of xorg.conf for the formatting of the display modes.

Final Thoughts
It's not Windows. It's not easy. It's kind of a pain to set up. Oh Ubuntu, why don't you make a GUI tool to make this configuration nice and easy, and why oh why don't you include it as a System->Preference option? I guess they're working on it for 7.10. But I hope I have saved you some of the trouble I came across when trying to configure multiple monitors. Happy editing!


Alec said...

How ironic that your blog is called "rtfm-nub".

Have you read the manpages, particularly "man Xorg"?

Raj said...

i have read that manpage...why is it ironic? it'd be ironic if i were an idiot who had no idea about xorg and was complaining about setting it up. instead i offer a simplified tutorial for those that don't want to go through that arcane guide known as the manpages.