39

I have a tricky problem regarding multiple monitors on KDE (Kubuntu). I have a laptop which, at home, is connected to two monitors - VGA and HDMI. That works only when the built-in laptop display is disabled (at least I was told that).

The problem is that now I took the laptop away and booted it up with no external monitors connected. The system remembers that the built-in display was disabled, so it disables it even though it is the only monitor connected. Obviously, that makes the laptop pretty much unusable. Switching to a terminal through Ctrl+Alt+F# works, I can login; even Guest works normally.

The question is, how do I (re)set an account's monitor settings through terminals, since I can't use the GUI?

Thanks

13
  • 3
    Related question with a recent answer re xrandr that might be useful.
    – user76204
    Feb 25, 2013 at 20:16
  • 2
    This helped when I could use the console on the second monitor, xrandr was able to set my settings. However, when i can only use the non-gui terminal, xrandr says it can't open display, so it's pretty useless. Feb 27, 2013 at 8:48
  • How did you disable the built-in laptop display? Feb 27, 2013 at 18:00
  • I don't know if there's a relevant difference to KDE, but in standard ubuntu it works just fine for me (with the internal monitor switched off via the GUI, with the laptop lid closed and the laptop sitting comfortably in its docking station). Feb 27, 2013 at 18:03
  • 1
    do you mean that I have to set the settings every time I use the laptop with and without external monitors? If so, that sucks. Anyway, I need to know how to do that through tty Feb 28, 2013 at 17:40

5 Answers 5

24

The command xrandr -s 0 should reset your displays in terminal. More can be found at the following site or from man xrandr in terminal.

https://linuxacademy.com/blog/linux/solution-resetting-your-screen-resolution-with-xrandr/

4
  • Welcome to Ask Ubuntu! While this answers the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – guntbert
    Dec 6, 2014 at 20:25
  • 4
    Yes, this works. The other answers are just too bloated, complicated or not efficient. Also might be of some value to note that if you experience a black screen (and cannot see anything), you can open your terminal with shortcut keys and blindly type "xrandr -s 0". That's what i did :)
    – kodeart
    Jan 19, 2015 at 12:31
  • 1
    Note that in two-monitor setups, this command may deactivate the second monitor, rather than setting both monitors to their default resolution.
    – Darien
    Mar 23, 2017 at 0:01
  • On my system, the command disables both external monitors, but also resets their configuration to default - which fixes the VGA DCC detection that gets broken from time to time. After which I just need to re-enable the screens and reposition them using the Displays tool. Its not ideal but its is very workable and better than my previous solution, which was to suspend and wake the computer a few times until it resets the VGA port.
    – Guss
    Apr 30, 2017 at 14:01
19

Whenever I put my Lubuntu laptop to sleep when it's exclusively displaying on my TV and wake it up after having unplugged it, I end up with a black screen because the wrong resolution is assigned. So same problem as you, I need to set the resolution from the TTY1 virtual terminal I can reach with Ctrl-alt-F1, but xrandr doesn't seem to work. I scoured pages of Google search results before coming upon the solution, so I thought I'd share.

The key thing is that xrandr apparently only works on the currently focused display. So you have to chain a sleep command before your xrandr command to give you time to switch back to the X server with Ctrl-alt-F7 so the command is executed there. Otherwise you get an error like xrandr: Configure crtc 0 failed.

  1. Open virtual terminal with Ctrl-alt-F1 and log in

To get the names of connected screens (and assuming your X server is running on :0 ):

  1. $xrandr -d :0

To modify display settings:

  1. $sleep 5; xrandr --output LVDS1 --auto -d :0

Substitute LVDS1 by the output you want to modify, and --auto by whatever xrandr parameters you wanna use.

  1. Switch to the X server with Ctrl-alt-F7 before the sleep delay you set in the command above elapses.

There HAS to be a better way to do this. But it works.

Original source for the solution: http://www.lgqyc.com/server-14-04-3-lts-display-orientation/

Check out this comment for a possible improvement to my solution (not tested myself).

5
  • This was the only answer that worked for me. Crazy coincidence, a 3 year old topic had the only working answer submitted 11 hours ago :). EDIT: oh snap, EXACTLY 3 years ago. Weird... Feb 25, 2016 at 12:41
  • Wow. This has been driving me nuts for ages. Your answer seems ridiculous (sleep? really?), but it works, so thank you!
    – Tyler
    Mar 17, 2016 at 22:54
  • 7
    Turns out, there is a slightly better way to do this: chvt 7; xrandr --output LVDS1 --auto -d :0. chvt 7 switches to the VT7 for you, so you don't need to sleep/Ctrl-Alt-F7. Might need a sleep 5 between the chvt and xrandr calls, but even then it saves the manual key presses.
    – Tyler
    Mar 18, 2016 at 1:13
  • One option would be to create .xsessionrc executable in your home directory and including command xrandr --auto to force automatic re-configure of all displays every time you log in. Feb 20, 2018 at 9:16
  • Adding chvy 7 was necessary for me, otherwise xrandr couldn't "open the display". This is awesome by the way; offers some insight into how all of this works!
    – vincent
    Dec 28, 2023 at 17:49
