在 Linux 上使用 lspci 命令查看 PCI 总线硬件设备信息

lspci 命令用于显示 Linux 系统上的设备和驱动程序。

当在个人电脑或服务器上运行 Linux 时,有时需要识别该系统中的硬件。lspci 命令用于显示连接到 PCI 总线的所有设备,从而满足上述需求。该命令由 pciutils 包提供,可用于各种基于 Linux 和 BSD 的操作系统。

基础用法

当普通用户运行 lspci 时,显示的信息可能会受到访问权限限制。使用 sudo 运行该命令可以提供完整的信息。

以下是家庭媒体中心电脑的一个示例。它是一台基于 AMD Phenom CPU 的系统,具有 AMD 芯片组,它还配备了 Atheros 无线控制器和 Nvidia 显卡。

仅运行 lspci 会列出 PCI 总线及其连接的设备。所有硬件设备都列有供应商、名称和型号等详细信息。

   1. $ sudo lspci
   2. 00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] RS880 Host     Bridge
   3. 00:02.0 PCI bridge: Advanced Micro Devices, Inc. [AMD] RS780     PCI to PCI bridge (ext gfx port 0)
   4. 00:04.0 PCI bridge: Advanced Micro Devices, Inc. [AMD] RS780/RS880     PCI to PCI bridge (PCIE port 0)
   5. 00:05.0 PCI bridge: Advanced Micro Devices, Inc. [AMD] RS780/RS880     PCI to PCI bridge (PCIE port 1)
   6. 00:11.0 SATA controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 SATA Controller [AHCI mode]
   7. 00:12.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0     USB OHCI0 Controller
   8. 00:12.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0 USB OHCI1 Controller
   9. 00:12.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 USB EHCI Controller
   10. 00:13.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 USB OHCI0 Controller
   11. 00:13.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0 USB OHCI1 Controller
   12. 00:13.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 USB EHCI Controller
   13. 00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 SMBus     Controller (rev 3c)
   14. 00:14.1 IDE interface: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 IDE Controller
   15. 00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 LPC host controller
   16. 00:14.4 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] SBx00     PCI to PCI Bridge
   17. 00:14.5 USB controller: Advanced Micro Devices, Inc. [AMD/ATI]     SB7x0/SB8x0/SB9x0 USB OHCI2 Controller
   18. 00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h     Processor HyperTransport Configuration
   19. 00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h     Processor Address Map
   20. 00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h     Processor DRAM Controller
   21. 00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h     Processor Miscellaneous Control
   22. 00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h     Processor Link Control
   23. 01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [GeForce     GTX 650] (rev a1)
   24. 01:00.1 Audio device: NVIDIA Corporation GK107 HDMI Audio Controller     (rev a1)
   25. 02:00.0 Network controller: Qualcomm Atheros AR9287 Wireless Network     Adapter (PCI-Express) (rev 01)

详细输出

添加 -v 选项会显示每个设备的详细信息,可以使用 -vv 或 -vvv 来获取更多的设备细节。在 -v 级别,lspci 会显示所有设备的各种子系统和内存地址、中断请求(IRQ)编号和一些其他功能信息。输出信息会非常长。在系统上试一试吧。

使用 grep 过滤搜索

可能会需要缩小搜索范围。例如,RPM Fusion 网站有安装 Nvidia 图形驱动程序的说明,里面就首先使用了 grep 命令来定位显卡信息。下面是在笔记本电脑上得到的输出:

   1. $ sudo lspci | grep -e VGA
   2. 00:02.0 VGA compatible controller: Intel Corporation UHD Graphics     620 (rev 07)
   3. $ sudo lspci | grep -e 3D
   4. 01:00.0 3D controller: NVIDIA Corporation GM108M [GeForce MX130]     (rev a2)

下面(LCTT 译注:原文为 “above”,应为作者笔误)的 grep 命令在媒体中心 PC 上定位了一个 VGA 设备,但没有显示 3D 设备。

   1. $ sudo lspci | grep -e VGA
   2. 01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [GeForce     GTX 650] (rev a1)
   3. $ sudo lspci | grep -e 3D
   4. $

