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

@giatrada
Copy link

giatrada commented Nov 15, 2023

I found a way to be able to keep using connected displays

The follow scripts will check on startup if there is a display connected, if not, it will enable the dummy display.

  1. Create a service unit file /etc/systemd/system/vnc-diplay.service
[Unit]
Description=Configure VNC dummy screen
After=network-online.target

[Service]
ExecStart=/usr/local/bin/vnc-display.sh

[Install]
WantedBy=multi-user.target
  1. Create a script /usr/local/bin/vnc-display.sh
#!/bin/bash
# Check connected displays
if xrandr | grep -q "DP-[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  
  

and make it executable with chmod +x /usr/local/bin/vnc-display.sh

  1. To enable the service to run on startup, use the command sudo systemctl enable vnc-display.service

This script only checks for displays connected with a displayport, you can change the xrandr grep command to check for different connections.

how to use it for hdmi?? cuz i change the dp to hdmi didnt work

#!/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

Send to you ^^

@Flyalay
Copy link

Flyalay commented Dec 13, 2023

can i config two dummy monitors?

@linuxnand
Copy link

linuxnand commented Feb 22, 2024

I found a way to be able to keep using connected displays

The follow scripts will check on startup if there is a display connected, if not, it will enable the dummy display.

  1. Create a service unit file /etc/systemd/system/vnc-diplay.service
[Unit]
Description=Configure VNC dummy screen
After=network-online.target

[Service]
ExecStart=/usr/local/bin/vnc-display.sh

[Install]
WantedBy=multi-user.target
  1. Create a script /usr/local/bin/vnc-display.sh
#!/bin/bash
# Check connected displays
if xrandr | grep -q "DP-[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  
  

and make it executable with chmod +x /usr/local/bin/vnc-display.sh

  1. To enable the service to run on startup, use the command sudo systemctl enable vnc-display.service

This script only checks for displays connected with a displayport, you can change the xrandr grep command to check for different connections.

Is there a way to force to check if there is a display connected without rebooting?
Maybe logging out and back in?

@paelnever
Copy link

paelnever commented Mar 1, 2024

Partially worked for me, Ubuntu 22.04. Got max resolution as 1280x720.

tried to update grub's default resolution - without any luck. Please help. Guy

Same trouble here.
Anybody was able to make it work for screen resolutions greater than 1360x768?
I guess it must be a trouble with xserver-xorg-video-dummy because it was working at full resolution in VNC when physical monitor was directly connected.

@DasKraut37
Copy link

Just found this, and it immediately fixed my issue not being able to connect via RealVNC to my new miniPC. Thank you for that! I do seem to be locked to 1280x720 as well. But it's a good compromise for now. Would love to know if anyone finds a solution to the max resolution. Thanks to all who have contributed here as well!

@DasKraut37
Copy link

Just an update, I haven't tried this yet, but I did find this tonight: https://techoverflow.net/2019/02/23/how-to-run-x-server-using-xserver-xorg-video-dummy-driver-on-ubuntu/

@CabinetGuy1966
Copy link

It is always nice to get feedback, so I want to let you know this helped me! I have been bashing my head against my keyboard for weeks trying to figure this out, and your solution worked! Thank you so much, I hope you have an amazing day!

@ijwfly
Copy link

ijwfly commented Mar 23, 2024

Just an update, I haven't tried this yet, but I did find this tonight: https://techoverflow.net/2019/02/23/how-to-run-x-server-using-xserver-xorg-video-dummy-driver-on-ubuntu/

This configuration works just fine. I'll paste it here just to be sure it will never be missed.

Section "Monitor"
  Identifier "Monitor0"
  HorizSync 28.0-80.0
  VertRefresh 48.0-75.0
  # https://arachnoid.com/modelines/
  # 1920x1080 @ 60.00 Hz (GTF) hsync: 67.08 kHz; pclk: 172.80 MHz
  Modeline "1920x1080_60.00" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 -HSync +Vsync
EndSection
Section "Device"
  Identifier "Card0"
  Driver "dummy"
  VideoRam 256000
EndSection
Section "Screen"
  DefaultDepth 24
  Identifier "Screen0"
  Device "Card0"
  Monitor "Monitor0"
  SubSection "Display"
    Depth 24
    Modes "1920x1080_60.00"
  EndSubSection
EndSection

Also, you can generate your own Modeline here: https://arachnoid.com/modelines/

@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.

@chandler150
Copy link

chandler150 commented Nov 15, 2024

Just an update, I haven't tried this yet, but I did find this tonight: https://techoverflow.net/2019/02/23/how-to-run-x-server-using-xserver-xorg-video-dummy-driver-on-ubuntu/

This configuration works just fine. I'll paste it here just to be sure it will never be missed.

Section "Monitor"
  Identifier "Monitor0"
  HorizSync 28.0-80.0
  VertRefresh 48.0-75.0
  # https://arachnoid.com/modelines/
  # 1920x1080 @ 60.00 Hz (GTF) hsync: 67.08 kHz; pclk: 172.80 MHz
  Modeline "1920x1080_60.00" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 -HSync +Vsync
EndSection
Section "Device"
  Identifier "Card0"
  Driver "dummy"
  VideoRam 256000
EndSection
Section "Screen"
  DefaultDepth 24
  Identifier "Screen0"
  Device "Card0"
  Monitor "Monitor0"
  SubSection "Display"
    Depth 24
    Modes "1920x1080_60.00"
  EndSubSection
EndSection

Also, you can generate your own Modeline here: https://arachnoid.com/modelines/

This worked well for me, new maximum I can get is 2048x1152, and that is with the modeline line replaced with

# 3840x2160 @ 60.00 Hz (GTF) hsync: 134.10 kHz; pclk: 712.34 MHz
Modeline "3840x2160_60.00" 712.34 3840 4152 4576 5312 2160 2161 2164 2235 -HSync +Vsync

Not sure why it's capping there yet, but useful

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