9
+100

Good question. A bit tricky to answer, but here is a try.

Basic Answer

There is actually a little reset possiblity included in X11. You can find it at /etc/X11/Xreset. You could use the Xreset directory (Xreset.d) to paste a script that runs automatically when a user logs out. The README file:

# Scripts in this directory are executed as root when a user log out from
# a display manager using /etc/X11/Xreset.
# The username of the user logging out is provided in the $USER environment
# variable.

You could thus a) add a reset script in /etc/X11/Xreset.d and b) make a script attached to a launcher that sets your dual external displays up. As such, you would log off and everything would be back to normal, you would log on to your laptop, hit the launcher for the displays and enjoy life.

More information

  1. You might want to look into sudo dpkg-reconfigure -phigh xserver-xorg for resetting the xserver or (probably better look at the answer Mik suggested in the comments).

  2. A SuSE guy wrote a nice article about X.

  3. In a solved bugreport someone states:

    admins can drop scripts in /etc/X11/Xreset.d/ to run after the user logs out.

  4. This is the contents of the file:

You can find it on your own system.

#!/bin/sh
#
# /etc/X11/Xreset
#
# global Xreset file -- for use by display managers
 
# $Id: Xsession 967 2005-12-27 07:20:55Z dnusinow $

set -e
 
PROGNAME=Xreset
SYSSESSIONDIR=/etc/X11/Xreset.d
 
if [ ! -d "$SYSSESSIONDIR" ]; then
  # Nothing to do, exiting
  exit 0
fi

# use run-parts to source every file in the session directory; we source
# instead of executing so that the variables and functions defined above
# are available to the scripts, and so that they can pass variables to each
# other
SESSIONFILES=$(run-parts --list $SYSSESSIONDIR)
if [ -n "$SESSIONFILES" ]; then
  set +e
  for SESSIONFILE in $SESSIONFILES; do
    . $SESSIONFILE
  done
  set -e
fi 

exit 0

# vim:set ai et sts=2 sw=2 tw=80:
4
  • 1
    Interesting. The reset script doesn't do anything though. I ran it through tty, restarted computer, but everything was the same. Same with putting it into the folder :| I tried putting xrandr commands inside too, but to no avail Mar 4, 2013 at 20:12
  • The reset script runs whatever is found in the Xreset.d directory.
    – don.joey
    Mar 5, 2013 at 7:59
  • 1
    Right. It didn't work for me at first, because I forgot to add executable permission to the script. Now it works like a charm. Thank you. One small remark, however. If I put the laptop to sleep and unplug monitors during that, I have not logged off and so the screen will not be reset. Is there a way to logoff myself through tty? I tried logging in as the same user who uses X, but logoff only logged me off from the tty, not from X. Mar 5, 2013 at 20:15
  • Hi Martin. I am happy you got it to work! Did you try something like gnome-session-quit? Source: askubuntu.com/questions/15795/…
    – don.joey
    Mar 6, 2013 at 6:50
5

have you tried (sth like)

DISPLAY=:0 xrandr --output LVDS1 --auto

from a different tty (e.g. tty1),

which you can access through Ctrl Alt F1 and switch back to (the standard graphical) tty7 with Ctrl Alt F7?

2
  • 1
    This is giving me xrandr: Configure crtc 1 failed when attempting --output HDMI1 --off . --auto doesn't say anything, until i manually switch it off. Then --auto throws the same error Mar 3, 2013 at 17:00
  • would need to investigate more closely; am positive it would work, eventually... Mar 3, 2013 at 17:43
2

One thing I haven't mentioned yet, but what might be critical: if you were using a Thinkpad laptop, the solution would be straightforward: Fn+F7. If you're using a different manufacturer's laptop, there will, in good likelihood, be some other Fn-type key which will toggle through the display/screen outputs (e.g., beamer, external monitor, internal display; mirror, on/off, and the like) down at the BIOS level (I'd assume - Edit: See How do Fn keys work? for more details on this).

So there'd be no need to reset anything within Linux, so to speak.

4
  • 1
    I have an IdeaPad, but the Fn+keys don't work (the only one that does is Sleep) Mar 3, 2013 at 16:52
  • My hunch is: keep going with this one! I don't have time to thoroughly investigate myself presently, though there's a good chance I could do some optimization in this field on my IBM Thinkpad X41, but -for what it's worth- most Fn keys do work on my system (both on my laptop, as well as on my external sk-8855 "thinkvantage" keyboard): in ubuntu software center (or synaptic) at a first superficial glance at least this thing tp-smapi-dkms 0.41-1 is installed. So you may wanna try installing it, looking into it and/or similar alternatives which will make your Fn keys finally come to life! Mar 3, 2013 at 17:41
  • also check out tpctl.sourceforge.net Mar 3, 2013 at 17:48
  • Hard to believe, but this was it. Switch displays - Fn+F8 on Dell Latitude. After removing from the docking station, it sometimes did not turn on the built-in display. (I use only external VGA display with the docking station.) Trying to switch the display seemed like nonsense, but it did turn on the built-in display. Oct 22, 2015 at 7:07

You must log in to answer this question.

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