Pages

Saturday, July 16, 2011

Fixing Stuck Monitor Resolution in Ubuntu

After a few hours of thrashing around trying to get my graphics card to show the right display resolution I finally managed to do it. Here's a pretty comprehensive set of stuff you can try in case you find yourself in a similar predicament...

(P.S. Newbies be prepared to do a lot of learning...)

(P.P.S: The following worked for me on an Intel desktop motherboard (DG31PR) with Intel Integrated Graphics and a widescreen monitor (LG Flatron W1934S) Before embarking on the following, do ensure that your hardware does support the resolution you want.)

(P.P.P.S: Turns out the procedure for doing this in Windows is even harder, but I eventually managed it...)

(P.P.P.P.S: There are a few changes for later versions of Ubuntu, updated in the text of the post.)

The symptoms:
You either got a new monitor, or just disconnected and re-conected the monitor, updated something, reinstalled something, whatever. The result is that you are stuck with a monitor resolution like 800x600 or 1024x768 on Ubuntu. Here's what you need to do...

  1. First off, go the Monitors menu (System > Preferences > Monitors) and see if any higher resolution is available. If you got around to reading this, I'm guessing not. Check the box for 'show monitors in panel' - we're going to be needing this pretty often.
  2. Some solutions on the web ask you to use a disk for Ubuntu 8.04 or older - just ignore these. Its not worth going to the trouble of downloading the ISO and burning it or even making a bootable USB drive.
  3. There are the following tools that you can use - (I dont know which of these will work but one of them will do the job)
    1. The "recovery" option from the grub menu (which appears before you boot)
    2. The xorg.conf file and
    3. The xrandr command
Recovery Option:
The recovery option is useful as a quick option in case things were working normally earlier. Select recovery, and then from the prompt that comes up select "X in safemode". This then gives you a number of options - first try the option that will recover your settings from the backup file. (Reboot to see if this has any effect - you can do this by using the root prompt). If this does not work, or if its a new piece of hardware that caused the problem, select "Create a new hardware configuration". If this succeeds you will see a dialog box with a message. If it fails nothing happens; and you need to fiddle around with the xorg.conf file.

[Ubuntu 12.04 update: no options are provided, at least for me. By now I know that there is something severely screwed up either with my graphics card or monitor or the combination. So on to the next step]

The xorg.conf file:
This is a configuration file that stores settings for Xorg. It is located in /etc/X11. From Ubuntu 9.04 onwards there is no xorg.conf file shipped with the OS. X will, at startup, try to detect and apply all settings if no file is found. If a file is found it will use it for its settings. Making a xorg.conf file from scratch is a pain. Its content depends on your graphics card _and_ your monitor. To create a fresh xorg.conf use the command:

X -configure 


This will generate a file called xorg.conf.new. Open it with a text editor and make all modifications. Then rename it to xorg.conf and move it to /etc/X11/ . 
The additions that will need to be made are in the 'monitor' section, where you must add the video timing data for the resolution you desire. To get the timings, run the command 

cvt 1024 768


Where 1024 and 768 are example values of resolution. The output will be something like:
# 1440x900 59.89 Hz (CVT 1.30MA) hsync: 55.93 kHz; pclk: 106.50 MHz
Modeline "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync


Out of this copy the line 
"Modeline "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync

and paste it in the monitor section in the new file:

Section "Monitor"
Identifier   "Monitor0"
VendorName   "Monitor Vendor"
ModelName    "Monitor Model"
#Modeline "1280x960_60.00"  101.25  1280 1360 1488 1696  960 963 967 996 -hsync +vsync
#Modeline "1600x900_60.00"  118.25  1600 1696 1856 2112  900 903 908 934 -hsync +vsync
EndSection



Then copy the file off as /etc/X11/xorg.conf ; making sure that the old file, if any, is backed up. Then restart gdm using
sudo /etc.init.d/gdm restart


Using xrandr:

Boot into Ubuntu and start a terminal. Use xrandr to list all supported modes and active devices.


$ xrandr
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 4096 x 4096
VGA1 connected 1440x900+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1360x768       59.8  
   1024x768       60.0  
   800x600        60.3     56.2  
   848x480        60.0  
   640x480        59.9     59.9  
   1440x900_60.00   59.9*
Evaluate the video timings using cvt as explained above.
Create a new mode using the command

xrandr --newmode "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsyn
(The values are taken from the output of cvt; note that the quotes are required here)

Then add this as one of the available modes using the command:
xrandr --addmode VGA1 1440x900_60.00

(Note: No quotes here)

Then select this mode:
xrandr --output VGA1 --mode 1440x900_60.00 [1]


(Where VGA1 is the device that is shown as active in the output of the command xrandr)

If these steps work you may want to make these resolution settings permanent.

If you use gdm then simply add the last three commands to the /etc/gdm/Init/Default file; after the line OLD_IFS=$IFS. And thats that!

If you use lightdm then you need to edit the /etc/lightdm/lightdm.conf file as explained here. Only one additional point - there are two entries in lightdm.conf that set the variable display-setup-script. Keep the first entry commented out and set the value using the second.

[1] There was a typo in this line which has been fixed.

No comments: