如何確認「Nvidia驅動程式」是否已經安裝

原始討論

方法一

若是使用「安裝Nvidia驅動程式套件」的方式,可以確認套件是否已經安裝。

可以執行

$ dpkg -l 'nvidia*'

顯示

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                     Version           Architecture      Description
+++-========================-=================-=================-======================================================
ii  nvidia-361               361.42-0ubuntu2   amd64             NVIDIA binary driver - version 361.42
ii  nvidia-361-updates       361.42-0ubuntu2   amd64             Transitional package for nvidia-361
un  nvidia-common            <none>            <none>            (no description available)
un  nvidia-driver-binary     <none>            <none>            (no description available)
un  nvidia-legacy-340xx-vdpa <none>            <none>            (no description available)
un  nvidia-libopencl1-361    <none>            <none>            (no description available)
un  nvidia-libopencl1-dev    <none>            <none>            (no description available)
un  nvidia-opencl-icd        <none>            <none>            (no description available)
ii  nvidia-opencl-icd-361    361.42-0ubuntu2   amd64             NVIDIA OpenCL ICD
un  nvidia-persistenced      <none>            <none>            (no description available)
ii  nvidia-prime             0.8.2             amd64             Tools to enable NVIDIA's Prime
ii  nvidia-settings          361.42-0ubuntu1   amd64             Tool for configuring the NVIDIA graphics driver
un  nvidia-settings-binary   <none>            <none>            (no description available)
un  nvidia-vdpau-driver      <none>            <none>            (no description available)

或是執行

$ dpkg --get-selections | grep nvidia

顯示

nvidia-361					install
nvidia-361-updates				install
nvidia-opencl-icd-361				install
nvidia-prime					install
nvidia-settings					install

如何查詢套件是否已經安裝在系統上,可以閱讀「如何知道某個套件是否已經安裝」。

「Nvidia驅動程式套件」的概念,可以閱讀『如何找出「Nvidia驅動程式套件」』這篇。

方法二

執行下面指令,可以知道 「nvidia 的 kernel 模組(驅動程式)」 是否有載入

$ lsmod | grep nvidia

顯示

nvidia_uvm            696320  0
nvidia_modeset        745472  2
nvidia              10076160  88 nvidia_modeset,nvidia_uvm
drm                   360448  9 i915,drm_kms_helper,nvidia

相關的概念,

請閱讀「鳥哥的私房菜 / 第十九章、開機流程、模組管理與 Loader / 19.2.2 核心模組的觀察: lsmod, modinfo」。

modinfo

進一步可以查詢模組的相關資訊

執行

$ modinfo nvidia_361

顯示

filename:       /lib/modules/4.4.0-24-generic/updates/dkms/nvidia_361.ko
alias:          char-major-195-*
version:        361.42
supported:      external
license:        NVIDIA
srcversion:     47D1C898C46D058800C3250
alias:          pci:v000010DEd00000E00sv*sd*bc04sc80i00*
alias:          pci:v000010DEd*sv*sd*bc03sc02i00*
alias:          pci:v000010DEd*sv*sd*bc03sc00i00*
depends:        drm
vermagic:       4.4.0-24-generic SMP mod_unload modversions
parm:           NVreg_Mobile:int
parm:           NVreg_ResmanDebugLevel:int
parm:           NVreg_RmLogonRC:int
parm:           NVreg_ModifyDeviceFiles:int
parm:           NVreg_DeviceFileUID:int
parm:           NVreg_DeviceFileGID:int
parm:           NVreg_DeviceFileMode:int
parm:           NVreg_UpdateMemoryTypes:int
parm:           NVreg_InitializeSystemMemoryAllocations:int
parm:           NVreg_UsePageAttributeTable:int
parm:           NVreg_MapRegistersEarly:int
parm:           NVreg_RegisterForACPIEvents:int
parm:           NVreg_CheckPCIConfigSpace:int
parm:           NVreg_EnablePCIeGen3:int
parm:           NVreg_EnableMSI:int
parm:           NVreg_TCEBypassMode:int
parm:           NVreg_MemoryPoolSize:int
parm:           NVreg_RegistryDwords:charp
parm:           NVreg_RmMsg:charp
parm:           NVreg_AssignGpus:charp

alias

至於為什麼是「nvidia_361」而不是「nvidia」,

我看到「/lib/nvidia-361/modprobe.conf」這個檔有做「alias」。

執行

$ cat /lib/nvidia-361/modprobe.conf

顯示

# This file was installed by nvidia-361
# Do not edit this file manually

blacklist nouveau
blacklist lbm-nouveau
blacklist nvidia-current
blacklist nvidia-173
blacklist nvidia-96
blacklist nvidia-current-updates
blacklist nvidia-173-updates
blacklist nvidia-96-updates
blacklist nvidia-361-updates
alias nvidia nvidia_361
alias nvidia-uvm nvidia_361-uvm
alias nvidia-modeset nvidia_361-modeset
alias nouveau off
alias lbm-nouveau off

可以看到上面有一行「alias nvidia nvidia_361」。

不過整個機制,我還沒研究透徹,先紀錄我目前發現到的。

「/lib/nvidia-361/modprobe.conf」這個檔,我是執行下面的指令查詢到的。

$ dpkg -L nvidia-361

上面這個指令,就是查詢「nvidia-361」這個套件,安裝那些檔案在系統上,顯示的「file list」,也可以在網頁上找到。

這個用法,可以參考「如何查詢某個套件安裝在系統上的所有檔案」這篇。

然後執行

$ grep '/lib/nvidia-361/modprobe.conf' /var/lib/dpkg/info/* -R

顯示

/var/lib/dpkg/info/nvidia-361.list:/lib/nvidia-361/modprobe.conf
/var/lib/dpkg/info/nvidia-361.postinst:            --slave /etc/modprobe.d/nvidia-graphics-drivers.conf x86_64-linux-gnu_nvidia_modconf /lib/nvidia-361/modprobe.conf \
/var/lib/dpkg/info/nvidia-361.postinst:            --slave /etc/modprobe.d/nvidia-graphics-drivers.conf x86_64-linux-gnu_nvidia_modconf /lib/nvidia-361/modprobe.conf \

執行

$ ls /etc/modprobe.d/nvidia-graphics-drivers.conf -l

, 顯示

lrwxrwxrwx 1 root root 49 Apr 24 21:37 /etc/modprobe.d/nvidia-graphics-drivers.conf -> /etc/alternatives/x86_64-linux-gnu_nvidia_modconf

執行

$ ls /etc/alternatives/x86_64-linux-gnu_nvidia_modconf -l

顯示

lrwxrwxrwx 1 root root 29 Apr 24 21:37 /etc/alternatives/x86_64-linux-gnu_nvidia_modconf -> /lib/nvidia-361/modprobe.conf

也就是「/etc/modprobe.d/nvidia-graphics-drivers.conf」是symbolic link到「/lib/nvidia-361/modprobe.conf」。

modprobe.d

接下來研究「/etc/modprobe.d/」的用法。

執行

$ dpkg -S /etc/modprobe.d

顯示

intel-microcode, osspd, udev, nvidia-361, xserver-xorg-video-vmware, kmod, alsa-base, dkms, linux-sound-base: /etc/modprobe.d

觀察最接近我們要找的套件「kmod」。

執行

$ dpkg -L kmod

顯示

/.
/sbin
/etc
/etc/init.d
/etc/init.d/kmod
/etc/modprobe.d
/etc/modprobe.d/blacklist-ath_pci.conf
/etc/modprobe.d/mlx4.conf
/etc/modprobe.d/blacklist.conf
/etc/modprobe.d/iwlwifi.conf
/etc/modprobe.d/blacklist-rare-network.conf
/etc/modprobe.d/blacklist-framebuffer.conf
/etc/modprobe.d/blacklist-watchdog.conf
/etc/modprobe.d/blacklist-firewire.conf
/etc/init
/etc/init/kmod.conf
/etc/depmod.d
/etc/depmod.d/ubuntu.conf
/bin
/bin/kmod
/lib
/lib/modprobe.d
/lib/modprobe.d/aliases.conf
/usr
/usr/share
/usr/share/initramfs-tools
/usr/share/initramfs-tools/hooks
/usr/share/initramfs-tools/hooks/kmod
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/kmod
/usr/share/doc
/usr/share/doc/libkmod2
/usr/share/doc/libkmod2/TODO
/usr/share/doc/libkmod2/README
/usr/share/man
/usr/share/man/fr
/usr/share/man/fr/man5
/usr/share/man/fr/man5/modules.5.gz
/usr/share/man/man8
/usr/share/man/man8/depmod.8.gz
/usr/share/man/man8/kmod.8.gz
/usr/share/man/man8/modinfo.8.gz
/usr/share/man/man8/insmod.8.gz
/usr/share/man/man8/lsmod.8.gz
/usr/share/man/man8/rmmod.8.gz
/usr/share/man/man8/modprobe.8.gz
/usr/share/man/man5
/usr/share/man/man5/modprobe.d.5.gz
/usr/share/man/man5/modules.dep.5.gz
/usr/share/man/man5/modules.5.gz
/usr/share/man/man5/depmod.d.5.gz
/sbin/rmmod
/sbin/depmod
/sbin/modprobe
/sbin/modinfo
/sbin/insmod
/sbin/lsmod
/bin/lsmod
/usr/share/doc/kmod
/usr/share/man/man5/modules.dep.bin.5.gz

有看到「/usr/share/man/man5/modprobe.d.5.gz」

也可以執行下面指令,找出有那些manpage可以閱讀

$ dpkg -L kmod | grep '/man/man.*/' | sort

