Fix wrong resolution at MDM/LightDM login screen in Linux Mint/Ubuntu

If you use an external monitor for your laptop like me, you may notice that when it boots up the resolution on the external screen is incorrect and mirrored with the laptop screen. These quick fixes will turn off your laptop screen if an external one is detected and changes the resolution as well.

First, while logged into your system run this on the command line:

Look for lines such as

LVDS1 is your laptop screen, VGA1 is my external screen connected by VGA. Note for you, this may be HDMI, DisplayPort etc.

Determine what the name of your laptop screen is (in my case LVDS1) and your external screen (in my case VGA1).

Also determine what your external screen resolution should be, in my case this is 1920×1080.

The following shell script checks xrandr to see if VGA1 is connected, if so it turns off the laptop screen and changes the external screen to be primary and the correct resolution.

MDM – Mate Display Manager

If you are using Mate Display Manager in Linux Mint 13, add the above script to /etc/mdm/Init/Default (you can remove the first line #!/bin/bash). Add the rest of the code to the end of the file, just above exit 0.

One problem that may occur is that some of the utilities such as xrandr or grep are not on the right path as this script doesn’t use the entire path you may be used too when logged in. In my installation, grep was is in /bin and not /usr/bin like the rest of the utilities, which stopped this script from ever passing the if condition.

You can make sure xrandr, grep, etc are on the right path by running

etc, in my case I fully qualified grep to /bin/grep.

LightDM

If you are using LightDM, place the script somewhere executable, it could be /usr/local/bin for example, chmod the script with execution rights with

In /etc/lightdm/lightdm.conf add this to [SeatDefaults]

 

, , , ,

8 thoughts on “Fix wrong resolution at MDM/LightDM login screen in Linux Mint/Ubuntu

  • Dee'Kej says:

    I’ve inspired myself by your solution and probably created more universal version. It’s used if you just want to use your monitor instead of laptop display. However, the parameters for xrandr can be easily modified here (xrandr –help for more options). Also, it’s done in one command, so the display blinking when switching resolution should be minimized… 😉

    Anyway, thx for the help.

    Here’s the script:

    # Updating login screen resolution to maximized one:
    monitor=”$(xrandr -q | grep -E -o -e “VGA[[:digit:]] connected” | sed -r -e ‘s/ connected//’)”
    display=”$(xrandr -q | grep -E -o -e “LVDS[[:digit:]] connected” | sed -r -e ‘s/ connected//’)”

    if [ -n “$monitor” ]; then
    xrandr –output “$display” –off –output “$monitor” –auto –primary –preferred –right-of “$display”
    fi

    exit 0

    • Dee'Kej says:

      //edit: I’ve been using this in Linux Mint 14.

      If you want to use this in Mint 13, you can. It’s working there also. And if you have a problem when the Cinnamon freezes in Mint 13 after loging in, make sure to run the /etc/mdm/Init/Default script (or just this little piece of code) again, via some symbolink link in Startup applications. 😉

    • Sammy says:

      Thank you for the script.
      Here is a more generic version I use:

      # Updating login screen resolution to maximized one:
      monitor="$(xrandr -q | grep -o "^.*[[:digit:]] connected" | tr -d ' connected')"

      if [ -n "$monitor" ]; then
      display="$(echo $monitor | sed -e 's/^.*[[:digit:]] //')"
      monitor="$(echo $monitor | sed -e 's/ .*$//')"
      xrandr --output "$display" --off --output "$monitor" --auto --primary
      fi

      exit 0

  • Bremme says:

    I was struggling with the same problem, but with a little different setup. I’m using two external displays at home, sometimes just one and just the laptop when i’m on the road.

    I made some modifications to Dee’Kej’s script to suit my setup. Tested and working under ubuntu 13.04 x64 (lightdm). Here’s the code if someone want’s to use it:


    #!/bin/bash

    # Get xrandr display names (returns empty if not connected)
    monitor1="$(xrandr -q | grep -E -o -e "HDMI[[:digit:]] connected" | sed -r -e 's/ connected//')"
    monitor2="$(xrandr -q | grep -E -o -e "VGA[[:digit:]] connected" | sed -r -e 's/ connected//')"
    display1="$(xrandr -q | grep -E -o -e "LVDS[[:digit:]] connected" | sed -r -e 's/ connected//')"

    # if both vga and hdmi monitors are attached > display on hdmi(primary) and vga(secondary)
    if [ -n "$monitor1" ] || [ -n "$monitor2" ]; then
    xrandr --output "$display1" --off --output "$monitor1" --auto --primary --preferred --left-of "$monitor2" --output "$monitor2" --auto --noprimary

    # elseif hdmi monitor is attached > display on hdmi(primary) and display(secondary))
    elif [ -n "$monitor1" ]; then
    xrandr --output "$monitor2" --off --output "$monitor1" --auto --primary --preferred --left-of "$display1" --output "$display1" --auto --noprimary

    # elseif vga monitor is attached > display on vga(primary) and display(secondary)
    elif [ -n "$monitor2" ]; then
    xrandr --output "$monitor1" --off --output "$monitor2" --auto --primary --preferred --left-of "$display1" --output "$display1" --auto --noprimary

    # else > display on internal display(primary) only
    else
    xrandr --output "$monitor1" --off --output "$monitor2" --off --output "$display1" --auto --primary --preferred
    fi

    # exit script
    exit 0

    actually my very first linux script:).

  • Hudsonkem says:

    Bremme your scrip is excellent, work is a bird here :P. ubuntu 14.10; with MDM

  • Gus says:

    Thanks for this script, i am very new and I cant manage to have it run… I put it in init.d made it executable but it doesnt do anything… Could you please elaborate on how to use this? thanks!

  • Tony says:

    This worked almost perfectly for me. However, when I log out it goes back to the way it was. I think this means that I need to edit another file for the logout, but I don’t know which one to edit. Any help?

Leave a Reply

Your email address will not be published. Required fields are marked *