按供应商 ID 搜索

还有另一种无需 grep 的方法可以使用。假设想确认一下此计算机是否有其他的 Nvidia 设备,在此之前们还需要一些额外信息,使用 -nn 选项显示的供应商和设备 ID 号。在媒体中心 PC 上,此选项会给出 VGA 卡、供应商 ID 和设备 ID:

  1. $ sudo lspci -nn | grep -e VGA
  2. 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107 [GeForce GTX 650] [10de:0fc6] (rev a1)

设备名称后的方括号内有用冒号分隔的数字,即供应商和设备 ID。输出表明 Nvidia Corporation 制造的设备的供应商 ID 为 10de。

-d 选项用于指定供应商、设备或类 ID 的所有设备。以下是系统中的所有 Nvidia 设备(保留 -nn 以解析供应商 ID):

   1. $ sudo lspci -nn -d 10de:
   2. 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation     GK107 [GeForce GTX 650] [10de:0fc6] (rev a1)
   3. 01:00.1 Audio device [0403]: NVIDIA Corporation GK107 HDMI Audio     Controller [10de:0e1b] (rev a1)

从输出中可以看到,除了显卡之外,还有一个 Nvidia 音频设备。实际上它们都属于同一张 Nvidia GeForce GTX 650 卡,但这仍然是一个很好的示例。

内核模块

结合 PCI 硬件设备,lspci 可以使用 -k 选项显示内核加载了哪些驱动程序模块。将此选项添加到 lspci 命令来查看有关 Nvidia 设备的信息。

   1. $ sudo lspci -nn -k -d 10de:
   2. 01:00.0 VGA compatible controller [0300]: NVIDIA Corporation     GK107 [GeForce GTX 650] [10de:0fc6] (rev a1)
   3.  Subsystem: eVga.com. Corp. GK107 [GeForce GTX 650] [3842:2650]
   4.  Kernel driver in use: nvidia
   5.  Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
   6. 01:00.1 Audio device [0403]: NVIDIA Corporation GK107 HDMI Audio     Controller [10de:0e1b] (rev a1)
   7.  Subsystem: eVga.com. Corp. GK107 HDMI Audio Controller [3842:2650]
   8.  Kernel driver in use: snd_hda_intel
   9.  Kernel modules: snd_hda_intel

可以看到额外显示了两行:正在使用的内核驱动程序(Kernel driver in use) 和 内核模块(Kernel modules),其中后者列出了可用于支持该设备的模块。

同步最新状态

新设备和供应商总是在不断迭代。如果看到显示为 unknown 的设备,说明 PCI 设备 ID 数据库可能已过时。有两种方法可以检查更新。-Q 选项会使用 DNS 查询中央数据库,当然,这需要联网。

   $ sudo lspci -Q

还可以通过运行命令 update-pciids 来更新本地 PCI ID 数据库。

   1. $ sudo update-pciids
   2. Downloaded daily snapshot dated 2021-08-22 03:15:01

了解有关硬件的更多信息

当然,lspci 只是 Linux 中用于查询系统硬件和软件的诸多命令之一。读者可以在阅读关于 USB 设备的文章,了解有关 Linux 硬件的更多信息:使用此 USB ID 存储库识别 Linux 上的更多设备


via: https://opensource.com/article/21/9/lspci-linux-hardware

作者:Alan Formy-Duval 选题:lujun9972 译者:unigeorge 校对:turbokernel

本文由 LCTT 原创编译,Linux中国 荣誉推出 | 2021-09-17 09:14


获取 PCI 总线硬件设备信息的 7 个 Linux lspci 命令示例

【摘要】

lspci 代表 pci 列表。将此命令视为“ls”+“pci”。

将显示有关服务器中所有 PCI 总线的信息。

除了显示有关总线的信息外,它还将显示有关连接到 PCI 和 PCIe 总线的所有硬件设备的信息。

例如,它将显示有关以太网卡、RAID 控制器、视频卡等的信息。

lspci 实用程序是 pciutils 软件包的一部分。

如果没有 pciutilis,请将其安装在系统上,如下所示。