顯示

/usr/share/man/man5/depmod.d.5.gz
/usr/share/man/man5/modprobe.d.5.gz
/usr/share/man/man5/modules.5.gz
/usr/share/man/man5/modules.dep.5.gz
/usr/share/man/man5/modules.dep.bin.5.gz
/usr/share/man/man8/depmod.8.gz
/usr/share/man/man8/insmod.8.gz
/usr/share/man/man8/kmod.8.gz
/usr/share/man/man8/lsmod.8.gz
/usr/share/man/man8/modinfo.8.gz
/usr/share/man/man8/modprobe.8.gz
/usr/share/man/man8/rmmod.8.gz

所以你可以執行

$ man modprobe.d

或是執行

$ man 5 modprobe.d

或是執行

$ man /usr/share/man/man5/modprobe.d.5.gz

來閱讀。

查詢目前套用的設定

執行

$ modprobe -c | grep nvidia | less

顯示

blacklist nvidiafb
blacklist nvidia_current
blacklist nvidia_173
blacklist nvidia_96
blacklist nvidia_current_updates
blacklist nvidia_173_updates
blacklist nvidia_96_updates
blacklist nvidia_361_updates
alias nvidia nvidia_361
alias nvidia_uvm nvidia_361_uvm
alias nvidia_modeset nvidia_361_modeset
alias char_major_195_* nvidia_361
alias mbp_nvidia_bl apple_bl
alias pci:v000010DEd*sv*sd*bc03sc*i* nvidiafb
alias pci:v000010DEd*sv*sd*bc03sc00i00* nvidia_361
alias pci:v000010DEd*sv*sd*bc03sc02i00* nvidia_361
alias pci:v000010DEd00000E00sv*sd*bc04sc80i00* nvidia_361
alias symbol:nvKmsKapiGetFunctionsTable nvidia_361_modeset
alias symbol:nvUvmInterfaceAddressSpaceCreate nvidia_361
alias symbol:nvUvmInterfaceAddressSpaceCreateMirrored nvidia_361
alias symbol:nvUvmInterfaceAddressSpaceDestroy nvidia_361
alias symbol:nvUvmInterfaceBindChannel nvidia_361
...略...