Persist NVIDIA X Server Settings

I have an X Server Configuration that I made using the NVIDIA X Server Settings application in Ubuntu 20.04.1 LTS x86_64 i.e.:

enter image description here

The configuration is as follows:

~$ cat /etc/X11/xorg.conf
# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings:  version 440.82

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    Option         "Xinerama" "0"
EndSection

Section "Files"
EndSection

Section "Module"
    Load           "dbe"
    Load           "extmod"
    Load           "type1"
    Load           "freetype"
    Load           "glx"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    # HorizSync source: edid, VertRefresh source: edid
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "SAMSUNG"
    HorizSync       15.0 - 81.0
    VertRefresh     24.0 - 75.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce GTX 1080 Ti"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "Stereo" "0"
    Option         "nvidiaXineramaInfoOrder" "DFP-1"
    Option         "metamodes" "HDMI-0: 3840x2160 +0+0, DP-5: nvidia-auto-select +0+0 {viewportin=3840x2160, ForceCompositionPipeline=On, ForceFullCompositionPipeline=On}"
    Option         "SLI" "Off"
    Option         "MultiGPU" "Off"
    Option         "BaseMosaic" "off"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

I noticed first that at boot, my configuration is not loaded so I created a .xinitrc:

~$ cat /home/sterlingbutters/.xinitrc
nvidia-settings --load-config-only &
. /etc/X11/xinit/xinitrc

for reference:

~$ cat /etc/X11/xinit/xinitrc
#!/bin/sh

# /etc/X11/xinit/xinitrc
#
# global xinitrc file, used by all X sessions started by xinit (startx)

# invoke global X session script
. /etc/X11/Xsession

This appears to work and the configuration is loaded correctly at login. Unfortunately, if I power off/on my tv/monitor then the configuration reverts to a non-preferred setting. How can I always get this configuration to persist no matter what?

Some (potentially) notable mentions:

  • Whenever I exit the server configuration it prompts me with a message saying I have unsaved changes even though I click apply and “Save to X Configuration File”.
  • I am using lightdm

thanks in advance

From the screenshot, it looks like you’re using GNOME. Is that correct? GNOME has its own display manager control panel and will try to apply the settings from that automatically when it detects monitor hot plug or unplug events.

Please try configuring the display layout you want in the GNOME control panel rather than in nvidia-settings.

Wow thank you so much for the quick response!

Yes I am using GNOME. Unfortunately the display manager control panel does not correctly identify the resolution of my second monitor/display so I cannot make the correct selection (whereas I can with NVIDIA manager). Is there a way to disable GNOME hot/un-plug events (or load NVIDIA config for these events)?

Also FYI on last reboot my NVIDIA configuration was not loaded at login.

I’m not sure. There used to be an option to disable the xrandr handling in gnome-settings-daemon, but I don’t think that works anymore. I’d suggest filing an issue against GNOME about the missing resolutions.

Although looking at your screenshot again, I’m kind of curious – is this configuration scaling 3840x2160 down to 1920x1080 for the DP-5 output?

The DP-5 output is actually connected to a capture card hooked up to Pi-KVM. Allegedly the capture card is capable of 4k pass-through though I have had varying mileage with this - additionally just switching the input to the capture card pass-through output is not a legitimate test since in doing so a hotplug event is instantiated (causing the native display manager to attempt reconfiguration). However, the actual capture is 1920x1080.

Some helpful info for my case:

The display settings I configured in nvidia-settings do not persist.
Depending on the type of configuration being performed, nvidia-settings will save configuration changes to one of several places:

  • Static X server configuration changes are saved to the X configuration file (e.g. /etc/X11/xorg.conf ). These settings are loaded by the X server when it starts, and cannot be changed without restarting X.
  • Dynamic, user-specific configuration changes are saved to ~/.nvidia-settings-rc . nvidia-settings loads this file and applies any settings contained within. These settings can be changed without restarting the X server, and can typically be configured through the nvidia-settings command line interface as well, or via the RandR and/or NV-CONTROL APIs.
  • User-specific application profiles edited in nvidia-settings are saved to ~/.nv/nvidia-application-profiles-rc . This file is loaded along with the other files in the application profile search path by the NVIDIA OpenGL driver when it is loaded by an OpenGL application. The driver evaluates the application profiles to determine which settings apply to the application. Changes made to this configuration file while an application is already running will be applied when the application is next restarted. See Appendix J, Application Profiles for more information about application profiles.

