lspci 命令详解与参数实测(Ubuntu 22.04)

lspci 命令逐参数实测详解:46 台 PCI 设备清单逐类解读、-n/-nn 数字 ID、-m/-mm 机器可读格式、-t 总线树、-k 内核驱动绑定、-v/-vv 详细模式、-s/-d 设备筛选、-D/-P 域号与桥路径、-x 配置空间转储、-A/-O 访问方法与参数、-i pci.ids 名称解析链与 -q/-Q 联网查询,含 sysfs 可见性与名称解析链机制解析,全部回显在 Ubuntu 22.04(pciutils 3.7.0)实测通过。

Linux命令Linux系统UbuntuUbuntu 22.04命令行系统信息2026/10/15

lspci 命令详解与参数实测(Ubuntu 22.04)

目标:全面掌握 lspci 的每一个常用参数——默认列表逐类解读、-n/-nn 数字 ID、-m/-mm 机器可读单行、-t 总线树、-k 内核驱动绑定、-v/-vv 详细模式、-s/-d 设备筛选、-D/-P 域号与桥路径、-x 配置空间转储、-A/-O 访问方法与参数、-i 自定义 pci.ids 名称解析链,全部命令与回显已在 Ubuntu 22.04(pciutils 3.7.0)实测通过。

一、环境信息

  • 操作系统:Ubuntu 22.04.5 LTS(x86_64,内核 6.8.0-138-generic)
  • lspci 版本:pciutils 3.7.0(lspci --version 实测;包 pciutils 1:3.7.0-6,库 libpci3 1:3.7.0-6)
  • 设备名数据库:pci.ids 0.0~2022.01.22-1ubuntu0.1(/usr/share/misc/pci.ids,实测 1299917 字节)
  • lspci 不随最小化安装预装,需安装 pciutils 包(见 2.2)
  • 实测机 PCI 形态:46 个 PCI 功能(Host bridge、PCI/PCIe 桥、IDE/SATA 控制器、VGA、SCSI、以太网、声卡、USB 控制器、VMware 虚拟设备),数据经 sysfs(/sys/bus/pci)读取
  • 演示数据目录:/root/demo/lspci/(存放默认清单快照)

二、命令概览

2.1 语法与测试数据准备

lspci(list PCI)的基本语法是 lspci [<switches>]:不带参数时枚举总线上全部 PCI 设备,每行"槽位地址 + 类型 + 厂商与设备名"。它的数据来源是 PCI 总线拓扑:默认经 linux-sysfs 访问方法读取 /sys/bus/pci/devices/ 下各设备的配置空间,再查 /usr/share/misc/pci.ids 数据库把 vendor:device 数字 ID 翻译成可读名称。设备枚举是内核视角的真实枚举,输出随真实硬件(含虚拟化平台呈现的虚拟设备)变化,无法用文件模拟,因此本篇不构造演示数据,仅把默认清单存档备查:

mkdir -p /root/demo/lspci
lspci > /root/demo/lspci/pci-list.txt

💡 技术拓展:Linux 下查看硬件信息的命令不止 lspci,各自管辖的总线/层次不同——

命令覆盖范围典型用途
lspciPCI/PCIe 总线设备看显卡、网卡、NVMe 控制器与内核驱动
lsusbUSB 总线设备看外设、U 盘、USB 网卡
dmidecodeDMI/SMBIOS(主板固件层)看主板型号、内存插槽与条目信息
lshw全部硬件(综合树)一次性导出整机硬件清单
lsblk块设备拓扑看磁盘/分区/挂载点层次

本文主角 lspci 专注 PCI 总线一层,粒度到「设备 + 内核驱动」;同机的 USB 设备走 lsusb(另篇详解),整机概览用 lshw。

2.2 安装(pciutils 包)

Ubuntu 22.04 桌面版通常自带 pciutils;最小化安装的服务器/系统镜像需要手动安装。先同步软件源索引,再安装 pciutils(实测输出):

$ apt-get update
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists...

$ apt-get install -y pciutils
Reading package lists...
Building dependency tree...
Reading state information...
pciutils is already the newest version (1:3.7.0-6).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

首次安装时(实测解包与配置阶段输出,摘取 pciutils 相关行):

Selecting previously unselected package pciutils.
Preparing to unpack .../pciutils_1%3a3.7.0-6_amd64.deb ...
Unpacking pciutils (1:3.7.0-6) ...
Setting up pci.ids (0.0~2022.01.22-1ubuntu0.1) ...
Setting up libpci3:amd64 (1:3.7.0-6) ...
Setting up pciutils (1:3.7.0-6) ...

三个包各司其职:pciutils 提供 lspci/setpci 等命令、libpci3 是访问 PCI 配置空间的共享库、pci.ids 是设备 ID 到名称的数据库。安装完立即验证:

$ lspci --version
lspci version 3.7.0

2.3 --help 全量输出

lspci 不支持 --help(也不支持 -h),传入未知参数会打印用法并报错退出——这份用法清单就是它的事实帮助页(实测原样保留):

$ lspci --help
lspci: invalid option -- '-'
Usage: lspci [<switches>]

Basic display modes:
-mm             Produce machine-readable output (single -m for an obsolete format)
-t              Show bus tree

