如何检查 Linux 上安装了哪个 GPU

需要识别 Linux 计算机中的图形处理单元 (GPU)?下面介绍如何从命令行和 GNOME 中识别显卡。
第一步
你可能去过那里。您被征召为一位非技术人员的亲戚或同事提供支持,有些事情告诉您这并非一帆风顺。不过,你投球!您很快确定问题可能是显示驱动程序问题。嘿,这毕竟不是那么糟糕!但是当你问“你有什么样的显卡?”时,你那短暂的希望破灭了。
你在回应中收到的鹿在车头灯下的表情很能说明问题。要支持某事,您需要知道它是什么。那么如何识别Linux电脑中的显卡呢?
让我们假设最坏的情况,并假设从未安装显卡驱动程序,因此您甚至无法通过查看这些来获得线索。没关系!您可以从命令行或通过图形用户界面 (GUI) 解决这个难题。
lspci 和 PCI ID 数据库
外围组件互连 (PCI) 标准是一种通用协议,可用于与图形卡等内部外围设备通信。 PCI ID 存储库维护一个包含所有已知 PCI 设备 ID 的数据库。这意味着如果您知道有关该设备的一些信息,则可以进行查找。
您可以使用 lspci
命令列出安装在 Linux 计算机上的 PCI 设备,以及有关它们的一些信息。
如果我们可以将 PCI 数据库和 lspci
命令结合在一起,那不是很好吗?好吧,实际上,这正是您运行 lspci
命令时发生的情况。它检查 PCI 数据库的本地副本以识别它检测到的 PCI 设备。在我们开始之前,更新 PCI 数据库的本地副本是明智的。
输入 update-pciids
命令来做到这一点:
sudo update-pciids

为我们检索了最新的数据库版本,我们现在可以使用 lspci
命令。会有很多输出,所以我们将其通过管道传输到 less
中。 -v
(详细)选项告诉 lscpi
为我们提供尽可能多的信息。我们将使用 sudo
来确保信息尽可能详细。
我们键入我们的命令如下:
sudo lspci -v | less

结果出现在 less
中。如果您按下正斜杠 (/
),您将激活 less
搜索功能。
键入全部大写的“VGA”,然后按 Enter。

less
搜索字符串“VGA”,它会向您显示它找到的第一个匹配项。从那时起,您可以滚动或向前翻页以查看找到了多少显卡 lspci
。

对于本文,我们对在 VirtualBox 虚拟机中运行的各种 Linux 发行版进行了研究。虚拟机当然有虚拟显卡。
所以你可以看到一个真实世界结果的例子,这是主机(物理)计算机的输出:
26:00.0 VGA compatible controller: NVIDIA Corporation GP108 [GeForce GT 1030] (rev a1) (prog-if 00 [VGA controller])
Subsystem: Gigabyte Technology Co., Ltd GP108 [GeForce GT 1030]
Flags: bus master, fast devsel, latency 0, IRQ 97
Memory at f6000000 (32-bit, non-prefetchable) [size=16M]
Memory at e0000000 (64-bit, prefetchable) [size=256M]
Memory at f0000000 (64-bit, prefetchable) [size=32M]
I/O ports at e000 [size=128]
Expansion ROM at 000c0000 [disabled] [size=128K]
Capabilities: [60] Power Management version 3
Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [78] Express Legacy Endpoint, MSI 00
Capabilities: [100] Virtual Channel
Capabilities: [250] Latency Tolerance Reporting
Capabilities: [128] Power Budgeting <?>
Capabilities: [420] Advanced Error Reporting
Capabilities: [600] Vendor Specific Information: ID=0001 Rev=1 Len=024 <?>
Capabilities: [900] Secondary PCI Express <?>
Kernel driver in use: nouveau
Kernel modules: nouveau
一下子给了我们很多好消息!
该卡是 NVIDIA Corporation GP108 [GeForce GT 1030],使用搜索引擎几秒钟后,我们找到了该设备的 NVIDIA 技术页面。第一行末尾的“[VGA controller]”文本表示这是“可操作的”显卡。当计算机上安装了多张卡时,这是有用的信息。
lshw 命令
您还可以使用 lshw
命令列出 Linux 计算机上安装的硬件。它也报告多种类型——不仅仅是 PCI 硬件。
为了告诉它报告它找到的显卡,我们将使用 -C
(class) 选项并传递“display”修饰符。 -numeric
选项强制 lshw
提供设备的数字 ID 及其名称。
输入以下内容:
sudo lshw -numeric -C display

这是该命令在物理计算机上发现的内容:
*-display
description: VGA compatible controller
product: GP108 [GeForce GT 1030] [10DE:1D01]
vendor: NVIDIA Corporation [10DE]
physical id: 0
bus info: pci@0000:26:00.0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
configuration: driver=nouveau latency=0
resources: irq:97 memory:f6000000-f6ffffff memory:e0000000-efffffff memory:f0000000-f1ffffff ioport:e000(size=128) memory:c0000-dffff
令人鼓舞的是,他们都找到了同一张卡片!
[10DE:1D01] 标识符代表制造商 (10DE) 和型号 (1D01)。要立即找到品牌和型号,您可以在搜索引擎中输入“显卡 10de:1d01”。
glxinfo 命令
glxinfo
命令是您可以使用的另一种方法。它为您提供来自 X Windows 系统的 OpenGL 扩展的信息。然后,您可以搜索其中的一些信息,找出机器上安装了哪种图形卡。
glxinfo
命令已经存在于 Manjaro 和 Fedora 上,但您必须在 Ubuntu 上安装它。为此,请键入以下命令:
sudo apt-get install mesa-utils

要将 glxinfo
的输出通过 less
进行管道传输,并使用 -B
(打印 ID)选项,请键入以下内容:
glxinfo -B | less

图形卡在“设备”行中进行了描述。

这是物理计算机的输出:
name of display: :1
display: :1 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: nouveau (0x10de)
Device: NV138 (0x1d01)
Version: 19.3.2
Accelerated: yes
Video memory: 1987MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 4.3
Max compat profile version: 4.3
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.2
OpenGL vendor string: nouveau
OpenGL renderer string: NV138
OpenGL core profile version string: 4.3 (Core Profile) Mesa 19.3.2
OpenGL core profile shading language version string: 4.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.3 (Compatibility Profile) Mesa 19.3.2
OpenGL shading language version string: 4.30
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 19.3.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
当您在搜索引擎中输入“NV138”时,NVIDIA 显卡会立即被识别出来。
使用 GUI 识别显卡
如果计算机是仅 CLI 服务器,则必须使用我们上面介绍的技术之一。但是,如果它有一个(工作的)GUI,则可能有一种图形方式可以识别图形卡。事实上,该选项可能位于您的 Linux 桌面设置工具中的某个位置。
在 GNOME 桌面上,打开“设置”对话框,然后单击边栏中的“详细信息”。在“关于”面板中,查找“图形”条目。这会告诉您计算机中的显卡类型,或者更具体地说,是当前正在使用的显卡。您的机器可能有多个 GPU。

在物理主机的 GNOME 设置“关于”选项卡中,我们获得了与之前看到的相同的“NV138”卡 ID。同样,我们可以将该信息插入搜索引擎以查找卡片类型。

笔记本电脑上的显卡
许多笔记本电脑有两块显卡:一块来自中央处理器 (CPU) 制造商,另一块来自主流 GPU 供应商。
让我们输入与之前相同的 lspci
命令,但这一次,我们将在笔记本电脑上运行它:
sudo lspci -v | less
不出所料,我们得到了机器中显卡的描述:
00:02.0 VGA compatible controller: Intel Corporation 3rd Gen Core processor Graphics Controller (rev 09) (prog-if 00 [VGA controller])
Subsystem: ASUSTeK Computer Inc. 3rd Gen Core processor Graphics Controller
Flags: bus master, fast devsel, latency 0, IRQ 33
Memory at f7400000 (64-bit, non-prefetchable) [size=4M]
Memory at d0000000 (64-bit, prefetchable) [size=256M]
I/O ports at f000 [size=64]
[virtual] Expansion ROM at 000c0000 [disabled] [size=128K]
Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit-
Capabilities: [d0] Power Management version 2
Capabilities: [a4] PCI Advanced Features
Kernel driver in use: i915
Kernel modules: i915
01:00.0 VGA compatible controller: NVIDIA Corporation GF119M [GeForce 610M] (rev a1) (prog-if 00 [VGA controller])
Subsystem: ASUSTeK Computer Inc. GF119M [GeForce 610M]
Flags: bus master, fast devsel, latency 0, IRQ 34
Memory at f6000000 (32-bit, non-prefetchable) [size=16M]
Memory at e0000000 (64-bit, prefetchable) [size=128M]
Memory at e8000000 (64-bit, prefetchable) [size=32M]
I/O ports at e000 [size=128]
Expansion ROM at f7000000 [disabled] [size=512K]
Capabilities: [60] Power Management version 3
Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [78] Express Endpoint, MSI 00
Capabilities: [b4] Vendor Specific Information: Len=14 <?>
Capabilities: [100] Virtual Channel
Capabilities: [128] Power Budgeting <?>
Capabilities: [600] Vendor Specific Information: ID=0001 Rev=1 Len=024 <?>
Kernel driver in use: nouveau
Kernel modules: nouveau
这台笔记本电脑同时配备了 Intel Core GPU 和 NVIDIA GeForce 610M。但是,这两张卡都有“[VGA controller]”字符串,通常表示正在使用哪个 GPU。
它们不能同时使用,因此请先尝试从主流 GPU 供应商处获取该卡。这是笔记本电脑制造商认为的默认设置,并包含在机器的硬件规格中。
我们在这里介绍的其中一项技术肯定对您有用!在知道计算机或笔记本电脑的显卡类型后,您可以选择合适的显卡驱动程序。
Linux Commands | ||
Files | tar · pv · cat · tac · chmod · grep · diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm · scp · gzip · chattr · cut · find · umask · wc | |
Processes | alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg · pidof · nohup · pmap | |
Networking | netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami · w · iptables · ssh-keygen · ufw · arping · firewalld |
RELATED: Best Linux Laptops for Developers and Enthusiasts