安裝Nvidia GPU專屬驅動後Xorg的變化

背景

安裝Nvidia GPU專屬驅動後(zhuanlan.zhihu.com/p/28),Linux系統在啟動桌面系統(當然說的就是老舊的X Server)的時候會和之前有什麼變化嗎?gemfield本文以kUbuntu 17.10為例。

配置文件的變化

1,/etc/X11/xorg.conf

安裝Nvidia驅動後,會生成/etc/X11/xorg.conf配置文件(默認是沒有的),這樣,X Server在啟動的時候,就會首先從/etc/X11/xorg.conf 讀取配置來改變自己的行為:

gemfield@ai:~$ cat /etc/X11/xorg.conf# nvidia-xconfig: X configuration file generated by nvidia-xconfig# nvidia-xconfig: version 384.90 (buildmeister@swio-display-x86-rhel47-05) Tue Sep 19 18:13:03 PDT 2017Section "ServerLayout" Identifier "Layout0" Screen 0 "Screen0" InputDevice "Keyboard0" "CoreKeyboard" InputDevice "Mouse0" "CorePointer"EndSectionSection "Files"EndSectionSection "InputDevice" # generated from default Identifier "Mouse0" Driver "mouse" Option "Protocol" "auto" Option "Device" "/dev/psaux" Option "Emulate3Buttons" "no" Option "ZAxisMapping" "4 5"EndSectionSection "InputDevice" # generated from default Identifier "Keyboard0" Driver "kbd"EndSectionSection "Monitor" Identifier "Monitor0" VendorName "Unknown" ModelName "Unknown" HorizSync 28.0 - 33.0 VertRefresh 43.0 - 72.0 Option "DPMS"EndSectionSection "Device" Identifier "Device0" Driver "nvidia" VendorName "NVIDIA Corporation"EndSectionSection "Screen" Identifier "Screen0" Device "Device0" Monitor "Monitor0" DefaultDepth 24 SubSection "Display" Depth 24 EndSubSectionEndSection

這個配置文件的ServerLayout section會在X Server啟動的時候產生一些效果,就是下面log中有(**) 前綴的:

[ 42.691] Markers: (--) probed, (**) from config file, (==) default setting, (++) from command line, (!!) notice, (II) informational, (WW) warning, (EE) error, (NI) not implemented, (??) unknown.[ 42.691] (==) Log file: "/var/log/Xorg.0.log", Time: Sat Feb 24 09:52:05 2018[ 42.691] (==) Using config file: "/etc/X11/xorg.conf"[ 42.691] (==) Using system config directory "/usr/share/X11/xorg.conf.d"[ 42.692] (==) ServerLayout "Layout0"[ 42.692] (**) |-->Screen "Screen0" (0)[ 42.692] (**) | |-->Monitor "Monitor0"[ 42.692] (**) | |-->Device "Device0"[ 42.692] (**) |-->Input Device "Keyboard0"[ 42.692] (**) |-->Input Device "Mouse0"[ 42.692] (==) Automatically adding devices[ 42.692] (==) Automatically enabling devices[ 42.692] (==) Automatically adding GPU devices[ 42.692] (==) Automatically binding GPU devices

而InputDevice section會在X server啟動的時候產生下面的效果:

[ 42.692] (WW) Hotplugging is on, devices using drivers kbd, mouse or vmmouse will be disabled.[ 42.692] (WW) Disabling Keyboard0[ 42.692] (WW) Disabling Mouse0

重要的來了,Device section會產生下面的效果:

