Getting ubuntu to boot with correct resolution even if the monitor is disconnected

Problem: I’m administrating several ubuntu linux boxes in a rack at a friend’s company, where there is one monitor and no KVM switch for them. Whenever someone wants to do something with one of them, they connect the monitor to the one they want to work with.

When i remotely reboot Linux after some upgrades, the computer typically doesn’t find a monitor and enters 640×480 mode. When the monitor is connected later, the display is unusable; the same happens when i vnc into the machine.

Solution: use xrandr to set the display mode upon boot.

First thing to do is to find out the correct display parameters for the screen. The easiest way to do this is connect the monitor, let the X server determine the parameters, and note them. The command xrandr –verbose will give them to you like this:

$ xrandr --verbose
    Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 32767 x 32767
    VGA1 connected 1920x1080+0+0 (0xb0) normal (normal left inverted right x axis y axis) 598mm x 336mm
        Identifier: 0x43
    ...
      1920x1080 (0xb0)  138.5MHz +HSync -VSync *current
            h: width  1920 start 1968 end 2000 total 2080 skew    0 clock   66.6KHz
            v: height 1080 start 1083 end 1088 total 1111           clock   59.9Hz
      1024x768 (0xb8)   65.0MHz -HSync -VSync
            h: width  1024 start 1048 end 1184 total 1344 skew    0 clock   48.4KHz
    ....

The important things are the output port name and resolution that are currently in use, the mode parameters, and the display frequency.

We’ll add the commands to create this mode, and switch to it, in the .xprofile file. (This assumes autologin is enabled, so the .xprofile gets executed shortly after boot). Put the following into $HOME/.xprofile, adjusting the parameters to your xrandr output:

    xrandr --fb 1920x1080
    xrandr --newmode "1920x1080_59.9" 138.5 1920 1968 2000 2080 1080 1083 1088 1111 +HSync -VSync
    xrandr --addmode VGA1 "1920x1080_59.9"
    xrandr --output VGA1 --mode 1920x1080_59.9

For the mode name, you can actually use any string you want, as long as it isn’t one of the names the X server assigns to the modes from your monitor. I took the resolution + frequency to get a meaningful name, but “goldfish” or “nerdyone” work just as well as long as you stay consistent.

Now, when you reboot without your monitor attached, this mode should be set automatically just after login.

 

Leave a Reply

Your email address will not be published. Required fields are marked *