This article describes how to make certain configuration changes to the X Window System. For more general information on X, see the Graphics on Linux article.
Before you Begin
Since this article has you editing your xorg.conf file, you should back it up, before you begin, in case you mess it up. That way, you can play around with it as much as you want, and if it doesn't work, you can always revert back to a working copy. (Especially because you don't want to have to resort to using vi from the command line, to solve X problems!)
Luckily, it's very easy to do; simply make a copy of it.
sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
Notice that you have to use sudo to make a copy of the file, because it's protected by the operating system.
If you're not familiar with the cp command, it simply means “copy.” We are copying the xorg.conf file to a new file, named xorg.conf.bak. Adding an extra .bak to the end of the file is a common convention, but you can name the new file whatever you want — as long as you remember what you name it.
Recovering From a Problem
The xorg.conf file has some pretty important settings, for X; it controls how the mouse and keyboard work, how the display works, and how certain drivers are loaded or configured. So if you mess it up, you can completely prevent the graphical aspect of Ubuntu from working!
If this happens, you'll load up Ubuntu, and instead of seeing the login screen, you'll see a text-based message, saying that X had problems, and offering to show you the log files. In many cases, it might be a good idea to look at these logs, so that you can find out exactly how you messed up your settings.
Luckily, if you have a backup copy of your xorg.conf file, that you know works, you can fix the problem easily.
First, you have to switch to a different virtual console. I usually use the first one, which I get to by pressing Ctrl+Alt+F1. From here, you simply need to take your copy of the xorg.conf file and make it the real configuration file again. If you've made changes that you want to keep, so that you can keep fiddling with it, you'll want to keep that, too.
cd /etc/Xll sudo cp xorg.conf xorg.conf.broken sudo cp xorg.conf.bak xorg.conf exit
Since I logged into a different virtual console, I just like to log back out, after.
Once this is done, you can press Ctrl+Alt+F7 to go back to the normal console, and then press Ctrl+Alt+Backspace to restart X. This time it should load up fine, since it's using a copy of the xorg.conf file that you know works.
Changing The File
All that being said, how do you actually edit the file? Well, it's a text file, so you can use any editor you wish; I typically use gedit, so I use the following command to edit the file:
sudo gedit /etc/X11/xorg.conf
Since the file is protected by the operating system, you have to use sudo to kick off your gedit session, but after that, you can make changes and save the file just as with any other text file.
As you make changes to the xorg.conf file, of course you'll want to know if they actually work. This is easy enough to test:
- Save your changes in gedit (or whatever text editor you're using)
- Press Ctrl+Alt+Backspace, which will restart X1
If your changes don't work, then you need to recover it and start again, as outlined above.
In some cases, X might start, just not in the way that you'd like it to. (For example, if you're trying to get multiple monitors working, but haven't got it quite right, you might get X loading properly on one monitor, and the other might still be dark.) You can still see the file, which is at /var/log/Xorg.0.log. (You can also use the System Log viewer, to see the same log.)