赞
踩
在Ubuntu上查看电脑显卡型号以及下载对应的驱动,可以按照以下步骤进行:
打开终端(Terminal)。
输入命令 lspci | grep -i vga 或者 lspci | grep -i nvidia(如果是NVIDIA显卡),然后按Enter键。这将列出与显卡相关的信息。
在输出信息中,查找显卡型号。通常,显卡型号会显示在类似于“VGA compatible controller”或“NVIDIA Corporation”的行中。
wcx@wcx-Ubuntu:~/Desktop$ lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation TU116 [GeForce GTX 1660 SUPER] (rev a1)
wcx@wcx-Ubuntu:~/Desktop$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation TU116 [GeForce GTX 1660 SUPER] (rev a1)
01:00.1 Audio device: NVIDIA Corporation TU116 High Definition Audio Controller (rev a1)
01:00.2 USB controller: NVIDIA Corporation TU116 USB 3.1 Host Controller (rev a1)
01:00.3 Serial bus controller [0c80]: NVIDIA Corporation TU116 [GeForce GTX 1650 SUPER] (rev a1)
访问NVIDIA官方网站 https://www.nvidia.com/Download/index.aspx?lang=en-us
在网站上选择适当的显卡型号和操作系统(Ubuntu及其版本)。
下载与你的显卡型号和Ubuntu版本相匹配的驱动程序。通常,这会是一个.run文件。
打开终端,输入以下命令:
sudo apt update
sudo apt upgrade
sudo apt install gcc g++ make
Nouveau是一个开源的显卡驱动,与NVIDIA的官方驱动冲突。在安装NVIDIA驱动之前,需要禁用它
编辑黑名单文件:
sudo nano /etc/modprobe.d/blacklist.conf
在文件末尾添加以下行:
blacklist nouveau
options nouveau modeset=0
保存并关闭文件。然后更新initramfs并重启:
sudo update-initramfs -u
sudo reboot
在重启后,界面为黑色,进入命令行模式(通常可以按Ctrl+Alt+F2或其他F键)。登录到你的用户账户
首先,你可能需要停止lightdm或gdm服务(取决于你使用的显示管理器)
wenchenxing@wenchenxing-virtual-machine:~/Downloads$ sudo service lightdm stop
wenchenxing@wenchenxing-virtual-machine:~/Downloads$ ls
NVIDIA-Linux-x86_64-535.86.05.run
wenchenxing@wenchenxing-virtual-machine:~/Downloads$ chmod a+x NVIDIA-Linux-x86_64-550.54.16.run
wenchenxing@wenchenxing-virtual-machine:~/Downloads$ sudo ./NVIDIA-Linux-x86_64-550.54.16.run
Verifying archive integrity… OK
一直 enter
安装完成后,重启你的计算机:
sudo reboot
重启后,你可以通过运行以下命令来验证NVIDIA驱动是否正确安装:
nvidia-smi
如果一切正常,这个命令应该会显示关于你的NVIDIA显卡的信息。
wcx@wcx-Ubuntu:~/Desktop$ nvidia-smi
Sun Feb 25 16:00:23 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce GTX 1660 ... Off | 00000000:01:00.0 On | N/A |
| 30% 42C P8 7W / 125W | 211MiB / 6144MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 1097 G /usr/lib/xorg/Xorg 35MiB |
| 0 N/A N/A 1776 G /usr/lib/xorg/Xorg 47MiB |
| 0 N/A N/A 1908 G /usr/bin/gnome-shell 118MiB |
+-----------------------------------------------------------------------------------------+
wcx@wcx-Ubuntu:~/Desktop$ sudo nvidia-smi
[sudo] password for wcx:
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
原因: Ubuntu更新后导致内核不兼容导致
查看Ubuntu更新
wcx@wcx-Ubuntu:~/Desktop$ uname -a
Linux wcx-Ubuntu 5.15.0-100-generic #110~20.04.1-Ubuntu SMP Tue Feb 13 14:25:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
检查cuda是否存在
wcx@wcx-Ubuntu:~/Desktop$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243
查看已安装驱动版本
wcx@wcx-Ubuntu:~/Desktop$ ls /usr/src/ | grep nvidia
nvidia-550.54.14
安装dkms 可以做到内核变更后自动编译模块,适配新内核
wcx@wcx-Ubuntu:~/Desktop$ sudo apt install dkms
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
dctrl-tools
Suggested packages:
debtags menu
The following NEW packages will be installed:
dctrl-tools dkms
0 upgraded, 2 newly installed, 0 to remove and 11 not upgraded.
Need to get 128 kB of archives.
After this operation, 599 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 dctrl-tools amd64 2.24-3 [61.5 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 dkms all 2.8.1-5ubuntu2 [66.8 kB]
Fetched 128 kB in 1s (105 kB/s)
Selecting previously unselected package dctrl-tools.
(Reading database ... 213981 files and directories currently installed.)
Preparing to unpack .../dctrl-tools_2.24-3_amd64.deb ...
Unpacking dctrl-tools (2.24-3) ...
Selecting previously unselected package dkms.
Preparing to unpack .../dkms_2.8.1-5ubuntu2_all.deb ...
Unpacking dkms (2.8.1-5ubuntu2) ...
Setting up dctrl-tools (2.24-3) ...
Setting up dkms (2.8.1-5ubuntu2) ...
Processing triggers for man-db (2.9.1-1) ...
使用dkms重新编译当前驱动适配当前内核
wcx@wcx-Ubuntu:~/Desktop$ sudo dkms install -m nvidia -v 550.54.14
Creating symlink /var/lib/dkms/nvidia/550.54.14/source ->
/usr/src/nvidia-550.54.14
DKMS: add completed.
Kernel preparation unnecessary for this kernel. Skipping...
Building module:
cleaning build area...
'make' -j16 NV_EXCLUDE_BUILD_MODULES='' KERNEL_UNAME=5.15.0-100-generic modules..........
Signing module:
Generating a new Secure Boot signing key:
Can't load /var/lib/shim-signed/mok/.rnd into RNG
140081268356416:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:98:Filename=/var/lib/shim-signed/mok/.rnd
Generating a RSA private key
.................................+++++
......................................+++++
writing new private key to '/var/lib/shim-signed/mok/MOK.priv'
-----
- /var/lib/dkms/nvidia/550.54.14/5.15.0-100-generic/x86_64/module/nvidia.ko
- /var/lib/dkms/nvidia/550.54.14/5.15.0-100-generic/x86_64/module/nvidia-modeset.ko
- /var/lib/dkms/nvidia/550.54.14/5.15.0-100-generic/x86_64/module/nvidia-peermem.ko
- /var/lib/dkms/nvidia/550.54.14/5.15.0-100-generic/x86_64/module/nvidia-drm.ko
- /var/lib/dkms/nvidia/550.54.14/5.15.0-100-generic/x86_64/module/nvidia-uvm.ko
Secure Boot not enabled on this system.
cleaning build area...
DKMS: build completed.
nvidia.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.15.0-100-generic/updates/dkms/
nvidia-uvm.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.15.0-100-generic/updates/dkms/
nvidia-modeset.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.15.0-100-generic/updates/dkms/
nvidia-drm.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.15.0-100-generic/updates/dkms/
nvidia-peermem.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/5.15.0-100-generic/updates/dkms/
depmod..........
DKMS: install completed.
nvidia-smi
wcx@wcx-Ubuntu:~/Desktop$ nvidia-smi
Fri Mar 15 18:23:27 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.54.14 Driver Version: 550.54.14 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce GTX 1660 ... Off | 00000000:01:00.0 Off | N/A |
| 21% 50C P0 31W / 125W | 0MiB / 6144MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。