How do I save my new resolution setting with xrandr?

You have several choices but perhaps the easiest is to place your command exactly as you have given above in your $HOME/.xprofile file. From here it will be executed every time you login.

By default this file does not exist in Ubuntu and so may need to be created manually and then be made executable. The following commands will do this:

touch $HOME/.xprofile
chmod +x $HOME/.xprofile

Note the 2 small shortcomings of this method:

  1. .xprofile is accessed occurs fairly late in the startup process so you may see some initial screen resolution resizing
  2. This is a 'per user' setting and may need to be repeated for other users on your system

If you wish to delve deeper there are a few other choices available in the reference link below, but this is still the safest and easiest.

References:

  • Setting xrandr changes persistently

The accepted answer applies the same configuration regardless of the status of connected displays. This didn't work for me, as I'm connected to different displays at work and at home. autorandr allows automatic xrandr configurations for different display setup. To use autorandr,

  1. Install with sudo apt install autorandr (tested on Ubuntu 18.04)
  2. Configure your monitor to your liking with xrandr
  3. Store your configuration with autorandr --save work (I'm storing my work config, choose a name that suits you)
  4. Resume the config with autorandr --change work to choose config, or just autorandr --change to have it infer your config from your connected monitors.

XDG autostart .desktop is also provided, and installed into /etc/xdg/autostart/autorandr.desktop by default. When you reconnect your work monitor, the work setup will be reloaded.


The following simple configuration works for me, and when connected, my monitor automatically uses the correct resolution without any manual intervention.

sudo nano /etc/X11/xorg.conf

Note that this file may or may not already exist. Add the following:

Section "Monitor"
    Identifier "VGA1"
    Modeline   "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync
EndSection    

Then reboot. If all goes well, then things should just work.

Background

I have a UX32VD laptop, and I wanted to have 4K over HDMI, even though there is no 3840x2160 option in the display settings.

My first task was to compute the modeline. Skip this step if you already know the modeline. (The modeline below may work for you.) I downloaded umc-0.2.tar.gz, extracted, and ran ./configure and make. To get the 25Hz Reverse Blanking Timing mode, I ran

umc-0.2/src/umc 3840 2160 25 --rbt

which outputs

    # 3840x2160x24.99 @ 54.625kHz
    Modeline "3840x2160x24.99"  218.500000  3840 3888 3920 4000  2160 2163 2167 2186  +HSync -VSync

Next I wanted to test this modeline. Running xrandr with no arguments, I saw that my HDMI device is named HDMI-1. I tested this mode by running commands analogous to Jacob's:

xrandr --newmode "3840x2160x24.99"  218.500000  3840 3888 3920 4000  2160 2163 2167 2186  +HSync -VSync
xrandr --addmode HDMI-1 "3840x2160x24.99"
xrandr --output HDMI-1 --mode "3840x2160x24.99" --preferred

Finally, to make the resolution permanent, I created /etc/X11/xorg.conf with the following contents:

Section "Monitor"
    Identifier "HDMI-1"
    Modeline   "3840x2160x24.99"  218.500000  3840 3888 3920 4000  2160 2163 2167 2186  +HSync -VSync
EndSection  

To test, restart the computer.

I should note that I am running nvidia-driver-390 on Ubuntu 18.04. Hopefully my technique generalizes well to other configurations. (Please let me know in the comments.)