想知道你的 Linux 电脑里用的是哪种图形处理器 (GPU) 吗?本文将介绍如何通过命令行和 GNOME 桌面环境来识别显卡。
第一步
你可能遇到过这种情况:你被要求帮助一位不太懂技术的朋友或同事。经验告诉你,这可能会很棘手。但你还是答应了!很快,你意识到问题可能出在显卡驱动上。这或许并非难事!但当你问“你用的是什么显卡?”时,你心中燃起的希望瞬间熄灭。
对方一脸茫然的表情说明了一切。要解决问题,首先得了解问题是什么。那么,如何在 Linux 电脑上识别显卡呢?
假设最坏的情况,即从未安装过显卡驱动,你甚至无法通过查看驱动来获得线索。没关系!你可以通过命令行或 图形用户界面 (GUI) 来识别显卡。
lspci 和 PCI ID 数据库
外围组件互连 (PCI) 是一种通用协议,用于与内部外围设备(例如显卡)通信。PCI ID 存储库 维护着所有已知 PCI 设备的数据库。这意味着,如果你知道设备的一些信息,就可以查找到它。
你可以使用 `lspci` 命令列出 安装在 Linux 电脑上的 PCI 设备,并获取它们的一些信息。
如果能将 PCI 数据库和 `lspci` 命令结合起来就好了,对吧?实际上,当你运行 `lspci` 命令时,它正是这么做的。它会检查 PCI 数据库的本地副本,以识别它检测到的 PCI 设备。在我们开始之前,最好更新 PCI 数据库的本地副本。
输入 `update-pciids` 命令 来完成此操作:
sudo update-pciids
更新了最新数据库版本后,我们现在可以使用 `lspci` 命令了。输出信息会很多,所以我们将其传递给 `less` 命令进行分页查看。`-v` (详细) 选项会告诉 `lspci` 提供尽可能多的信息。我们将使用 `sudo` 来确保信息尽可能详细。
我们输入以下命令:
sudo lspci -v | less
结果会显示在 `less` 中。如果按下斜杠 ( `/` ),则会激活 `less` 的搜索功能。
输入大写的“VGA”,然后按 Enter 键。
`less` 会搜索字符串“VGA”,并显示找到的第一个匹配项。之后,你可以滚动或翻页,查看 `lspci` 找到了多少显卡。
在本文中,我们使用的是运行在 VirtualBox 虚拟机上的系统。虚拟机当然有虚拟显卡。
下面是一个真实的结果示例,这是主机(物理)计算机的输出:
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` (类) 选项并传递 “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: [email protected]: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
显卡信息在“Device”行中描述。
以下是物理计算机的输出:
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
这款笔记本电脑具有 英特尔酷睿 GPU 和 NVIDIA GeForce 610M。但是,两张卡都有 “[VGA controller]” 字符串,通常表示正在使用哪个 GPU。
它们不能同时使用,因此请首先尝试从主流 GPU 供应商处获取该卡。这是笔记本电脑制造商认为的默认设置,并包含在机器的硬件规格中。
我们在这里介绍的其中一种技术肯定会奏效!在了解计算机或笔记本电脑的显卡类型后,你可以选择合适的显卡驱动程序。