Skip to content

Instantly share code, notes, and snippets.

@dragolabs
Created April 29, 2020 20:09
Show Gist options
  • Save dragolabs/8e559113567faed32327ef24fdce775b to your computer and use it in GitHub Desktop.
Save dragolabs/8e559113567faed32327ef24fdce775b to your computer and use it in GitHub Desktop.
Run VNC without connected monitor to ubuntu Desktop

Install Video Dummy Package

sudo apt-get install xserver-xorg-video-dummy

Create Default X Windows Configuration File

Create / Edit xorg.conf file Rename file if already exists for backup

sudo vi /usr/share/X11/xorg.conf.d/xorg.conf

Add the following content to the file Set the resolution to what you like (whatever resolution the screen is that is used to connect remotely is probably is a good idea)

Section "Device"
    Identifier  "Configured Video Device"
    Driver      "dummy"
EndSection

Section "Monitor"
    Identifier  "Configured Monitor"
    HorizSync 31.5-48.5
    VertRefresh 50-70
EndSection

Section "Screen"
    Identifier  "Default Screen"
    Monitor     "Configured Monitor"
    Device      "Configured Video Device"
    DefaultDepth 24
    SubSection "Display"
    Depth 24
    Modes "1920x1080"
    EndSubSection
EndSection

Save the file Reboot and Test

@DasKraut37
Copy link

DasKraut37 commented Apr 11, 2024

#!/bin/bash
# Check connected displays
if xrandr | grep -q "[DP+VGA+HDMI+DVI-I]-[0-9]\+\(\.[0-9]\+\)\? connected"; then
  # If yes, disable the dummy driver configuration by renaming the file
  sudo mv /etc/X11/xorg.conf.d/dummy.conf /etc/X11/xorg.conf.d/dummy.conf.bak
else
  # If no, enable the dummy driver configuration by restoring the file
  sudo mv /etc/X11/xorg.conf.d/dummy.conf.bak /etc/X11/xorg.conf.d/dummy.conf
  sudo X :0 -config /etc/X11/xorg.conf.d/dummy.conf &
fi

This script looks for a file that doesn't exist. I just searched my entire Ubuntu LTS 22.04 system for dummy.conf and it doesn't exist anywhere. Maybe things changed since this was originally written? Any idea how to make this script work not in 2024? Thanks!

And just to clarify: Yes, I've followed all of the instruction above and can currently connect to my headless Linux box over VNC without having a monitor plugged in. But I still need to be able to connect a real monitor on occasion.

FOLLOW UP QUESTION: In the script above, are you sure you don't mean /usr/share/X11/xorg.conf.d/xorg.conf instead of /etc/X11/xorg.conf.d/dummy.conf?

@imsan29
Copy link

imsan29 commented Apr 16, 2024

#!/bin/bash
# Check connected displays
if xrandr | grep -q "[DP+VGA+HDMI+DVI-I]-[0-9]\+\(\.[0-9]\+\)\? connected"; then
  # If yes, disable the dummy driver configuration by renaming the file
  sudo mv /etc/X11/xorg.conf.d/dummy.conf /etc/X11/xorg.conf.d/dummy.conf.bak
else
  # If no, enable the dummy driver configuration by restoring the file
  sudo mv /etc/X11/xorg.conf.d/dummy.conf.bak /etc/X11/xorg.conf.d/dummy.conf
  sudo X :0 -config /etc/X11/xorg.conf.d/dummy.conf &
fi

This script looks for a file that doesn't exist. I just searched my entire Ubuntu LTS 22.04 system for dummy.conf and it doesn't exist anywhere. Maybe things changed since this was originally written? Any idea how to make this script work not in 2024? Thanks!

And just to clarify: Yes, I've followed all of the instruction above and can currently connect to my headless Linux box over VNC without having a monitor plugged in. But I still need to be able to connect a real monitor on occasion.

FOLLOW UP QUESTION: In the script above, are you sure you don't mean /usr/share/X11/xorg.conf.d/xorg.conf instead of /etc/X11/xorg.conf.d/dummy.conf?

I made that switch from /etc/X11/xorg.conf.d/dummy.conf to /usr/share/X11/xorg.conf.d/xorg.conf and it seems to be working well with finding the file, however whenever I reboot and check status using sudo systemctl status vnc-display, the xrandr if statement within the vnc script always returns an error:
Apr 16 07:37:55 ODS-001 vnc-display.sh[1322]: Can't open display
and then moves to else whether or not I have a connected display. However, when I manually run the "if" line after reboot, it returns true. How can I get xrandr to run within the script file?

@kylesherry
Copy link

#!/bin/bash
# Check connected displays
if xrandr | grep -q "[DP+VGA+HDMI+DVI-I]-[0-9]\+\(\.[0-9]\+\)\? connected"; then
  # If yes, disable the dummy driver configuration by renaming the file
  sudo mv /etc/X11/xorg.conf.d/dummy.conf /etc/X11/xorg.conf.d/dummy.conf.bak
else
  # If no, enable the dummy driver configuration by restoring the file
  sudo mv /etc/X11/xorg.conf.d/dummy.conf.bak /etc/X11/xorg.conf.d/dummy.conf
  sudo X :0 -config /etc/X11/xorg.conf.d/dummy.conf &
fi

This script looks for a file that doesn't exist. I just searched my entire Ubuntu LTS 22.04 system for dummy.conf and it doesn't exist anywhere. Maybe things changed since this was originally written? Any idea how to make this script work not in 2024? Thanks!
And just to clarify: Yes, I've followed all of the instruction above and can currently connect to my headless Linux box over VNC without having a monitor plugged in. But I still need to be able to connect a real monitor on occasion.
FOLLOW UP QUESTION: In the script above, are you sure you don't mean /usr/share/X11/xorg.conf.d/xorg.conf instead of /etc/X11/xorg.conf.d/dummy.conf?

I made that switch from /etc/X11/xorg.conf.d/dummy.conf to /usr/share/X11/xorg.conf.d/xorg.conf and it seems to be working well with finding the file, however whenever I reboot and check status using sudo systemctl status vnc-display, the xrandr if statement within the vnc script always returns an error: Apr 16 07:37:55 ODS-001 vnc-display.sh[1322]: Can't open display and then moves to else whether or not I have a connected display. However, when I manually run the "if" line after reboot, it returns true. How can I get xrandr to run within the script file?

After fighting with this for hours, I made a few tweaks to get around the "can't open display " error.
First:
I used the answer here: https://askubuntu.com/questions/1274241/xrandr-script-for-external-monitor-adjustment-not-executing-from-udev and used a different IF statement that looks for the connection status in /sys/class/drm. My machine only has 1 DisplayPort so I only need to check one place for the status.

DP_Status= cat /sys/class/drm/card0-DP-1/status if [ $DP_Status = "connected" ] then sudo mv /etc/X11/xorg.conf /etc/X11/xorg.conf.bak else sudo mv /etc/X11/xorg.conf.bak /etc/X11/xorg.conf sudo X :0 -config /etc/X11/xorg.conf & fi

Second:
The script correctly updated the xorg.conf file, but on boot, it was still loading when connected to DisplayPort.
I assumed the script was running after the xorg.conf file was loaded because it had been updated to xorg.conf.bak. I changed the after statement in the vnc-display.service to
After=systemd-user-sessions.service
I grabbed the same after service as the display manger.

I also changed the x11vnc.service:
Requires=vnc-display.service After=vnc-display.service

Now, when I boot without displayport connected, it loads the dummy display and if I boot with displayport connected, it uses displayport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment