lspci 命令用于顯示 Linux 系統上的設備和驅動程序
當在個人電腦或服務器上運行 Linux 時,有時需要識別該系統中的硬件。lspci 命令用于顯示連接到 PCI 總線的所有設備,從而滿足上述需求。該命令由 pciutils 包提供,可用于各種基于 Linux 和 BSD 的操作系統。
基礎用法
當普通用戶運行 lspci 時,顯示的信息可能會受到訪問權限限制。使用 sudo 運行該命令可以提供完整的信息。
以下是家庭媒體中心電腦的一個示例。它是一臺基于 AMD Phenom CPU 的系統,具有 AMD 芯片組,它還配備了 Atheros 無線控制器和 Nvidia 顯卡。
僅運行 lspci 會列出 PCI 總線及其連接的設備。所有硬件設備都列有供應商、名稱和型號等詳細信息。
1. $ sudo lspci2. 00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] RS880 Host Bridge3. 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 Controller8. 00:12.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0 USB OHCI1 Controller9. 00:12.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller10. 00:13.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller11. 00:13.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0 USB OHCI1 Controller12. 00:13.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller13. 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 Controller15. 00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 LPC host controller16. 00:14.4 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 PCI to PCI Bridge17. 00:14.5 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI2 Controller18. 00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor HyperTransport Configuration19. 00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Address Map20. 00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor DRAM Controller21. 00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Miscellaneous Control22. 00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Link Control23. 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 VGA2. 00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07)3. $ sudo lspci | grep -e 3D4. 01:00.0 3D controller: NVIDIA Corporation GM108M [GeForce MX130] (rev a2)
下面(LCTT 譯注:原文為 “above”,應為作者筆誤)的 grep 命令在媒體中心 PC 上定位了一個 VGA 設備,但沒有顯示 3D 設備。
1. $ sudo lspci | grep -e VGA2. 01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [GeForce GTX 650] (rev a1)3. $ sudo lspci | grep -e 3D4. $
按供應商 ID 搜索
還有另一種無需 grep 的方法可以使用。假設想確認一下此計算機是否有其他的 Nvidia 設備,在此之前們還需要一些額外信息,使用-nn
選項顯示的供應商和設備 ID 號。在媒體中心 PC 上,此選項會給出 VGA 卡、供應商 ID 和設備 ID:
- $ sudo lspci -nn | grep -e VGA
- 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: nvidia5. Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia6. 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_intel9. 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-pciids2. Downloaded daily snapshot dated 2021-08-22 03:15:01
獲取 PCI 總線硬件設備信息的 7 個 Linux lspci 命令示例
【摘要】
lspci
命令可視為" ls + pci "
的組合功能。
lspci 將顯示有關服務器中所有 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 -v03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)Subsystem: Dell PERC H700 IntegratedFlags: bus master, fast devsel, latency 0, IRQ 16I/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 3Capabilities: [68] Express Endpoint, MSI 00Capabilities: [d0] Vital Product DataCapabilities: [a8] MSI: Enable- Count=1/1 Maskable- 64bit+Capabilities: [c0] MSI-X: Enable+ Count=15 Masked-Capabilities: [100] Advanced Error ReportingCapabilities: [138] Power Budgeting <?>Kernel driver in use: megaraid_sasKernel 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 ControllerKernel driver in use: ata_piixKernel 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 EthernetKernel driver in use: bnx2Kernel modules: bnx2
03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)Subsystem: Dell PERC H700 IntegratedKernel driver in use: megaraid_sasKernel modules: megaraid_sas
via:
-
lspci 命令用于顯示 Linux 系統上的設備和驅動程 作者:Alan Formy-Duval LCTT 原創編譯,Linux中國 榮譽推出 2021-09-17
https://opensource.com/article/21/9/lspci-linux-hardware -
獲取 PCI 總線硬件設備信息的 7 個 Linux lspci 命令示例-云社區-華為云 Tiamo_T 發表于 2022/09/08 16:41:32
https://bbs.huaweicloud.com/blogs/374466