[ 42.697] (II) "glx" will be loaded by default.[ 42.697] (II) LoadModule: "glx"[ 42.697] (II) Loading /usr/lib/x86_64-linux-gnu/xorg/extra-modules/libglx.so[ 42.703] (II) Module glx: vendor="NVIDIA Corporation"[ 42.703] compiled for 4.0.2, module version = 1.0.0[ 42.703] Module class: X.Org Server Extension[ 42.703] (II) NVIDIA GLX Module 384.111 Tue Dec 19 22:51:13 PST 2017[ 42.703] (II) LoadModule: "nvidia"[ 42.703] (II) Loading /usr/lib/x86_64-linux-gnu/xorg/extra-modules/nvidia_drv.so[ 42.703] (II) Module nvidia: vendor="NVIDIA Corporation"[ 42.703] compiled for 4.0.2, module version = 1.0.0[ 42.703] Module class: X.Org Video Driver[ 42.703] (II) NVIDIA dlloader X Driver 384.111 Tue Dec 19 22:25:34 PST 2017[ 42.703] (II) NVIDIA Unified Driver for all Supported NVIDIA GPUs[ 42.703] (II) Loading sub module "fb"[ 42.703] (II) LoadModule: "fb"[ 42.703] (II) Loading /usr/lib/xorg/modules/libfb.so[ 42.704] (II) Module fb: vendor="X.Org Foundation"[ 42.704] compiled for 1.19.5, module version = 1.0.0[ 42.704] ABI class: X.Org ANSI C Emulation, version 0.4[ 42.704] (II) Loading sub module "wfb"[ 42.704] (II) LoadModule: "wfb"[ 42.704] (II) Loading /usr/lib/xorg/modules/libwfb.so[ 42.704] (II) Module wfb: vendor="X.Org Foundation"[ 42.704] compiled for 1.19.5, module version = 1.0.0[ 42.704] ABI class: X.Org ANSI C Emulation, version 0.4[ 42.704] (II) Loading sub module "ramdac"[ 42.704] (II) LoadModule: "ramdac"[ 42.704] (II) Module "ramdac" already built-in[ 42.704] (**) NVIDIA(0): Depth 24, (--) framebuffer bpp 32[ 42.704] (==) NVIDIA(0): RGB weight 888[ 42.704] (==) NVIDIA(0): Default visual is TrueColor[ 42.704] (==) NVIDIA(0): Using gamma correction (1.0, 1.0, 1.0)[ 42.704] (**) NVIDIA(0): Enabling 2D acceleration[ 42.737] (--) NVIDIA(0): Valid display device(s) on GPU-0 at PCI:76:0:0[ 42.737] (--) NVIDIA(0): DFP-0[ 42.737] (--) NVIDIA(0): DFP-1[ 42.737] (--) NVIDIA(0): DFP-2[ 42.737] (--) NVIDIA(0): DFP-3[ 42.737] (--) NVIDIA(0): DFP-4[ 42.737] (--) NVIDIA(0): DFP-5[ 42.737] (--) NVIDIA(0): DFP-6 (boot)[ 42.739] (II) NVIDIA(0): NVIDIA GPU GeForce GTX 1080 Ti (GP102-A) at PCI:76:0:0[ 42.739] (II) NVIDIA(0): (GPU-0)[ 42.739] (--) NVIDIA(0): Memory: 11534336 kBytes[ 42.739] (--) NVIDIA(0): VideoBIOS: 86.02.40.00.3c[ 42.739] (II) NVIDIA(0): Detected PCI Express Link width: 16X[ 42.739] (--) NVIDIA(GPU-0): DFP-0: disconnected[ 42.739] (--) NVIDIA(GPU-0): DFP-0: Internal TMDS[ 42.739] (--) NVIDIA(GPU-0): DFP-0: 165.0 MHz maximum pixel clock[ 42.739] (--) NVIDIA(GPU-0): [ 42.739] (--) NVIDIA(GPU-0): DFP-1: disconnected[ 42.739] (--) NVIDIA(GPU-0): DFP-1: Internal DisplayPort[ 42.739] (--) NVIDIA(GPU-0): DFP-1: 1440.0 MHz maximum pixel clock[ 42.739] (--) NVIDIA(GPU-0): [ 42.739] (--) NVIDIA(GPU-0): DFP-2: disconnected[ 42.739] (--) NVIDIA(GPU-0): DFP-2: Internal TMDS[ 42.739] (--) NVIDIA(GPU-0): DFP-2: 165.0 MHz maximum pixel clock[ 42.739] (--) NVIDIA(GPU-0): [ 42.739] (--) NVIDIA(GPU-0): DFP-3: disconnected[ 42.739] (--) NVIDIA(GPU-0): DFP-3: Internal DisplayPort[ 42.739] (--) NVIDIA(GPU-0): DFP-3: 1440.0 MHz maximum pixel clock[ 42.739] (--) NVIDIA(GPU-0): [ 42.740] (--) NVIDIA(GPU-0): DFP-4: disconnected[ 42.740] (--) NVIDIA(GPU-0): DFP-4: Internal TMDS[ 42.740] (--) NVIDIA(GPU-0): DFP-4: 165.0 MHz maximum pixel clock[ 42.740] (--) NVIDIA(GPU-0): [ 42.740] (--) NVIDIA(GPU-0): DFP-5: disconnected[ 42.740] (--) NVIDIA(GPU-0): DFP-5: Internal DisplayPort[ 42.740] (--) NVIDIA(GPU-0): DFP-5: 1440.0 MHz maximum pixel clock[ 42.740] (--) NVIDIA(GPU-0): [ 42.740] (--) NVIDIA(GPU-0): DFP-6: disconnected[ 42.740] (--) NVIDIA(GPU-0): DFP-6: Internal TMDS[ 42.740] (--) NVIDIA(GPU-0): DFP-6: 165.0 MHz maximum pixel clock[ 42.740] (--) NVIDIA(GPU-0): [ 42.740] (EE) NVIDIA(0): Failed to assign any connected display devices to X screen 0. [ 42.740] (EE) NVIDIA(0): Set AllowEmptyInitialConfiguration if you want the server[ 42.740] (EE) NVIDIA(0): to start anyway[ 42.740] (EE) NVIDIA(0): Failing initialization of X screen 0[ 43.386] (II) UnloadModule: "nvidia"[ 43.386] (II) UnloadSubModule: "wfb"[ 43.386] (II) UnloadSubModule: "fb"[ 43.386] (EE) Screen(s) found, but none have a usable configuration.[ 43.386] (EE) Fatal server error:[ 43.386] (EE) no screens found(EE) [ 43.386] (EE) Please consult the The X.Org Foundation support at http://wiki.x.org for help. [ 43.386] (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.[ 43.386] (EE) [ 43.387] (EE) Server terminated with error (1). Closing log file.

