69

I used to edit the startup script for the GDM (/etc/gdm/Init/Default) to permanently change my display resolution.

How can I do this with LigthDM in Ubuntu Oneiric?

1

9 Answers 9

69

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.

7
  • For Mint 13 XFCE using mdm, edit /etc/mdm/Init/Default. Call your script before the "exit 0"
    – StackUnder
    Feb 21, 2014 at 13:06
  • Evnn works on Fedora... only needed the display-setup-script script as Xfce had it already set by the display settings, so the session-setup-script just dumped me at the login screen.
    – Wilf
    Jun 3, 2014 at 20:21
  • 1
    There not even the directory /etc/lightdm in my Ubuntu 20.4
    – thanos.a
    Dec 17, 2020 at 9:16
  • @thanos.a Are you using the main Ubuntu or a flavour (e.g. Xubuntu)? The former does not use lightdm in 20.04 Mar 24, 2021 at 16:11
  • 1
    @thanos.a The main Ubuntu flavour has been using GDM instead of LightDM since 17.10. This answer would have been correct at the time it was posted, but for newer versions of Ubuntu you will need to make the changes in GDM's config. See this answer. Mar 26, 2021 at 8:29
27

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]
6
  • I tried this and it wouldn't boot for some reason. I used the modeline generated from the cvt command and the driver from the other one (and tried vesa too), but it just hung with no error messages. Jon Roberts' solution worked perfectly for me and is independent of things such as the video card driver that you mention here which could easily go wrong for newbies, so therefore I'm voting his answer up.
    – Mike
    Nov 19, 2011 at 23:49
  • 1
    This doesn't seem to help for thing like --rotate.
    – Jherico
    Dec 9, 2012 at 19:40
  • 2
    This answer is outdated. See John Roberts Answer
    – con-f-use
    Oct 19, 2013 at 14:48
  • +1 Perfect-o! Using GDM w/Gnome 3.16, and this got my GDm to recognize 1080p monitors. Thank you!
    – eduncan911
    May 8, 2015 at 20:31
  • On my computer, lshw output i915, however the correct driver is intel.
    – user202729
    Sep 17, 2019 at 10:56
11

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.

2
  • This solution worked great for lubuntu 17.x on an old machine. It affects only the session, so the greeter login screen doesn't display with the desired resolution.
    – laconbass
    Jun 29, 2018 at 11:25
  • From the script portion you had posted, /etc/xprofile and $HOME/.xprofile seem the best place to make such modification without getting overwritten by updates.
    – user.dz
    Apr 20, 2020 at 11:32
6

I have been trying to solve a similar problem for a while now and found a solution that works for me so hopefully it will help...

I have an old aspire one AOA110 that I have broken the screen on too many times and after buying a new laptop decided that I would try to turn it into a HTPC but the external display I have is not recognised by X so I have had to 'tweak' it numerous times to get it working at the correct resolution.

Here is what I did:

After using this http://ubuntuforums.org/showthread.php?t=1112186 tutorial up to step 5 I was able to find a working and acceptable resolution in xrandr but this wasn't working on the LightDM login screen.

Don't follow the steps to make it persistent in the above how to it may work but I think this is the proper way to do it in 11.10. I found this post on the ArchWiki https://wiki.archlinux.org/index.php/Xorg which I adapted to my needs.

First create a file here: /etc/X11/xorg.conf.d/10-monitor.conf

Then add the appropriate X details for your display here is how mine looked:

Section "ServerLayout"
Identifier     "DualSreen"
Screen       0 "Screen0"
Screen       1 "Screen1" RightOf "Screen0" #Screen1 at the right of Screen0
#Option         "Xinerama" "1" #To move windows between screens
EndSection

Section "Monitor"
Identifier     "LVDS1"
Option         "ignore" "true"
EndSection

Section "Monitor"
Identifier     "VGA1"
Option         "Enable" "true"
Modeline "1440x900_60.00"  106.47  1440 1520 1672 1904  900 901 904 932  -HSync +Vsync
EndSection

Section "Device"
Identifier     "Device0"
Driver         "intel"
Screen         0
EndSection

Section "Device"
Identifier     "Device1"
Driver         "intel"
Screen         1
EndSection

Section "Screen"
Identifier     "Screen0"
Device         "Device0"
Monitor        "VGA1"
DefaultDepth    24
Option         "TwinView" "0"
SubSection "Display"
    Depth          24
    Modes          "1440x900_60.00"
EndSubSection
EndSection

Section "Screen"
Identifier     "Screen1"
Device         "Device1"
Monitor        "LVDS1"
DefaultDepth   24
Option         "TwinView" "0"
SubSection "Display"
    Depth          24
EndSubSection
EndSection

The important bits to add are under the appropriate Section "Monitor" include the appropriate Modeline that you found while using gtf 1440 900 60.00 and then under the corresponding Section "Screen" including the correct Modes.

You'll notice that what I was trying to do was not only to set the VGA1 connection to a suitable resolution but also tell it not to use my LVDS1 output. Obviously you will need to tweak yours appropriately to match the right number of outputs and the right Device, Screen and Display sections for your setup.

Sorry for the epic post, I have been tweaking xorg.conf files for some time now with the Hannspree display I've been using and the old xorg.conf setups that I used pre 11.10 just don't work properly any more this is the only solution I've found that works.

Good Luck!

2
  • Using xrandr -q should give you the right info on which display is being used and possible Modes. Dec 7, 2011 at 17:05
  • A basic config file can be generated by running Xorg :1 -configure, which makes a new X server and generates a config file from it - this can the be copied from /root/xorg.conf.new to /etc/X11/xorg.conf. I found a better way was the above answer
    – Wilf
    Jun 3, 2014 at 20:24
