How to switch to external display during boot?
The display-setup-script
line is in the wrong place in your config file. Move it to Seat:*
(previously SeatDefaults
):
[Seat:*]
display-setup-script=/path/to/display-setup.sh
The package includes an example file /usr/share/doc/lightdm/lightdm.conf.gz
that shows the correct layout.
Contents of display-setup.sh
:
#!/bin/sh
#xrandr's name for the external monitor connection
MONITOR=DP-5.8
#bail out if monitor not found
xrandr --query | grep -q "^$MONITOR connected" || exit 0
#the original command that does the switching
xrandr --output "$MONITOR" --mode "2560x1600" --primary
#optional: switch to vt1 and back, to fix with "blank screen" problem
chvt 1
chvt 7
Related videos on Youtube
student
Updated on September 18, 2022Comments
-
student over 1 year
When my laptop is on docking station, the boot messages are printed on the laptop screen and not on the external monitor. The earliest time I managed to switch to my external monitor was after login.
I also played with the BIOS settings but that doesn't seem to work as I want, so I am looking for a way to switch to the external monitor (if available) automatically during boot as early as possible.
I am using ubuntu 16.04.1 with systemd, lightdm (and xmonad). The laptop has an onboard intel card and a discrete nvidia card. Only the nvidia card can be used to use the external monitor. I am using the official nvidia drivers for this.
Following the suggestions on how do I prevent Xorg using my Linux laptop's display panel? I put the following in my (otherwise empty)
/etc/lightdm/lightdm.conf
:[Lightdm] display-setup-script=xrandr --output DP-5.8 --mode "2560x1600" --primary
(Executing that command from commandline does activate the external screen.) However it does nothing. Moving the command into a script made no difference, and putting
echo "test" > mylogfile
into the script revealed that it's not run on boot.Edit I just checked if mir is running or not by executing
ps -e | grep unity-system-co
which resulted in nothing (https://askubuntu.com/a/523012/12015)-
VocalFan over 7 yearsIs the point when it starts Xorg (lightdm) early enough? unix.stackexchange.com/questions/13619/…
-
student over 7 years@JigglyNaga: I just added for testing the following lines (to my otherwise empty /etc/lightdm/lightdm.conf: [Lightdm] display-setup-script=xrandr --output DP-5.8 --mode "2560x1600" --primary however it does nothing. (Executing the command from commandline does activate the external screen). (After [Lightdm] there is a line break)
-
student over 7 years@JigglyNaga: I also wrapped it into a script and also tried quotes. It doesn't work. About the xorg method I don't really understand what I do. The first problem is that my xorg file seems be automatically recreated after each boot (I just renamed it to xorg.conf.bak and after a reboot there was a xorg.conf file there with the same content as before). Since I am using ubuntu 16.01 I am also not sure, how much native xorg this uses or if its more an xorg emulation provided by mir.
-
VocalFan over 7 yearsCould you expand on "doesn't work"? eg. have the script redirect its output to a log file, so you can see if it runs at all, or generates any errors. If you're using Mir, that's relevant information to include in the question.
-
VocalFan over 7 years
xorg.conf
could also be overwritten by gpu-manager. Ubuntu bug 1310489 says "Fix Released" but the comments suggest users are still affected, so the workarounds in there may help. -
student over 7 years@JigglyNaga: Ok, I don't know of how to redirect error messages of the xrandr command to a log file, but I included a line
echo "test" > mylogfile
. If I run the script from command line directly this file is created with the content "test". After deleting it and rebooting I noticed that this file was not created at all so I guess that ligthdm simply didn't execute the script on boot.
-
-
student over 7 years[LightDM] is in my example file. However with that it doesn't work.
-
student over 7 yearsWith
[Seat:*]
I get the same problem as described above, i.e. it works after switching to an tty and back. Any idea? -
student over 7 yearsI even tried
sleep 30
without success. Would it be possible to make the switching to tty and back automatically from the script? -
student over 7 yearsUsing chvt 1 and chvt 7 after calling xrandr works, thanks. How can I catch the case that the monitor is not connected?
-
student over 7 yearsYour script ends in a blinking screen showing boot messages. I had the idea to call xrandr --auto and tried this: but it results in a black screen pastebin.com/XVaVkqQy (no error messages in the log)
-
student over 7 yearsBooting with my external monitor works with your script and also with my pastebin script (I did run chvt ... run in the exactly same way like you). However booting the laptop without external monitor doesn't work anymore, if the script is activated.
-
student over 7 yearsI just noticed that after booting with your script and the external monitor plugged in, it works that everything is displayed on the external monitor as said above, but xrandr --query doesn't show up my laptop screen anymore.
-
VocalFan over 7 yearsLet us continue this discussion in chat.