# yum install pciutils

1. 默认用法

默认情况下,它将显示所有设备信息,如下所示。第一个字段是槽信息,格式如下:[domain:]bus:device.function

在这个例子中,由于所有的域都是 0,所以 lspci 不会显示域。

# lspci
00:00.0 Host bridge: Intel Corporation 5500 I/O Hub to ESI Port (rev 13)
00:01.0 PCI bridge: Intel Corporation 5520/5500/X58 I/O Hub PCI Express Root Port 1 (rev 13)
00:09.0 PCI bridge: Intel Corporation 7500/5520/5500/X58 I/O Hub PCI Express Root Port 9 (rev 13)
00:14.0 PIC: Intel Corporation 7500/5520/5500/X58 I/O Hub System Management Registers (rev 13)
00:14.1 PIC: Intel Corporation 7500/5520/5500/X58 I/O Hub GPIO and Scratch Pad Registers (rev 13)
00:14.2 PIC: Intel Corporation 7500/5520/5500/X58 I/O Hub Control Status and RAS Registers (rev 13)
00:1a.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 02)
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 02)
00:1d.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 92)
00:1f.0 ISA bridge: Intel Corporation 82801IB (ICH9) LPC Interface Controller (rev 02)
00:1f.2 IDE interface: Intel Corporation 82801IB (ICH9) 2 port SATA Controller [IDE mode] (rev 02)
01:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
01:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)
06:03.0 VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200eW WPCM450 (rev 0a)

注意:在下面的所有示例中,我们将通过从上面的列表中选择几个设备来仅显示部分输出。

2. 以不同格式转储 PCI 信息

如果要将 lspci 命令的输出传递给 shell 脚本,可能需要使用 -m 选项(或 -mm 选项),如下所示。

当要查看子系统信息时,此选项也很有帮助。例如,对于 RAID 控制器,默认输出只是说正在使用 LSI Logic RAID 控制器。但是,以下输出显示子系统,即 DELL PERC H700 集成 RAID 控制器系统。

# lspci -m
00:00.0 "Host bridge" "Intel Corporation" "5500 I/O Hub to ESI Port" -r13 "Dell" "PowerEdge R610 I/O Hub to ESI Port"
00:09.0 "PCI bridge" "Intel Corporation" "7500/5520/5500/X58 I/O Hub PCI Express Root Port 9" -r13 "" ""
00:14.0 "PIC" "Intel Corporation" "7500/5520/5500/X58 I/O Hub System Management Registers" -r13 "" ""
00:1a.0 "USB controller" "Intel Corporation" "82801I (ICH9 Family) USB UHCI Controller #4" -r02 "Dell" "PowerEdge R610 USB UHCI Controller"
00:1f.0 "ISA bridge" "Intel Corporation" "82801IB (ICH9) LPC Interface Controller" -r02 "Dell" "PowerEdge R610 82801IB (ICH9) LPC Interface Controller"
00:1f.2 "IDE interface" "Intel Corporation" "82801IB (ICH9) 2 port SATA Controller [IDE mode]" -r02 -p8f "Dell" "PowerEdge R610 SATA IDE Controller"
01:00.0 "Ethernet controller" "Broadcom Corporation" "NetXtreme II BCM5709 Gigabit Ethernet" -r20 "Dell" "PowerEdge R610 BCM5709 Gigabit Ethernet"
03:00.0 "RAID bus controller" "LSI Logic / Symbios Logic" "MegaRAID SAS 2108 [Liberator]" -r05 "Dell" "PERC H700 Integrated"
06:03.0 "VGA compatible controller" "Matrox Electronics Systems Ltd." "MGA G200eW WPCM450" -r0a "Dell" "PowerEdge R610 MGA G200eW WPCM450"

3. 以树格式输出

-t 选项将以树格式显示输出,其中包含有关总线的信息,以及设备如何连接到这些总线,如下所示。输出将仅使用数字 ID。

