如何在 Ubuntu 上使用 xserver-xorg-video-dummy 驱动运行 X 服务器

当你需要在无头服务器(即没有任何物理显示器连接)上使用虚拟显示时,首先安装虚拟驱动程序包:

install-dummy-driver.sh
sudo apt install xserver-xorg-video-dummy

之后,将此配置文件保存为 dummy-1920x1080.conf

dummy-1920x1080.conf
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

现在你可以启动 X.org

start-x-with-config.sh
sudo X -config dummy-1920x1080.conf

输出将如下所示:

xorg-start-output.txt
X.Org X Server 1.19.6
Release Date: 2017-12-20
X Protocol Version 11, Revision 0
Build Operating System: Linux 4.4.0-138-generic x86_64 Ubuntu
Current Operating System: Linux ubuntu-s-1vcpu-2gb-fra1-01 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-45-generic root=LABEL=cloudimg-rootfs ro console=tty1 console=ttyS0
Build Date: 25 October 2018  04:11:27PM
xorg-server 2:1.19.6-1ubuntu4.2 (For technical support please see http://www.ubuntu.com/support)
Current version of pixman: 0.34.0
  Before reporting problems, check http://wiki.x.org
  to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
  (++) from command line, (!!) notice, (II) informational,
  (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Sat Feb 23 17:48:07 2019
(++) Using config file: "dummy-1920x1080.conf"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"

只要你需要显示器,就需要保持此进程运行。

识别显示器编号

如果没有其他 X 服务器运行,默认情况下这将使用显示器编号 0。查找此行以识别正在使用的显示器:

xorg-log-example.txt
(==) Log file: "/var/log/Xorg.0.log", Time: Sat Feb 23 17:48:07 2019

在该行中,Xorg.0.log 告诉你显示器 0 正在使用,而 Xorg.1.log 告诉你显示器 1 正在使用。

启动你的软件

现在你可以按如下方式启动需要图形界面的软件(我们以 firefox 和显示器编号 0 为例):

start-firefox-display0.sh
DISPLAY=:0 firefox

不要忘记 DISPLAY=:0 中的冒号!

在特定显示器编号上启动 X.org

如果你想在特定显示器编号上启动 X 服务器,例如 7,因为其他虚拟服务器正在并发运行,使用此命令启动 X 服务器:

start-x-display7.sh
sudo X :7 -config dummy-1920x1080.conf

当然你需要使用 DISPLAY=:7 firefox 才能使用此配置启动 firefox!

如果该显示器上已有 X 服务器运行,你将看到类似这样的错误消息:

xorg-server-already-active-error.txt
(EE)
Fatal server error:
(EE) Server is already active for display 7
  If this server is no longer running, remove /tmp/.X7-lock
  and start again.
(EE)
(EE)
Please consult the The X.Org Foundation support
   at http://wiki.x.org
 for help.
(EE)

查找 Server is already active for display 7 以确保你看到的是相同的错误消息!


Check out similar posts by category: Linux