Display options:
-v              Be verbose (-vv or -vvv for higher verbosity)
-k              Show kernel drivers handling each device
-x              Show hex-dump of the standard part of the config space
-xxx            Show hex-dump of the whole config space (dangerous; root only)
-xxxx           Show hex-dump of the 4096-byte extended config space (root only)
-b              Bus-centric view (addresses and IRQ's as seen by the bus)
-D              Always show domain numbers
-P              Display bridge path in addition to bus and device number
-PP             Display bus path in addition to bus and device number

Resolving of device ID's to names:
-n              Show numeric ID's
-nn             Show both textual and numeric ID's (names & numbers)
-q              Query the PCI ID database for unknown ID's via DNS
-qq             As above, but re-query locally cached entries
-Q              Query the PCI database for all ID's via DNS

Selection of devices:
-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]   Show only devices in selected slots
-d [<vendor>]:[<device>][:<class>]              Show only devices with specified ID's

Other options:
-i <file>       Use specified ID database instead of /usr/share/misc/pci.ids.gz
-p <file>       Look up kernel modules in a given file instead of default modules.pcimap
-M              Enable `bus mapping' mode (dangerous; root only)

PCI access options:
-A <method>     Use the specified PCI access method (see `-A help' for a list)
-O <par>=<val>  Set PCI access parameter (see `-O help' for a list)
-G              Enable PCI access debugging
-H <mode>       Use direct hardware access (<mode> = 1 or 2)
-F <file>       Read PCI configuration dump from a given file

💡 说明:参数分四组——显示模式(-m/-mm 单行机器可读、-t 树形、-v 系列详细、-k 驱动、-x 系列转储、-b 总线中心视角、-D/-P 地址扩展)、名称解析(-n/-nn、-q/-qq/-Q 联网查询)、设备筛选(-s 按槽位、-d 按 ID)、访问方法(-A/-O/-G/-H/-F,其中 -M/-xxx/-xxxx 标注 dangerous,仅限 root 且可能干扰系统,本文不做破坏性实测)。

2.4 版本信息

$ lspci --version
lspci version 3.7.0

设备名数据库文件与版本(pci.ids 包提供,lspci 启动时自动加载):

$ ls -l /usr/share/misc/pci.ids
-rw-r--r-- 1 root root 1299917 Mar  6  2025 /usr/share/misc/pci.ids

三、参数逐项实测

3.1 默认输出:46 个设备逐类解读

不带参数的 lspci 每行一个 PCI 功能:槽位地址(总线:槽位.功能)、设备类型、厂商与设备名、修订号(rev):

$ lspci
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:10.0 SCSI storage controller: Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
02:00.0 USB controller: VMware USB1.1 UHCI Controller
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
02:02.0 Multimedia audio controller: Ensoniq ES1371/ES1373 / Creative Labs CT2518 (rev 02)
02:03.0 USB controller: VMware USB2 EHCI Controller
02:04.0 SATA controller: VMware SATA AHCI controller

共 46 个功能,按类型归纳:

  • 00:00.0 / 00:01.0 / 00:07.x:440BX + PIIX4 芯片组经典组合——Host bridge(主桥)、AGP bridge、ISA bridge、IDE 控制器、ACPI 电源管理桥,这是 x86 平台老式芯片组的固定布局。
  • 00:0f.0:VGA 兼容控制器(显示适配),配 vmwgfx 驱动(见 3.5)。
  • 00:10.0:SCSI 存储控制器(LSI 53c1030),并行 SCSI 虚拟磁盘的挂载点。
  • 00:11.0、00:15.0~00:18.7:PCI 与 32 个 PCIe 根端口桥。桥本身不干活,负责挂下游总线——02 号总线就挂在 00:11.0 下面(树形视图见 3.4)。
  • 02:00.0~02:04.0:真正承载 I/O 的端设备——UHCI/EHCI 两个 USB 控制器、e1000 千兆网卡、ES1371 声卡、AHCI SATA 控制器。

💡 提示:槽位地址 02:01.0 读作"2 号总线、1 号槽位、0 号功能"。一个物理插槽可含 8 个功能(.0~.7),多网卡单芯片常以多功能形式出现。

3.2 -n / -nn:数字 ID 视图

-n(--numeric)关闭名称解析,只输出数字 ID——厂商、设备、类型全部以十六进制呈现:

$ lspci -n
00:00.0 0600: 8086:7190 (rev 01)
00:01.0 0604: 8086:7191 (rev 01)
00:07.0 0601: 8086:7110 (rev 08)
00:07.1 0101: 8086:7111 (rev 01)
00:07.3 0680: 8086:7113 (rev 08)
00:07.7 0880: 15ad:0740 (rev 10)
00:0f.0 0300: 15ad:0405
00:10.0 0100: 1000:0030 (rev 01)
00:11.0 0604: 15ad:0790 (rev 02)
00:15.0 0604: 15ad:07a0 (rev 01)
00:15.1 0604: 15ad:07a0 (rev 01)
00:15.2 0604: 15ad:07a0 (rev 01)
00:15.3 0604: 15ad:07a0 (rev 01)
00:15.4 0604: 15ad:07a0 (rev 01)
00:15.5 0604: 15ad:07a0 (rev 01)
00:15.6 0604: 15ad:07a0 (rev 01)
00:15.7 0604: 15ad:07a0 (rev 01)
00:16.0 0604: 15ad:07a0 (rev 01)
00:16.1 0604: 15ad:07a0 (rev 01)
00:16.2 0604: 15ad:07a0 (rev 01)
00:16.3 0604: 15ad:07a0 (rev 01)
00:16.4 0604: 15ad:07a0 (rev 01)
00:16.5 0604: 15ad:07a0 (rev 01)
00:16.6 0604: 15ad:07a0 (rev 01)
00:16.7 0604: 15ad:07a0 (rev 01)
00:17.0 0604: 15ad:07a0 (rev 01)
00:17.1 0604: 15ad:07a0 (rev 01)
00:17.2 0604: 15ad:07a0 (rev 01)
00:17.3 0604: 15ad:07a0 (rev 01)
00:17.4 0604: 15ad:07a0 (rev 01)
00:17.5 0604: 15ad:07a0 (rev 01)
00:17.6 0604: 15ad:07a0 (rev 01)
00:17.7 0604: 15ad:07a0 (rev 01)
00:18.0 0604: 15ad:07a0 (rev 01)
00:18.1 0604: 15ad:07a0 (rev 01)
00:18.2 0604: 15ad:07a0 (rev 01)
00:18.3 0604: 15ad:07a0 (rev 01)
00:18.4 0604: 15ad:07a0 (rev 01)
00:18.5 0604: 15ad:07a0 (rev 01)
00:18.6 0604: 15ad:07a0 (rev 01)
00:18.7 0604: 15ad:07a0 (rev 01)
02:00.0 0c03: 15ad:0774
02:01.0 0200: 8086:100f (rev 01)
02:02.0 0401: 1274:1371 (rev 02)
02:03.0 0c03: 15ad:0770
02:04.0 0106: 15ad:07e0

-nn 同时输出名称与数字 ID(方括号内),是排查硬件型号时最常用的形态——名称便于人读,数字 ID 便于搜索驱动与提交工单:

$ lspci -nn
00:00.0 Host bridge [0600]: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge [8086:7190] (rev 01)
00:01.0 PCI bridge [0604]: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge [8086:7191] (rev 01)
00:07.0 ISA bridge [0601]: Intel Corporation 82371AB/EB/MB PIIX4 ISA [8086:7110] (rev 08)
00:07.1 IDE interface [0101]: Intel Corporation 82371AB/EB/MB PIIX4 IDE [8086:7111] (rev 01)
00:07.3 Bridge [0680]: Intel Corporation 82371AB/EB/MB PIIX4 ACPI [8086:7113] (rev 08)
00:07.7 System peripheral [0880]: VMware Virtual Machine Communication Interface [15ad:0740] (rev 10)
00:0f.0 VGA compatible controller [0300]: VMware SVGA II Adapter [15ad:0405]
00:10.0 SCSI storage controller [0100]: Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI [1000:0030] (rev 01)
00:11.0 PCI bridge [0604]: VMware PCI bridge [15ad:0790] (rev 02)
00:15.0 PCI bridge [0604]: VMware PCI Express Root Port [15ad:07a0] (rev 01)
(中略:00:15.1 至 00:18.6 同为 VMware PCI Express Root Port [15ad:07a0],共 32 个根端口)
00:18.7 PCI bridge [0604]: VMware PCI Express Root Port [15ad:07a0] (rev 01)
02:00.0 USB controller [0c03]: VMware USB1.1 UHCI Controller [15ad:0774]
02:01.0 Ethernet controller [0200]: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) [8086:100f] (rev 01)
02:02.0 Multimedia audio controller [0401]: Ensoniq ES1371/ES1373 / Creative Labs CT2518 [1274:1371] (rev 02)
02:03.0 USB controller [0c03]: VMware USB2 EHCI Controller [15ad:0770]
02:04.0 SATA controller [0106]: VMware SATA AHCI controller [15ad:07e0]

💡 要点:0600=Host bridge、0604=PCI bridge、0300=VGA、0200=以太网、0c03=USB 控制器、0106=SATA——首位是设备大类。拿到 15ad:0405 这类 ID 后,可直接在 pci.ids 数据库里 grep 验证:15ad 是 VMware 的厂商 ID、8086 是 Intel、1000 是 LSI。

3.3 -m / -mm:机器可读单行格式

-m/-mm 把每台设备压成一行,所有字段用双引号包裹,供脚本 eval/awk 解析;-r01、-p8a 等前缀是修订号与编程接口号:

$ lspci -m | head -8
00:00.0 "Host bridge" "Intel Corporation" "440BX/ZX/DX - 82443BX/ZX/DX Host bridge" -r01 "VMware" "Virtual Machine Chipset"
00:01.0 "PCI bridge" "Intel Corporation" "440BX/ZX/DX - 82443BX/ZX/DX AGP bridge" -r01 "" ""
00:07.0 "ISA bridge" "Intel Corporation" "82371AB/EB/MB PIIX4 ISA" -r08 "VMware" "Virtual Machine Chipset"
00:07.1 "IDE interface" "Intel Corporation" "82371AB/EB/MB PIIX4 IDE" -r01 -p8a "VMware" "Virtual Machine Chipset"
00:07.3 "Bridge" "Intel Corporation" "82371AB/EB/MB PIIX4 ACPI" -r08 "VMware" "Virtual Machine Chipset"
00:07.7 "System peripheral" "VMware" "Virtual Machine Communication Interface" -r10 "VMware" "Virtual Machine Communication Interface"
00:0f.0 "VGA compatible controller" "VMware" "SVGA II Adapter" "VMware" "SVGA II Adapter"
00:10.0 "SCSI storage controller" "Broadcom / LSI" "53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI" -r01 "VMware" "LSI Logic Parallel SCSI Controller"

字段依次为:槽位、类型名、厂商名、设备名、修订号(可选)、子系统厂商、子系统设备名。子系统两列能区分"同一芯片的不同整机"——例如 02:01.0 的子系统名是 PRO/1000 MT Single Port Adapter,说明这块 e1000 芯片以 VMware 虚拟网卡形态提供。

-mm 是现代机器可读格式(帮助原文注明 -m 为 obsolete format),实测输出与 -m 逐行一致;-mm -nn 组合可在每对引号里再带上数字 ID,正则或 JSON 转换时最好处理:

$ lspci -mm -nn | head -8
00:00.0 "Host bridge [0600]" "Intel Corporation [8086]" "440BX/ZX/DX - 82443BX/ZX/DX Host bridge [7190]" -r01 "VMware [15ad]" "Virtual Machine Chipset [1976]"
00:01.0 "PCI bridge [0604]" "Intel Corporation [8086]" "440BX/ZX/DX - 82443BX/ZX/DX AGP bridge [7191]" -r01 "" ""
00:07.0 "ISA bridge [0601]" "Intel Corporation [8086]" "82371AB/EB/MB PIIX4 ISA [7110]" -r08 "VMware [15ad]" "Virtual Machine Chipset [1976]"
00:07.1 "IDE interface [0101]" "Intel Corporation [8086]" "82371AB/EB/MB PIIX4 IDE [7111]" -r01 -p8a "VMware [15ad]" "Virtual Machine Chipset [1976]"
00:07.3 "Bridge [0680]" "Intel Corporation [8086]" "82371AB/EB/MB PIIX4 ACPI [7113]" -r08 "VMware [15ad]" "Virtual Machine Chipset [1976]"
00:07.7 "System peripheral [0880]" "VMware [15ad]" "Virtual Machine Communication Interface [0740]" -r10 "VMware [15ad]" "Virtual Machine Communication Interface [0740]"
00:0f.0 "VGA compatible controller [0300]" "VMware [15ad]" "SVGA II Adapter [0405]" "VMware [15ad]" "SVGA II Adapter [0405]"
00:10.0 "SCSI storage controller [0100]" "Broadcom / LSI [1000]" "53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI [0030]" -r01 "VMware [15ad]" "LSI Logic Parallel SCSI Controller [1976]"

💡 要点:写资产盘点脚本时用 -mm -nn 而非默认格式——引号包裹保证含空格字段不被拆散,双列 ID 免去再查库。head -8 用于展示,实际清单共 46 行。

3.4 -t / -tv:总线拓扑树

-t 以树形呈现 PCI 拓扑:- 开头是根复合体,+-/\- 是桥下挂载点,方括号是桥分配的次级总线号:

$ lspci -t
-[0000:00]-+-00.0
           +-01.0-[01]--
           +-07.0
           +-07.1
           +-07.3
           +-07.7
           +-0f.0
           +-10.0
           +-11.0-[02]--+-00.0
           |            +-01.0
           |            +-02.0
           |            +-03.0
           |            \-04.0
           +-15.0-[03]--
           +-15.1-[04]--
           +-15.2-[05]--
           +-15.3-[06]--
           +-15.4-[07]--
           +-15.5-[08]--
           +-15.6-[09]--
           +-15.7-[0a]--
           +-16.0-[0b]--
           +-16.1-[0c]--
           +-16.2-[0d]--
           +-16.3-[0e]--
           +-16.4-[0f]--
           +-16.5-[10]--
           +-16.6-[11]--
           +-16.7-[12]--
           +-17.0-[13]--
           +-17.1-[14]--
           +-17.2-[15]--
           +-17.3-[16]--
           +-17.4-[17]--
           +-17.5-[18]--
           +-17.6-[19]--
           +-17.7-[1a]--
           +-18.0-[1b]--
           +-18.1-[1c]--
           +-18.2-[1d]--
           +-18.3-[1e]--
           +-18.4-[1f]--
           +-18.5-[20]--
           +-18.6-[21]--
           \-18.7-[22]--

一眼可见:02 号总线挂在 00:11.0 桥下,该桥下有 5 个端设备(00.004.0,即 USB/网卡/声卡/USB/SATA);其余 32 个 PCIe 根端口各分配了一条空总线(01、0322),是预留的扩展槽位。-tv 在树里同时显示设备名:

$ lspci -tv
-[0000:00]-+-00.0  Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge
           +-01.0-[01]--
           +-07.0  Intel Corporation 82371AB/EB/MB PIIX4 ISA
           +-07.1  Intel Corporation 82371AB/EB/MB PIIX4 IDE
           +-07.3  Intel Corporation 82371AB/EB/MB PIIX4 ACPI
           +-07.7  VMware Virtual Machine Communication Interface
           +-0f.0  VMware SVGA II Adapter
           +-10.0  Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI
           +-11.0-[02]--+-00.0  VMware USB1.1 UHCI Controller
           |            +-01.0  Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
           |            +-02.0  Ensoniq ES1371/ES1373 / Creative Labs CT2518
           |            +-03.0  VMware USB2 EHCI Controller
           |            \-04.0  VMware SATA AHCI controller
           +-15.0-[03]--
(中略:其余 PCIe 根端口分支同上,均为空总线)
           \-18.7-[22]--

💡 要点:判断"设备插在哪个口/桥下"只有 -t 能直观回答,做 SR-IOV、网卡多队列调优、GPU 直通排障时先用 -t 建立拓扑图。

3.5 -k:内核驱动绑定关系

-k(--kernel-drivers)在每台设备下追加 Kernel driver in use(当前绑定的驱动,来自 sysfs 的 driver 符号链接)与 Kernel modules(可服务该设备的模块清单,来自 /lib/modules/$(uname -r)/modules.alias),并顺带显示 Subsystem 行(实测全文):

$ lspci -k
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
	Subsystem: VMware Virtual Machine Chipset
	Kernel driver in use: agpgart-intel
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
	Subsystem: VMware Virtual Machine Chipset
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
	Subsystem: VMware Virtual Machine Chipset
	Kernel driver in use: ata_piix
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
	Subsystem: VMware Virtual Machine Chipset
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
	Subsystem: VMware Virtual Machine Communication Interface
	Kernel driver in use: vmw_vmci
	Kernel modules: vmw_vmci
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
	Subsystem: VMware SVGA II Adapter
	Kernel driver in use: vmwgfx
	Kernel modules: vmwgfx
00:10.0 SCSI storage controller: Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
	Subsystem: VMware LSI Logic Parallel SCSI Controller
	Kernel driver in use: mptspi
	Kernel modules: mptspi
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
	Kernel driver in use: pcieport
02:00.0 USB controller: VMware USB1.1 UHCI Controller
	DeviceName: usb
	Subsystem: VMware USB1.1 UHCI Controller
	Kernel driver in use: uhci_hcd
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
	DeviceName: Ethernet0
	Subsystem: VMware PRO/1000 MT Single Port Adapter
	Kernel driver in use: e1000
	Kernel modules: e1000
02:02.0 Multimedia audio controller: Ensoniq ES1371/ES1373 / Creative Labs CT2518 (rev 02)
	DeviceName: sound
	Subsystem: Ensoniq Audio PCI 64V/128/5200 / Creative CT4810/CT5803/CT5806 [Sound Blaster PCI]
	Kernel driver in use: snd_ens1371
02:03.0 USB controller: VMware USB2 EHCI Controller
	DeviceName: ehci
	Subsystem: VMware USB2 EHCI Controller
	Kernel driver in use: ehci-pci
02:04.0 SATA controller: VMware SATA AHCI controller
	DeviceName: sata0
	Subsystem: VMware SATA AHCI controller
	Kernel driver in use: ahci
	Kernel modules: ahci

逐条解读(仅列关键设备):agpgart-intel 管主桥的 AGP 兼容层、ata_piix 接管老式 IDE、vmw_vmci 是虚拟机通信接口、vmwgfx 是显示驱动、mptspi 驱动并行 SCSI 磁盘、e1000 千兆网卡、snd_ens1371 声卡、uhci_hcd/ehci-pci 分别是 USB 1.1/2.0 主机控制器、ahci 接管 SATA;32 个 PCIe 根端口统一由内核内建的 pcieport 管理(桥类设备不显示 Kernel modules 行)。DeviceName 行是固件(如 VMware 虚拟硬件描述)提供的设备别名。注意 00:01.0、00:07.0、00:07.3、00:11.0 四台设备没有任何 Kernel 行——AGP 桥、ISA 桥、ACPI 桥与 VMware PCI 桥没有绑定驱动,属正常现象。

💡 要点:Kernel driver in use(实际绑定)与 Kernel modules(可绑定的候选模块)是两回事。换驱动排障(如 e1000 换 e1000e)时,先看 in use 确认现状,再看 modules 确认候选,随后 modprobe + 重新绑定。

3.6 -v / -vv:详细与更详细模式

-v 追加每台设备的资源行:标志、IRQ、I/O 端口、内存映射区、扩展 ROM、能力列表、驱动绑定。先看单台设备(配 -s,见 3.7)的完整回显:

$ lspci -s 00:0f.0 -v
00:0f.0 VGA compatible controller: VMware SVGA II Adapter (prog-if 00 [VGA controller])
	Subsystem: VMware SVGA II Adapter
	Flags: bus master, medium devsel, latency 64, IRQ 16
	I/O ports at 1070 [size=16]
	Memory at e8000000 (32-bit, prefetchable) [size=128M]
	Memory at fe000000 (32-bit, non-prefetchable) [size=8M]
	Expansion ROM at 000c0000 [virtual] [disabled] [size=128K]
	Capabilities: <access denied>
	Kernel driver in use: vmwgfx
	Kernel modules: vmwgfx

逐行解读:Flags 中 bus master 表示允许设备主动发起 DMA,IRQ 16 是中断号;I/O ports at 1070 是 16 字节 I/O 端口窗口;两段 Memory 是 MMIO 区——128M 可预取显存窗口加 8M 寄存器窗口;Expansion ROM ... [disabled] 是未启用的选项 ROM;最后两行驱动信息同 3.5。

-vv 再加一层:导出配置空间头部的原始控制/状态寄存器、延迟、中断引脚与物理槽位号,更适合驱动排障。以 SATA 控制器为例(实测全文):

$ lspci -s 02:04.0 -vv
02:04.0 SATA controller: VMware SATA AHCI controller (prog-if 01 [AHCI 1.0])
	DeviceName: sata0
	Subsystem: VMware SATA AHCI controller
	Physical Slot: 36
	Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
	Status: Cap+ 66MHz+ UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
	Latency: 64
	Interrupt: pin A routed to IRQ 56
	Region 5: Memory at fd5ee000 (32-bit, non-prefetchable) [size=4K]
	Expansion ROM at fd510000 [virtual] [disabled] [size=64K]
	Capabilities: <access denied>
	Kernel driver in use: ahci
	Kernel modules: ahci

-v 不加 -s 时对全部 46 台设备输出(约 500 行),以下为首部节选(实测首尾标注):

$ lspci -v
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
	Subsystem: VMware Virtual Machine Chipset
	Flags: bus master, medium devsel, latency 0
	Kernel driver in use: agpgart-intel

00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01) (prog-if 00 [Normal decode])
	Flags: bus master, 66MHz, medium devsel, latency 0
	Bus: primary=00, secondary=01, subordinate=01, sec-latency=64
	I/O behind bridge: [disabled]
	Memory behind bridge: [disabled]
	Prefetchable memory behind bridge: [disabled]

00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
	Subsystem: VMware Virtual Machine Chipset
	Flags: bus master, medium devsel, latency 0
(输出节选:后续设备依次展开,直至 02:04.0 SATA 控制器,全文约 500 行)

💡 提示:Capabilities: <access denied> 表示配置空间能力区读取被当前环境的访问策略拒绝(本实测环境对 64 字节标准头之外的配置空间读取受限,全文共 43 处);标准服务器以 root 运行时会在此列出电源管理、MSI、PCIe 能力等子项。Physical Slot: 36 一行只有 -vv 才输出,定位机箱槽位时靠它。

3.7 -s:按槽位筛选设备

-s 的寻址语法是 [[[[<域>]:]<总线>]:][<槽位>][.[<功能>]],各段均可省略以实现"按总线筛"或"按功能筛"。实测三种典型写法——精确到功能、省略功能号、指定域号:

$ lspci -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

$ lspci -s 00:0f.0
00:0f.0 VGA compatible controller: VMware SVGA II Adapter

$ lspci -D -s 02:01.0
0000:02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

-D 强制输出里总是带 PCI 域号(0000:)。多路服务器或带多个 PCI 域(domain)的平台上域号才有区分度,单域平台默认省略。-s 与 -v/-k/-nn 全部正交组合,如 lspci -nnk -s 02:01.0。

💡 要点:-s 接受 02:(整条总线)、02:01.(单槽全部功能)、.1(所有总线的 1 号功能)等省略形态;写巡检脚本时用 -s 0000:02:01.0 带域全地址最稳。

3.8 -d:按厂商/设备/类代码筛选

-d [<vendor>]:[<device>][:<class>] 按数字 ID 过滤,任一段可留空表示通配。筛出全部 Intel 设备(vendor 8086):

$ lspci -d 8086:
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

筛出全部 VMware 设备(vendor 15ad):

$ lspci -d 15ad:
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
02:00.0 USB controller: VMware USB1.1 UHCI Controller
02:03.0 USB controller: VMware USB2 EHCI Controller
02:04.0 SATA controller: VMware SATA AHCI controller

精确匹配到 device ID(8086:100e 是 e1000 家族另一型号,本机不存在,输出为空):

$ lspci -d 8086:100e

💡 要点:-d 的 ID 都是十六进制(不带 0x 前缀),来源即 -nn 输出方括号里的编号。给某型号设备批量下驱动/核对批次时,-d 比 grep 默认输出更精确(不会误伤名称相似的型号)。

3.9 -P / -PP:桥路径视图

-P 在地址前追加"途经桥链",-PP 展示完整总线路径。实测 02:01.0 网卡位于 00:11.0 桥之下:

$ lspci -P -s 02:01.0
00:11.0/01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

00:11.0/01.0 读作"经 00:11.0 桥、再经总线 01 上的 01.0 位置"。深层树(多级 PCIe switch)中 -PP 的全路径对定位物理插口更直观。

3.10 -x:配置空间十六进制转储

-x 转储配置空间标准头部前 64 字节,每行 16 字节、行首是偏移:

$ lspci -x -s 00:07.0
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00: 86 80 10 71 07 00 80 02 08 00 01 06 00 00 80 00
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 ad 15 76 19
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

按小端序解读头部:偏移 00 的 86 80 即 vendor ID 0x8086(Intel)、10 71 即 device ID 0x7110;07 00 是命令寄存器;08 00 01 06 依次为修订号 08、编程接口 00、子类 01(ISA bridge)、基类 06(Bridge);偏移 2C 的 ad 15 76 19 是子系统 ID 0x15ad:0x1976(VMware 虚拟芯片组)。帮助还提供 -xxx(全 256 字节)与 -xxxx(4096 字节扩展空间),帮助原文标注 dangerous、root only,会干扰设备运行,生产环境慎用。

3.11 -A / -O:访问方法与访问参数

-A 指定读配置空间的底层方法。-A help 列出本机全部可用方法(实测):

$ lspci -A help
Known PCI access methods:

linux-sysfs
linux-proc
intel-conf1
intel-conf2
dump

五种方法的取舍——linux-sysfs 读 /sys/bus/pci(默认,最安全);linux-proc 读 /proc/bus/pci(传统接口);intel-conf1/intel-conf2 是 x86 直接 I/O 端口访问(绕过内核,风险高);dump 从文件回放(配 -F 与 -O dump.name=)。两种主流方法实测结果一致:

$ lspci -A linux-proc -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

$ lspci -A linux-sysfs -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

-O 微调访问参数,-O help 列出全部参数与默认值(实测):

$ lspci -O help
Known PCI access parameters:

dump.name            Name of the bus dump file to read from ()
proc.path            Path to the procfs bus tree (/proc/bus/pci)
sysfs.path           Path to the sysfs device tree (/sys/bus/pci)
hwdb.disable         Do not look up names in UDEV's HWDB if non-zero (0)
net.cache_name       Name of the ID cache file (~/.pciids-cache)
net.domain           DNS domain used for resolving of ID's (pci.id.ucw.cz)

💡 要点:sysfs.path 参数可以在不换机器的情况下读取另一套 sysfs 树(如挂载的救援盘),与 -F+-O dump.name= 的离线回放配合,可在任何一台机器上分析另一台的 PCI 配置。

3.12 -i:自定义 pci.ids 与名称解析链

-i 指定替代的 ID 数据库文件。指向 /dev/null(空库)时,名称解析只剩回落通道——本机 02:01.0 仍解析成功,因为它先前被 -Q 联网查询后写入了本地缓存 ~/.pciids-cache;而 00:0f.0(VMware SVGA)未被缓存,同时用 -O hwdb.disable=1 关掉 UDEV 硬件数据库后彻底退化为纯数字(实测):

$ lspci -i /dev/null -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

$ lspci -i /usr/share/misc/pci.ids -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

$ lspci -O hwdb.disable=1 -i /dev/null -s 00:0f.0
00:0f.0 Class 0300: Device 15ad:0405

缓存文件内容(-Q 实际写入的记录,前缀为查询类型与 ID):

#PCI-CACHE-1.0
6 2 0 0 0 Ethernet controller
1 8086 0 0 0 Intel Corporation
2 8086 100f 0 0 82545EM Gigabit Ethernet Controller (Copper)

💡 要点:lspci 的名称解析链为——-i 指定库(默认 /usr/share/misc/pci.ids)→ 本地缓存 ~/.pciids-cache → UDEV 硬件数据库(HWDB)→ 联网查询(仅 -q/-qq/-Q)。任何一环命中即止,-O hwdb.disable=1 与清空缓存可逐层裁剪,用于验证"名称究竟来自哪个库"。

3.13 -q / -qq / -Q:联网查询未知 ID

三个联网参数的差别:-q 仅对 pci.ids 里查不到的 ID 联网查询(命中后写缓存);-qq 对缓存里的旧条目也重新查询;-Q 无条件查询全部 ID(双向解析)。本机所有 ID 均已在库,三个参数都无可见变化、也不影响退出码:

$ lspci -q -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

$ lspci -Q -s 02:01.0
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)

💡 提示:查询域名由 -O net.domain= 控制(默认 pci.id.ucw.cz),内网隔离环境请勿使用 -Q(会为每台设备发起 DNS 查询);离线机器遇到"Unknown device"时,导出 -nn 结果到能联网的机器上查更实际。

四、实战示例

4.1 网卡定位:从接口名反查 PCI 槽位

先把默认清单存档,再对以太网控制器取详细驱动信息(演示数据见 /root/demo/lspci/pci-list.txt):

$ lspci > /root/demo/lspci/pci-list.txt && wc -l < /root/demo/lspci/pci-list.txt
46

$ lspci -nnk -s 02:01.0
02:01.0 Ethernet controller [0200]: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) [8086:100f] (rev 01)
	DeviceName: Ethernet0
	Subsystem: VMware PRO/1000 MT Single Port Adapter [15ad:0750]
	Kernel driver in use: e1000
	Kernel modules: e1000

-nnk -s <槽位> 三合一,一次拿到型号、数字 ID、子系统与驱动,是网卡/显卡排障的标准起手式。

4.2 盘点内核驱动的绑定分布

-k 输出的驱动行经 sort | uniq -c 汇总,一台机器上"谁在管哪些设备"一目了然:

$ lspci -k | grep 'Kernel driver in use' | sort | uniq -c
      1         Kernel driver in use: agpgart-intel
      1         Kernel driver in use: ahci
      1         Kernel driver in use: ata_piix
      1         Kernel driver in use: e1000
      1         Kernel driver in use: ehci-pci
      1         Kernel driver in use: mptspi
     32         Kernel driver in use: pcieport
      1         Kernel driver in use: snd_ens1371
      1         Kernel driver in use: uhci_hcd
      1         Kernel driver in use: vmw_vmci
      1         Kernel driver in use: vmwgfx

32 个 pcieport 对应 3.4 总线树里的 32 个 PCIe 根端口;其余驱动各管一台端设备,与 3.5 的逐条解读吻合。

4.3 总线树定位空槽位与已用槽位

扩容前用 -t 一眼确认哪些根端口还空着(3.4 的树中 01、03~22 号总线皆空),再结合 -P 验证目标设备的桥路径,规划直通或热插拔位置。

4.4 把 PCI 清单转成机器可读资产表

-mm -nn 的引号格式直接喂给 awk(-F'"' 按引号切列),生成"槽位/类型/厂商/设备名"资产表:

$ lspci -mm -nn | awk -F'"' '{print $1 $2 "|" $4 "|" $6}' | head -5
00:00.0 Host bridge [0600]|Intel Corporation [8086]|440BX/ZX/DX - 82443BX/ZX/DX Host bridge [7190]
00:01.0 PCI bridge [0604]|Intel Corporation [8086]|440BX/ZX/DX - 82443BX/ZX/DX AGP bridge [7191]
00:07.0 ISA bridge [0601]|Intel Corporation [8086]|82371AB/EB/MB PIIX4 ISA [7110]
00:07.1 IDE interface [0101]|Intel Corporation [8086]|82371AB/EB/MB PIIX4 IDE [7111]
00:07.3 Bridge [0680]|Intel Corporation [8086]|82371AB/EB/MB PIIX4 ACPI [7113]

4.5 校验磁盘控制器与 AHCI 状态

装系统前确认 SATA 控制器型号与驱动是否就位(ahci 未加载时系统盘可能不可见):

$ lspci -k -s 02:04.0
02:04.0 SATA controller: VMware SATA AHCI controller
	DeviceName: sata0
	Subsystem: VMware SATA AHCI controller
	Kernel driver in use: ahci
	Kernel modules: ahci

五、注意事项与常见问题

Q1:lspci 是从哪里读到设备清单的?没有插新硬件它会变吗? lspci 的默认访问方法 linux-sysfs 直接读取内核 sysfs:/sys/bus/pci/devices/ 下每个目录对应一个 PCI 功能,配置空间来自目录内 config 文件。清单由内核在开机枚举与热插拔时维护,插入 PCIe 设备(支持热插拔的平台)会即时出现,无需重启。这也是 lspci 输出完全跟随真实硬件、无法用文件伪造的原因——设备可见性取决于内核看到的总线。

Q2:为什么 -v 里 Capabilities: <access denied>,而其他行都正常? Capabilities: 之后的内容位于配置空间 64 字节标准头之外。实测环境对这段扩展配置空间读取受限(全文 43 处),lspci 如实标注 access denied;标准服务器以 root 运行时该行会展开为电源管理、MSI-X、PCIe 等能力子项。若在真实服务器上也遇到,检查是否非 root(配置空间文件权限 0400,仅 root 可全读)。

Q3:Kernel modules: 行为什么有时没有? Kernel driver in use 直接读 sysfs 的驱动绑定符号链接,永远反映现状;Kernel modules 则需要查 /lib/modules/$(uname -r)/modules.alias(由 kmod 包的 depmod 依据内核模块生成,linux-modules/linux-modules-extra 包提供 .ko 文件)。模块包未装齐或未执行 depmod 时该行缺失,lspci 同时报 lspci: Unable to load libkmod resources: error -2(实测)。补齐方式:安装与内核版本对应的 linux-modules 包并执行 depmod -a。

Q4:设备名显示 Unknown device 怎么办? 说明 pci.ids 数据库比硬件旧。两种处理:升级系统内的 pci.ids 包;或执行 update-pciids(pciutils 自带,从网络下载最新数据库覆盖 /usr/share/misc/pci.ids)。-q/-Q 的 DNS 查询是临时通道,结果会写入 ~/.pciids-cache,但正式环境建议以本地数据库为准。

Q5:lspci 会不会改系统状态?哪些参数危险? lspci 本身只读。帮助标注 dangerous 的 -M(总线映射模式,会扫描全部总线号)、-xxx/-xxxx(全量配置空间转储)、以及绕过内核的 -H/intel-conf* 方法,都可能干扰设备运行,仅限厂商调试使用。

Q6:lspci 与 lsusb、lshw 怎么分工? 三者都是硬件巡检工具,层级不同:lspci 看 PCI/PCIe 总线(网卡、显卡、存储控制器、USB 控制器);lsusb 看 USB 总线(键鼠、U 盘、USB 网卡,见《lsusb 命令详解与参数实测(Ubuntu 22.04)》);lshw 则汇总全总线(含内存、磁盘、固件版本)输出超详细报告。快速定位某类设备用 lspci/lsusb,出完整硬件资产清单用 lshw(本文不展开)。

六、参考链接