# lspci -t
-[0000:00]-+-00.0
           +-01.0-[01]--+-00.0
           |            \-00.1
           +-03.0-[02]--+-00.0
           |            \-00.1
           +-07.0-[04]--
           +-09.0-[05]--
           +-14.0
           +-14.1
           +-1c.0-[03]----00.0
           +-1d.0
           +-1e.0-[06]----03.0
           +-1f.0

4. 详细的设备信息

如果想查看特定设备的详细信息,请使用 -v 获取更多信息。这将显示有关所有设备的信息。该命令的输出会很长,需要向下滚动查看相应的部分。

对于详细程度的附加级别,可以使用 -vv 或 -vvv。

在以下示例中,我仅给出了 RAID 控制器设备的输出。

# lspci -v
 03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)
        Subsystem: Dell PERC H700 Integrated
        Flags: bus master, fast devsel, latency 0, IRQ 16
        I/O ports at fc00 [size=256]
        Memory at df1bc000 (64-bit, non-prefetchable) [size=16K]
        Memory at df1c0000 (64-bit, non-prefetchable) [size=256K]
        Expansion ROM at df100000 [disabled] [size=256K]
        Capabilities: [50] Power Management version 3
        Capabilities: [68] Express Endpoint, MSI 00
        Capabilities: [d0] Vital Product Data
        Capabilities: [a8] MSI: Enable- Count=1/1 Maskable- 64bit+
        Capabilities: [c0] MSI-X: Enable+ Count=15 Masked-
        Capabilities: [100] Advanced Error Reporting
        Capabilities: [138] Power Budgeting <?>
        Kernel driver in use: megaraid_sas
        Kernel modules: megaraid_sas

5. 在输出中显示设备代码

如果要显示 PCI 供应商代码,并且设备代码仅显示为数字,请使用 -n 选项。这不会查找 PCI 文件以获取数字的相应值。

# lspci -n
01:00.1 0200: 14e4:1639 (rev 20)
02:00.0 0200: 14e4:1639 (rev 20)
02:00.1 0200: 14e4:1639 (rev 20)
03:00.0 0104: 1000:0079 (rev 05)
06:03.0 0300: 102b:0532 (rev 0a)

如果要同时显示描述和编号,请使用选项 -nn,如下所示。

# lspci -nn
01:00.0 Ethernet controller [0200]: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet [14e4:1639] (rev 20)
03:00.0 RAID bus controller [0104]: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] [1000:0079] (rev 05)
06:03.0 VGA compatible controller [0300]: Matrox Electronics Systems Ltd. MGA G200eW WPCM450 [102b:0532] (rev 0a)
..

6.查找特定设备

当知道 domain🚌slot.func 格式中的插槽号时,可以查询特定设备,如下所示。在下面的示例中,我们没有指定域号,因为它是 0,可以省略。

# lspci -s 03:00.0
03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)

当知道 vendor:device 格式的设备编号时,可以查询特定设备,如下所示。

# lspci -d 1000:0079
03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)

如果只知道供应商 ID 或设备 ID,则可以省略另一个 ID。例如,以下两个命令都将返回与上述相同的输出。

lspci -d:0079
lspci -d 1000

7.显示内核驱动程序

当想知道将处理特定设备操作的内核模块的名称时,这非常有用。请注意,此选项仅适用于 Kernel 2.6 及更高版本。

# lspci -k
00:1f.2 IDE interface: Intel Corporation 82801IB (ICH9) 2 port SATA Controller [IDE mode] (rev 02)
        Subsystem: Dell PowerEdge R610 SATA IDE Controller
        Kernel driver in use: ata_piix
        Kernel modules: ata_generic, pata_acpi, ata_piix
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
        Subsystem: Dell PowerEdge R610 BCM5709 Gigabit Ethernet
        Kernel driver in use: bnx2
        Kernel modules: bnx2
03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)
        Subsystem: Dell PERC H700 Integrated
        Kernel driver in use: megaraid_sas
        Kernel modules: megaraid_sas        

via: 获取 PCI 总线硬件设备信息的 7 个 Linux lspci 命令示例-云社区-华为云 Tiamo_T 发表于 2022/09/08 16:41:32

https://bbs.huaweicloud.com/blogs/374466

  • 17
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值