7
June
2021
11:52

How to change the resolution of the display from the command line Linux

7 June 2021 11:52

If the image resolution on the screen does not correspond to the passport resolution of the display, you can change the resolution using the command line.

На I have a large -format display with a resolution of 1366 by 768 pixels with the Linux Mint 19.3 operating system. Once I uploaded a computer with a disconnected display and a resolution of 1024 to 768 was established. In some way, this permission was remembered and the image became stretched.

Launching the diagnosis of the main display:

xrandr -d :0 -q

Screen 0: minimum 8 x 8, current 1024 x 768, maximum 32767 x 32767
VGA1 connected primary 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
1024x768 60.00*
800x600 60.32 56.25
848x480 60.00
640x480 59.94

As you can see, the resolution of 1024x768 is chosen by the system, marked with the symbol of the asterisk*.

Solving the problem

  1. Find out the display model (sticker on the back cover) - by the model, set the most supported resolution.
    In this case, 1366 at 768 PX at a renewal frequency of 60 Hz.

  2. Perform the CVT command with parameters corresponding to resolution and update:

cvt 1366 768 60

In my case, the following was derived:

# 1368x768 59.88 Hz (CVT) hsync: 47.79 kHz; pclk: 85.25 MHz
Modeline "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync

  1. We must take a line and submit to the entry of Xrandr to create a new mode:

    xrandr --newmode "1368x768_60.00"   85.25  1368 1440 1576 1784  768 771 781 798 -hsync +vsync

  2. Find out the name of the display - displayed by the Xrandr team:

    xrandr -d :0 -q

In my case vga1

  1. Add the display a new, previously created mode:

xrandr --addmode VGA1 1368x768_60.00

  1. Finally, he completed the command to change the permission of the image (transfer of the display to the new mode "1368x768_60.00"):

sudo xrandr --output VGA1 --mode 1368x768_60.00

The display can blink and go out. If everything went well, the image will become the chosen resolution.

If necessary, perform a restoration of permission for 1024x768:
Press Enter several times and enter the next command into the command line

sudo xrandr --output VGA1 --mode 1024x768

If necessary, we repeat the change of display mode:

xrandr --output VGA1 --mode 1368x768_60.00

click "Enter"

Sudo password entering each time is not required.


Supplement for a monitor with a resolution of 1280x1024:

cvt 1280 1024 60
xrandr --newmode "1280x1024_60.00"   109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
xrandr --addmode VGA-1 1280x1024_60.00
sudo xrandr --output VGA-1 --mode 1280x1024_60.00

Supplement from 12/29/2023: to install the resolution of displays and preserve the finished shell-script to change the screen resolution, you can use the program arandr:
sudo apt install arandr
arandr

Constant installation of display resolution at the entrance to Linux

I prescribed the following three commands to the executed file.

At first I created an empty file in a home folder

nano resolution.sh

And inserted 4 lines of text into it:

#!/bin/bash
xrandr --newmode "1368x768_60" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
xrandr --addmode VGA1 1368x768_60
xrandr --output VGA1 --mode 1368x768_60

I saved the file.

The same file, but for the monitor 1280x1024 I am attaching:
resolution.sh.zip

Gave rights - fulfillment only from the current user (owner).

sudo chmod 700 resolution.sh

Added to the bus load (I have a LXQT shell):
Start - parameters - LXQT settings - session settings - Autostart - Add
sh /home/vladimir/resolution.sh.
Confirmed and closed the window.

Another option is to add commands to a file in the user's home catalog . Xinitrc :

export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_DATA_DIRS=/usr/share/openbox:/usr/local/share/:/usr/share/


xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync
xrandr --addmode VGA-1 1280x1024_60.00
xrandr --output VGA-1 --mode 1280x1024_60.00

He went out and entered the system to check. At the entrance, the display blinked and the correct resolution of the display was used.
Also, the command file Resolution.sh can be launched from the window terminal .

case hdmi connection and several monitors

Unlike the connection above via VGA cable, using several monitors connected via HDMI interfaces, the team syntax of another:

xrandr --newmode DVI-I-1 mode_name1 ...
xrandr --newmode DVI-I-2 mode_name2 ...
xrandr --addmode DVI-I-1 mode_name1
xrandr --addmode DVI-I-2 mode_name2
xrandr --output DVI-I-1 --mode mode_name1
xrandr --output DVI-I-2 --mode mode_name1

The names of monitor interfaces can be obtained using the same command

xrandr -q

Add: SHELL command files to change resolution, for several monitors at once, you can prepare using a graphic utility Arandr (installation:sudo apt install arandr). The name Arandr deciphers as "Another Xrandr Gui" (GUI-utilita of the Xrandr installation).

Add: for the environment of the desktop lxqt (in the Lubuntu OS, the back fedora linux or in the shell installed independently) - there is a graphic utility *lxqt-config-monitor доступная в меню "Параметры" - "Настройки LXQT" - "Настройки монитора". С её помощью можно менять разрешение и частоты обновления экранов мониторов и сохранять настройки в "профиль" (файл настройки). Однако, профили разрешения экрана в LXQT не подлежат редактированию из командной строки. Утилита **lxqt-config-monitor** modifies text files:
./.config/autostart/lxqt-config-monitor-autostart.desktop
./.config/lxqt/lxqt-config-monitor.conf

The settings listed here are used when starting the LXQT session from the file ~/.xinitrc , из которого вызывается скрипт exec startlxqt.


Sources:
https: //askubuntu.com/questions/281509/...
Forum Linuxmint.com



Related publications