How can I make xrandr customization permanent?

Modify /etc/lightdm/lightdm.conf to add the following options:

display-setup-script > calls your mycustomloginvideo.sh before the login screen appears session-setup-script > calls your mycustomdesktopvideo.sh before the user desktop session starts

[SeatDefaults]
greeter-session=unity-greeter
user-session=ubuntu
# for your login screen, e.g. LightDM (Ubuntu 11.10) or GDM (11.04 or earlier)
display-setup-script=/usr/share/mycustomloginvideo.sh
# for your desktop session
session-setup-script=/usr/share/mycustomdesktopvideo.sh

You may have "arandr" GUI tool generate the above sh script, picking parameters from your current session's X configuration.

Make sure that your shell script is executable:

chmod a+x /usr/share/mycustom*video.sh

and you can test that it works (i.e. that you don't have any typos or configuration errors in your xrandr command) just by running it in a terminal:

/usr/share/mycustomdesktopvideo.sh

If the login script doesn't work for any reason, your machine might not complete the boot process to the login screen. If the desktop script fails, you might not get a desktop after logging in. If you are setting an external monitor, these scripts will fail when you disconnect it, and X session will not start.


I think you can add the display modes to /etc/X11/xorg.conf.

If you don't have a xorg.conf, then you can use the following as a basis. You need to replace the entries with the names Modeline, Driver and Modes with the correct entries for your system. Depending on your hardware, you may need additional entries, for example if your system has more than one graphic chip.

Section "Monitor"
    Identifier    "Monitor0"
    Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
    Modeline "1024x768_60.00"   63.50  1024 1072 1176 1328  768 771 775 798 -hsync +vsync
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Card0"
    Monitor        "Monitor0"
    SubSection "Display"
        Modes       "1280x1024_60.00" "1024x768_60.00"
    EndSubSection
EndSection

Section "Device"
    Identifier    "Card0"
    Driver        "nvidia"
EndSection

If you don't know the name of the video driver that your system is using then you may get the name as follows (if you have an intel graphic chip, the driver name is just "intel"):

lshw -class display | grep "driver"

The modelines can be generated with cvt:

cvt <h-resolution> <v-resolution> [refresh]

Some one posted another workaround, although I must say It didn't work for me. It could probably work for you. In my case it breaks unity and I can only move my mouse cursor around. The app indicator top panel looks empty, but after unplugging my LCD I was able to delete the added lines and everything went back to normal.

edit the file /usr/sbin/lightdm-session

Here is how the first part of that file looks now:

#!/bin/sh
#
# LightDM wrapper to run around X sessions.

echo "Running X session wrapper"

# Load profile
for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
  if [ -f  "$file" ]; then
     echo "Loading profile from $file";
     . "$file"
  fi
done

xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode CRT1 1368x768_60.00
xrandr --output CRT1 --mode 1368x768_60.00

# Load resources

Take note that the Xrandr settings should be changed to match yours.