5

I've had a similar problem with my laptop as above, and I wanted to add something to the conversation. If you don't care about the login resolution (I don't), but want the actual workspace to be the right resolution, you can add your monitor information to LightDM but not turn on full resolution until you login.

I just added the following script for my monitor in a file: lighdmxrandr

xrandr --newmode "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync
xrandr --addmode VGA1 1440x900_60.00

then I call it in /etc/lightdm/lightdm.conf

display-setup-script=/usr/bin/lightdmxrandr

Once I login I can setup my monitor in Displays and it works, even after I re-log (used to give me a big ugly error).

1
  • This worked as desired but had to reboot not re-login...
    – CrandellWS
    May 13, 2018 at 18:08
4

As an enhancement for Jon Roberts answer, let me specify that arandr does not include in its sh script generation all parameters working in the current session. Primary monitor (in case you are using a dual monitor configuration), refresh rate and gamma settings for each monitor are not included, for example. My session script looks like that:

#!/bin/sh
xrandr --output LVDS --mode 1366x768 --pos 1600x432 --rotate normal --output HDMI-0 --off --output DVI-0 --off --output VGA-1 --mode 1600x1200 --rate 85 --pos 0x0 --rotate normal --primary
xrandr --output VGA-1 --gamma 0.8:0.7:0.55 

I manually added --rate and --primary options in the first line and then added manually a second line with the gamma correction because apparently xrandr gamma settings are lost whenever you switch a monitor to primary.

I do not know if this particular behavior with the gamma settings when making a monitor primary is intended or is a bug.

Moreover the session shell script is not called by lightdm but as a startup application, because it seems that lightdm calls the script before things are ready for xrandr and weird things happen.

4

I had the problem of wanting an extended display on my new LXDE box, (not a dual clone), found the correct command, but couldn't make it permanent.

xrandr --output VGA-0 --right-of DVI-0

The above methods all seemed too hard/not the right way to do it.

I eventually found this: http://www.sudo-juice.com/change-lxde-screen-resolution-ubuntu-lubuntu/

That worked a treat, but I used gedit instead:

gksu gedit /etc/xdg/lxsession/LXDE/autostart

Then added the line at the end with an @ symbol at the start:

@xrandr --output VGA-0 --right-of DVI-0

Hope that helps and thank you to sudo-juice.

PS Note the double - in the xrandr command -- (didn't show up too clearly on my screen).

3

Create a new document and name it e.g. /home/yourusername/yourscriptname.sh Type in

#!/bin/bash
xrandr --newmode "1600x900_60.00"  118.25  1600 1696 1856 2112  900 903 908 934 -hsync +vsync
xrandr --addmode VGA1 1600x900_60.00
xrandr --output VGA1 --mode 1600x900_60.00
unity --replace

and save it in your home folder (this sets the resolution to 1600x900)

Open Startup Applications (or run gnome-session-properties) and click "ADD". Give a name and type in the command line:

bash /home/yourusername/yourscriptname.sh

Save it, and now the script will be ran now every you login, so you will need to logout first for it to take effect. Running the command (e.g. bash /home/yourusername/yourscriptname.sh) in a terminal would also be a good idea to check whether the script works.

2
  • This was edited (instead if deleted) by the OP of this answer as it was posted here instead of here - i restored the original formatting as this may be useful as it should restore the xrandr config on login - the contents of the bash script should probably be replaced with the xrandr commands used to get the right configuration.
    – Wilf
    Jun 3, 2014 at 20:34
  • In my dual-monitor display, the EDID for my HDMI-0 display is being read, but the EDID for my DVI-0 is not being read. Pointing to a config script stored in /usr/bin did not work, but adding that script to my startup apps using gnome-session-properties was successful!
    – noobninja
    Jun 3, 2016 at 12:48
1

Based on responses upper, I have done some test and found a useful method that works to me, then I have created a simple script to automatize it with my automatic installs. But it will work to any other cases.

Create a scriptinstallxrandrfixed.sh. Add these lines:

#Variables for lightdm script and xrandr script to set up fixed resolution for old displays: 
xrandrscript=/usr/local/bin/xrandrscript.sh
lightdmstartscript=/usr/share/lightdm/lightdm.conf.d/60-xrandrscript.conf

#Added old style configuration for lightdm: 
sudo  ln -s /usr/share/lightdm/lightdm.conf.d /ec/lightdm/lightdm.conf.d
#A fix to some old displays in high school at Fray Bentos, fix to 104x768
#Some useful information comes from: http://askubuntu.com/questions/63681/how-can-i-make-xrandr-customization-permanent
sudo sh -c "echo '[SeatDefaults]' > $lightdmstartscript"
# for your login screen, e.g. LightDM (Ubuntu 11.10) or GDM (11.04 or earlier)
sudo sh -c "echo 'display-setup-script=$xrandrscript' >> $lightdmstartscript"
# for your desktop session
sudo sh -c "echo 'session-setup-script=$xrandrscript' >> $lightdmstartscript"
sudo sh -c "echo 'xrandr --size 1024x768 --rate 60.0' > $xrandrscript"
sudo chmod +x $xrandrscript

it will create the scripts and the files for lightdm display and session. Don't forgot to give it permission to execute

chmod +x scriptinstallxrandrfixed.sh

And execute

./scriptinstallxrandrfixed.sh

(you must be placed in same directory where you have the file.)

if not in same directory: /path/to/script/scriptinstallxrandrfixed.sh

Modify it to feet your needs.

1
  • I got: ln: failed to create symbolic link '/ec/lightdm/lightdm.conf.d': No such file or directory
    – thanos.a
    Dec 17, 2020 at 9:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .