I'm using ubuntu server with xmonad. I configure my dual monitor setup with xrandr but I can't get it to run on startup. My .xinitrc looks like this:

# WM

# dual monitor
xrandr --output HDMI1 --auto
xrandr --output VGA1 --auto --left-of HDMI1

The settings are not being applied. How should I go about this?


Try it with an ampersand (&) behind xmonad. So it will be executed in the background. And the two xrandr commands can be executed.

# dual monitor
xrandr --output HDMI1 --auto
xrandr --output VGA1 --auto --left-of HDMI1

# WM
  • I updated the answer^^ – chaos Oct 23 '13 at 16:09

ilia choly, See if this solution works better for you: How to force Multiple Monitors correct resolutions for LightDM?

It involves editing the /etc/lightdm/lightdm.conf to make the login screen (tested on Ubuntu 12.04) call a script. The file originally looks like this:


Adding the below line makes it call the given script still before logging in:


And this other line makes it call the given script after logging in:


In this example, the lightdmxrandr.sh script serves for auto recognizing the resolution of the screen and of the external monitor, if there is one. Here's the script content in my case (I adapted just a little bit from the one on the link):


# connected external output
XCOM0=`xrandr -q | egrep '(HDMI1|VGA1|DP1) connected' | egrep -o '(HDMI1|VGA1|DP1)'`
# command to set external desktop
XCOM1=`xrandr --output LVDS1 --primary --auto --output $XCOM0 --auto --right-of LVDS1`
# command to set normal desktop
XCOM2=`xrandr --output LVDS1 --primary --auto`
# if the external monitor is connected, then we tell XRANDR to set up an extended desktop
if [ -n "$XCOM0" ] || [ ! "$XCOM0" = "" ]; then echo $XCOM1
# if the external monitor is disconnected, then we tell XRANDR to output only to the laptop screen
else echo $XCOM2

exit 0;

Save this file as lightdmxrand.sh Set as an executable file like this:

$ sudo chmod +x lightdmxrand.sh

Move it to /usr/share/ directory like this:

$ sudo mv lightdmxrand.sh /usr/share/lightdmxrandr.sh

Edit /etc/lightdm/lightdm.conf adding the given line to it:


If you want this script to also run after the login, add:


Hope it works for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.