Skip to content

Instantly share code, notes, and snippets.

@dragolabs
Created April 29, 2020 20:09
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • 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

@dopeboy
Copy link

dopeboy commented Jan 23, 2022

this worked beautifully on ubuntu 20.04, thank you!

@sheminasalam
Copy link

I am not able to make this work with my ubuntu 20.04. Even when it displays a screen, it is stuck. only after connecting to monitor the screen becomes active. How can I diagnose the issue?

@ShinChoon
Copy link

Yes it works on Ubuntu 20.4 wireless but the original display cannot work though. So funny

@ShinChoon
Copy link

I am not able to make this work with my ubuntu 20.04. Even when it displays a screen, it is stuck. only after connecting to monitor the screen becomes active. How can I diagnose the issue?

Honestly I met such things when I only enable the screen sharing on ubuntu system settings, before install this video dummy and configure the xorg

@amenoni
Copy link

amenoni commented Sep 28, 2022

It worked perfectly for me, thank you very much for sharing this solution!

@MyraBaba
Copy link

This is working but then connecting HDMI screen is not seen its black but vnc is working.

How we can make it work togetger

@mmosquera91
Copy link

This is working but then connecting HDMI screen is not seen its black but vnc is working.

How we can make it work togetger

I still haven't found a way. I think the only easy way is using an HDMI dummy

@isdurjaldev
Copy link

this worked for me in Ubuntu 22.04

@mmosquera91
Copy link

mmosquera91 commented Jan 23, 2023 via email

@aghand0ur
Copy link

It worked for me under Ubuntu 20.04, thank you

@pityu63
Copy link

pityu63 commented Apr 24, 2023

Thank you. It worked for me Ubuntu 22.04

@HungryBoy02
Copy link

bricked my ubuntu
👍

@khanmenthe
Copy link

bricked my ubuntu +1

after it booted press CTRL + ALT + F1, and then type "sudo apt-get remove xserver-xorg-video-dummy", and then "sudo reboot".

@SeppeG
Copy link

SeppeG commented Jun 14, 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.

@guydvir2
Copy link

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

@nganunEanu
Copy link

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

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

@SawkeeReemo
Copy link

SawkeeReemo commented Mar 29, 2024

SOLVED: I typo'd the service file name... sigh. It works as it should!

I'm trying to set this up but when I try to activate the service I get an error:
Failed to enable unit: Unit file vnc-display.service does not exist.
But the file definitely exists at /etc/systemd/system/vnc-diplay.service

Is there some other step to get this registered as a service? I'm running Ubuntu LTS 22.04.

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

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