因為Xorg檢測到Nvidia驅動給Xorg提供的配置文件,所以就會裝載下面的module:

gemfield@ai:/var/log$ cat Xorg.0.log |grep " Load"[ 42.692] (II) Loader magic: 0x558da6b83020[ 42.697] (II) LoadModule: "glx"[ 42.697] (II) Loading /usr/lib/x86_64-linux-gnu/xorg/extra-modules/libglx.so[ 42.703] (II) LoadModule: "nvidia"[ 42.703] (II) Loading /usr/lib/x86_64-linux-gnu/xorg/extra-modules/nvidia_drv.so[ 42.703] (II) Loading sub module "fb"[ 42.703] (II) LoadModule: "fb"[ 42.703] (II) Loading /usr/lib/xorg/modules/libfb.so[ 42.704] (II) Loading sub module "wfb"[ 42.704] (II) LoadModule: "wfb"[ 42.704] (II) Loading /usr/lib/xorg/modules/libwfb.so[ 42.704] (II) Loading sub module "ramdac"[ 42.704] (II) LoadModule: "ramdac"

你會看到裝載了Nvidia驅動的模塊:

gemfield@ai:~$ ldd /usr/lib/x86_64-linux-gnu/xorg/extra-modules/libglx.so linux-vdso.so.1 => (0x00007ffe91398000) libnvidia-tls.so.384.111 => /usr/lib/nvidia-384/tls/libnvidia-tls.so.384.111 (0x00007f5de7f84000) libnvidia-glcore.so.384.111 => /usr/lib/nvidia-384/libnvidia-glcore.so.384.111 (0x00007f5de60c7000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5de5ce7000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5de5ae3000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5de578d000) /lib64/ld-linux-x86-64.so.2 (0x00007f5de90f0000)gemfield@ai:~$ ldd /usr/lib/x86_64-linux-gnu/xorg/extra-modules/nvidia_drv.so linux-vdso.so.1 => (0x00007ffe9e5c3000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0da8157000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0da7d77000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0da7b73000) /lib64/ld-linux-x86-64.so.2 (0x00007f0da8f95000)

