• 欢迎访问伊栖物联网社区,聚焦物联网技术和解决方案QQ群:735553309
  • ,从传感器到片上嵌入式系统,无线接入,边缘计算,在这里您可以讨论一切
  • 参加最新的物联网研讨会报名
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏伊栖Eccee

在ubuntu 20.04中用虚拟显卡创建远程虚拟桌面

软件和平台 peyoot 2年前 (2021-12-21) 3236次浏览 0个评论

vnc,nomachine或Teamviwer等远程终端一般用于接有显示器的桌面系统。但有时我们需要在无显示终端上操作,或是因为笔记本合盖关闭显卡等原因无法使用这些远程桌面工具,这时虚拟显卡就可以派上用场。
根据你的硬件平台,以确定是否要用#号内的命令。注意,如果出错进不了桌面并切不了命令行,可以用维护模式删除xserver-xorg-core来进入命令行模式重新安装X桌面。

sudo apt install xorg-video-abi-20 xserver-xorg-core 
sudo apt-get install xserver-xorg-video-dummy
#sudo apt install xserver-xorg-core-hwe-18.04
#sudo apt install xserver-xorg-video-dummy --fix-missing
#下载xorg.conf或自己创建
#sudo wget -P /etc/X11 https://gist.githubusercontent.com/mangoliou/ba126832f2fb8f86cc5b956355346038/raw/b6ad063711226fdd6413189ad905943750d64fd8/xorg.conf
nano  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

如果之前就是没有显示器的linux系统,可以把上面下载的xorg.conf放在X11默认支持的位置 /etc/X11/xorg.conf。如果已经有桌面,最好是另存为dummy-1920×1080.conf。
先配置默认不进入桌面,

sudo systemctl set-default multi-user.target 
sudo reboot

而是手工开启一个X。

sudo X -config dummy-1920x1080.conf

输出内容像这样:

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"

注意Log file这句,Xorg.0.log表示是使用了DISPLAY 0显示号。

在指定桌面启动程序,比如firefox:

DISPLAY=:0 firefox

其实也可以直接在启动X时指定显示号,如:

sudo X :7 -config dummy-1920x1080.conf

安装了虚拟显示器之后,打开Nomachine的时候可能会出现一下情况,可以通过运行下面这条命令开启屏幕共享。

sudo /usr/NX/bin/nxserver   --useredit ${USER}  --screensharing yes

另外,要查询是否使用虚拟显示器,用xrandr -q即可。

后记:这个方式适用于没有显示器的设备开启远程桌面,把上面的xorg.conf放在/etc/X11/下即可。 但我本意是笔记本合盖时不会息屏,无耐这是linux驱动决定的,当笔记本合上时,它会把显示输出关闭,远程桌面也就关了。因此如果想在笔记本息屏时使用,可能要用虚拟显示器,也就是欺骗显卡有显示器接着,在淘宝上很多。


ECCEE版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:在ubuntu 20.04中用虚拟显卡创建远程虚拟桌面
喜欢 (7)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址