当显卡为纯视频加速卡时,有可能没有视频输出接口,当Eable这种加速卡为显示卡时,可能会导致没有办法正常启动操作系统的UI 界面。最近我就遇到了一张这样的视频加速卡,一个视频输出口都没有就想一张内存卡一样插上去纯靠PCIe插槽来使用。
因为主机之前有集成显卡,所以可以完成正常的安装系统等工作,也可以正常启动UI,但是当Enable 这个显卡时,集成显卡就会被Disable掉,这样原来的集成显卡输出口就没有了视频画面。我在Ubuntu 上Enable 了视频加速卡重启后,通过SSH远程上去可以使用Ubuntu的Terminal,但是我需要启动一个XWindow来启动一个有图形界面的应用,如Unity的程序。
正文
当Ubuntu 没有接入显示器时,或ssh远程连接时,Terminal 是没有显示器的。可以使用xrandr
来查看是否有显示器。如下:
~/Documents/$ xrandr
Can't odmpen display
这时候如果系统中有显示设备或Ubuntu插了显示器,且用户已经登录显示这时候就可以使用export DISPLAY=:0.0
。
重要前提Ubuntu 装了 Xwindow,也就是xorg,没有装就先装一下吧,正常Ubuntu 安装时带UI界面也就是Xorg。安装了却没有起来后面说。
如果有显示器是:
Screen 0: minimum 320 x 200, current 1280 x 720, maximum 16384 x 16384
DisplayPort-0 disconnected (normal left inverted right x axis y axis)
DisplayPort-1 disconnected (normal left inverted right x axis y axis)
DisplayPort-2 connected primary 1280x720+0+0 (normal left inverted right x axis y axis) 410mm x 230mm
1366x768 59.79 +
1280x1024 75.02
1280x720 59.79*
1024x768 75.03 60.00
800x600 75.00 60.32
640x480 75.00 59.94
720x400 70.08
DisplayPort-3 disconnected (normal left inverted right x axis y axis)
HDMI-A-0 disconnected (normal left inverted right x axis y axis)
HDMI-A-1 disconnected (normal left inverted right x axis y axis)
如果没有显示器:
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 16384 x 16384
DP-1 disconnected primary (normal left inverted right x axis y axis)
HDMI-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)
HDMI-3 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
HDMI-4 disconnected (normal left inverted right x axis y axis)
如果没有显示器修改/usr/share/X11/xorg.conf.d/xorg.conf
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 16384 x 16384
DisplayPort-0 disconnected primary (normal left inverted right x axis y axis)
DisplayPort-1 disconnected (normal left inverted right x axis y axis)
DisplayPort-2 disconnected 1366x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
DisplayPort-3 disconnected (normal left inverted right x axis y axis)
HDMI-A-0 disconnected (normal left inverted right x axis y axis)
HDMI-A-1 disconnected (normal left inverted right x axis y axis)
1366x768 (0x5c) 85.500MHz +HSync +VSync
h: width 1366 start 1436 end 1579 total 1792 skew 0 clock 47.71KHz
v: height 768 start 771 end 774 total 798 clock 59.79Hz
xorg.conf 文件格式
因为工作关系,自己的配置文件就不发了,发一个网上别人1的吧:
Section "Monitor"
Identifier "Monitor0"
HorizSync 28.0-80.0
VertRefresh 48.0-75.0
# https://arachnoid.com/modelines/
# 1024x768 @ 60.00 Hz (GTF) hsync: 47.70 kHz; pclk: 64.11 MHz
Modeline "1024x768_60.00" 64.11 1024 1080 1184 1344 768 769 772 795 -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 "1024x768_60.00"
EndSubSection
EndSection
走到这里基本Xwindow就已经起好了,测试可以命令行启动一个编辑器然后使用VNC连接看下就可以看到VNC里面有一个编辑器。VNC需要后于应用起动。
安装了Xorg 但是没有启动
首先检查一下进程中有没有这个进程:
$ ps axu |grep -i xorg
如果有下面的进程那就启动好了,只需要设置display port 就可以了。
tayu 1381 0.0 0.5 1736804 92964 tty2 Sl+ 15:01 0:00 /usr/lib/xorg/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -background none -noreset -keeptty -verbose 3
没有的话,使用下面命令来启动吧:
$ sudo ll
$ sudo /usr/bin/X -sharevts&
不使用sudo 可能会报一些BusID 或者没有权限的错误。上面的sudo ll
是为了让terminal记住sudo的密码,要么会卡到输入密码的位置,并不能启动xorg,启动了ctrl + C 是退不出来的,所有放到后台运行不要运行只能Kill了。
安装启动VNC
$ mkdir ~/.vnc
$ x11vnc -storepasswd ~/.vnc/passwd
$ x11vnc -rfbauth ~/.vnc/passwd -display :0 -forever -bg -repeat -nowf -o ~/.vnc/x11vnc.log
终端启动gedit 测试
$ gedit
如何假装自己的Ubuntu 显卡导致用户界面没法启动呢?
方法就是关闭Ubuntu的UI,让默认就只启动终端。
引用别人2的方法:
// 关闭
sudo systemctl set-default multi-user.target
sudo reboot
// 开启
sudo systemctl set-default graphical.target
sudo reboot