而在一個沒有安裝Nvidia驅動的系統上,Xorg的啟動則會裝載下面的模塊:

gemfield@ThinkPad-X1C:/var/log$ cat Xorg.0.log |grep " Load"[ 6.155] (II) Loader magic: 0x5639b7085020[ 6.169] (II) LoadModule: "glx"[ 6.171] (II) Loading /usr/lib/xorg/modules/extensions/libglx.so[ 6.178] (II) LoadModule: "modesetting"[ 6.178] (II) Loading /usr/lib/xorg/modules/drivers/modesetting_drv.so[ 6.179] (II) LoadModule: "fbdev"[ 6.179] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so[ 6.180] (II) LoadModule: "vesa"[ 6.180] (II) Loading /usr/lib/xorg/modules/drivers/vesa_drv.so[ 6.184] (II) Loading sub module "fbdevhw"[ 6.184] (II) LoadModule: "fbdevhw"[ 6.184] (II) Loading /usr/lib/xorg/modules/libfbdevhw.so[ 6.185] (II) Loading sub module "glamoregl"[ 6.185] (II) LoadModule: "glamoregl"[ 6.185] (II) Loading /usr/lib/xorg/modules/libglamoregl.so[ 6.305] (II) Loading sub module "fb"[ 6.305] (II) LoadModule: "fb"[ 6.305] (II) Loading /usr/lib/xorg/modules/libfb.so[ 6.457] (II) AIGLX: Loaded and initialized i965[ 6.504] (II) LoadModule: "libinput"[ 6.504] (II) Loading /usr/lib/xorg/modules/input/libinput_drv.so

現在只剩一個問題了,X Server沒有起來,你只要ps -ef | grep Xorg就可以看到Xorg這個進程並不存在。這是因為,就像上面的log顯示的那樣:Failed to assign any connected display devices to X screen 0。這是因為我們的系統沒有外接顯示器所致。所以要想讓Xorg進程(也就是X Server)起來,要麼接個顯示器,要麼...就像log里說的,加個AllowEmptyInitialConfiguration選項。下文里Gemfield有專門的章節來介紹。

2,目錄/usr/share/X11/xorg.conf.d/

Xorg接下來會從/usr/share/X11/xorg.conf.d/下面讀取配置文件,安裝Nvidia專屬驅動後會在這個目錄下產生新的配置文件:

gemfield@ai:~$ ls /usr/share/X11/xorg.conf.d10-amdgpu.conf 10-quirks.conf 10-radeon.conf 40-libinput.conf 70-wacom.conf#安裝後gemfield@ai:~$ ls /usr/share/X11/xorg.conf.d/10-amdgpu.conf 10-radeon.conf 50-nvidia-drm-outputclass.conf 70-synaptics.conf glamoregl.conf10-quirks.conf 40-libinput.conf 51-synaptics-quirks.conf 70-wacom.conf

可以看到,主要是多出來Nvidia的配置文件50-nvidia-drm-outputclass.conf/nvidia-drm-outputclass.conf:

gemfield@ai:/usr/share/X11/xorg.conf.d$ cat 50-nvidia-drm-outputclass.conf/nvidia-drm-outputclass.conf # This xorg.conf.d configuration snippet configures the X server to# automatically load the nvidia X driver when it detects a device driven by the# nvidia-drm.ko kernel module. Please note that this only works on Linux kernels# version 3.9 or higher with CONFIG_DRM enabled, and only if the nvidia-drm.ko# kernel module is loaded before the X server is started.Section "OutputClass" Identifier "nvidia" MatchDriver "nvidia-drm" Driver "nvidia"EndSection

3 無顯示器啟動X Server

安裝Nvidia驅動後,如果沒有接顯示器,那麼X Server在啟動的時候會報錯:NVIDIA(0): Failed to assign any connected display devices to X screen 0. Set AllowEmptyInitialConfiguration if you want the server to start anyway

