How to reset monitor settings to default through terminal?

Solution 1:

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/

Solution 2:

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 Ctlr-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).

Solution 3:

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:

Solution 4:

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?

Solution 5:

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.