Settings in ~/.nvidia-settings-rc only take effect when processed by nvidia-settings , and therefore will not be loaded by default when starting a new X session. To load settings from ~/.nvidia-settings-rc without actually opening the nvidia-settings control panel, use the --load-config-only option on the nvidia-settings command line. nvidia-settings --load-config-only can be added to your login scripts to ensure that your settings are restored when starting a new desktop session.

Even after nvidia-settings has been run to restore any settings set in ~/.nvidia-settings-rc , some desktop environments (e.g. GNOME, KDE, Unity, Xfce) include advanced display configuration tools that may override settings that were configured via nvidia-settings . These tools may attempt to restore their own display configuration when starting a new desktop session, or when events such as display hotplugs, resolution changes, or VT switches occur.

These tools may also override some types of settings that are stored in and loaded from the X configuration file, such as any MetaMode strings that may specify the initial display layouts of NVIDIA X screens. Although the configuration of the initial MetaMode is static, it is possible to dynamically switch to a different MetaMode after X has started. This can have the effect of making the set of active displays, their resolutions, and layout positions as configured in the nvidia-settings control panel appear to be ineffective, when in reality, this configuration was active when starting X and then overridden later by the desktop environment.

If you believe that your desktop environment is overriding settings that you configured in nvidia-settings , some possible solutions are:

  • Use the display configuration tools provided as part of the desktop environment (e.g. gnome-control-center display , gnome-display-properties , kcmshell4 display , unity-control-center display , xfce4-display-settings ) to configure your displays, instead of the nvidia-settings control panel or the xrandr command line tool. Setting your desired configuration using the desktop environment’s tools should cause that configuration to be the one which is restored when the desktop environment overrides the existing configuration from nvidia-settings . If you are not sure which tools your desktop environment uses for display configuration, you may be able to discover them by navigating any available system menus for “Display” or “Monitor” control panels.
  • For settings loaded from ~/.nvidia-settings-rc which have been overridden, run nvidia-settings --load-config-only as needed to reload the settings from ~/.nvidia-settings-rc .
  • Disable any features your desktop environment may have for managing displays. (Note: this may disable other features, such as display configuration tools that are integrated into the desktop.)
  • Use a different desktop environment which does not actively manage display configuration, or do not use any desktop environment at all.

Some systems may have multiple different display configuration utilities, each with its own way of managing settings. In addition to conflicting with nvidia-settings , such tools may conflict with each other. If your system uses more than one tool for configuring displays, make sure to check the configuration of each tool when attempting to determine the source of any unexpected display settings.
My displays are reconfigured in unexpected ways when I plug in or unplug a display, or power a display off and then power it on again.
This is a special case of the issues described in “The display settings I configured in nvidia-settings do not persist.”. Some desktop environments which include advanced display configuration tools will automatically configure the display layout in response to detected configuration changes. For example, when a new display is plugged in, such a desktop environment may attempt to restore the previous layout that was used with the set of currently connected displays, or may configure a default layout based upon its own policy.

On X servers with support for RandR 1.2 or later, the NVIDIA X driver reports display hotplug events to the X server via RandR when displays are connected and disconnected. These hotplug events may trigger a desktop environment with advanced display management capabilities to change the display configuration. These changes may affect settings such as the set of active displays, their resolutions and positioning relative to each other, per-display color correction settings, and more.

In addition to hotplug events generated by connecting or disconnecting displays, DisplayPort displays will generate a hot unplug event when they power off, and a hotplug event when they power on, even if no physical plugging in or unplugging takes place. This can lead to hotplug-induced display configuration changes without any actual hotplug action taking place.

If display hotplug events are resulting in undesired configuration changes, try the solutions and workarounds listed in “The display settings I configured in nvidia-settings do not persist.”. Another workaround would be to disable the NVIDIA X driver’s reporting of hotplug events with the UseHotplugEvents X configuration option. Note that this option will have no effect on DisplayPort devices, which must report all hotplug events to ensure proper functionality.

It would be nice to know exactly how NVIDIA configs, xrandr, and display manager interact to develop the needed configuration since I doubt filing an issue with GNOME will be timely.