NVIDIA(0): Failing initialization of X screen 0

這個時候,根據錯誤提示,可以通過

sudo nvidia-xconfig --allow-empty-initial-configuration

來進行設置。該命令會修改文件/etc/X11/xorg.conf:

gemfield@ai:/usr/NX/var/log$ diff -u /etc/X11/xorg.conf.backup /etc/X11/xorg.conf--- /etc/X11/xorg.conf.gemfield 2018-02-26 11:17:31.966258143 +0800+++ /etc/X11/xorg.conf 2018-02-26 11:17:45.830258784 +0800@@ -1,9 +1,10 @@ # nvidia-xconfig: X configuration file generated by nvidia-xconfig-# nvidia-xconfig: version 384.90 (buildmeister@swio-display-x86-rhel47-05) Tue Sep 19 18:13:03 PDT 2017+# nvidia-xconfig: version 384.111 (buildmeister@swio-display-x86-rhel47-01) Wed Dec 20 00:05:28 PST 2017+ Section "ServerLayout" Identifier "Layout0"- Screen 0 "Screen0"+ Screen 0 "Screen0" 0 0 InputDevice "Keyboard0" "CoreKeyboard" InputDevice "Mouse0" "CorePointer" EndSection@@ -12,6 +13,7 @@ EndSection Section "InputDevice"+ # generated from default Identifier "Mouse0" Driver "mouse"@@ -22,6 +24,7 @@ EndSection Section "InputDevice"+ # generated from default Identifier "Keyboard0" Driver "kbd"@@ -47,6 +50,7 @@ Device "Device0" Monitor "Monitor0" DefaultDepth 24+ Option "AllowEmptyInitialConfiguration" "True" SubSection "Display" Depth 24 EndSubSection

你可以看到添加了這一行配置:Option "AllowEmptyInitialConfiguration" "True"。

進行了這個設置後,重啟系統,查看X Server的log:

gemfield@ai:/var/log$ cat Xorg.0.log |grep " Load"[ 12.607] (II) Loader magic: 0x56096dfb6020[ 12.612] (II) LoadModule: "glx"[ 12.612] (II) Loading /usr/lib/x86_64-linux-gnu/xorg/extra-modules/libglx.so[ 12.635] (II) LoadModule: "nvidia"[ 12.635] (II) Loading /usr/lib/x86_64-linux-gnu/xorg/extra-modules/nvidia_drv.so[ 12.641] (II) Loading sub module "fb"[ 12.641] (II) LoadModule: "fb"[ 12.642] (II) Loading /usr/lib/xorg/modules/libfb.so[ 12.643] (II) Loading sub module "wfb"[ 12.643] (II) LoadModule: "wfb"[ 12.643] (II) Loading /usr/lib/xorg/modules/libwfb.so[ 12.643] (II) Loading sub module "ramdac"[ 12.643] (II) LoadModule: "ramdac"[ 12.861] (II) Loading sub module "dri2"[ 12.861] (II) LoadModule: "dri2"[ 12.911] (II) LoadModule: "libinput"[ 12.911] (II) Loading /usr/lib/xorg/modules/input/libinput_drv.so

這次很明顯啟動完整了,再看看Xorg進程,也有了:

gemfield@ai:/var/log$ ps -ef |grep Xorgroot 1122 1014 0 11:23 tty7 00:00:00 /usr/lib/xorg/Xorg -nolisten tcp -auth /var/run/sddm/{b54247e5-6e6b-4d5e-96a3-083cf09a6782} -background none -noreset -displayfd 17 vt7

推薦閱讀:

筆記本里只裝Linux是什麼體驗?
從 X86 到 ARM 的移植,為什麼 Windows 的兼容性看起來沒有像Linux、OS X那樣好?
Mac OS X 有沒有ip命令?
祝賀 Linux 25 歲:25 個關於 Linux 的驚人真相!
Linux 性能診斷:負載評估

TAG:NVIDIA英偉達 | Xorg | Linux |