Have you ever encountered a time when you worked in a remote Linux server and needed to check what was connected to the system’s local PCI Express and PCI buses? To determine what PCI devices are connected one of the simplest ways to do this is using the lspci command.
Introduction
The lspci command on Linux is a utility that lists the PCI devices connected to a system. The lspci command comes pre-installed on almost all Linux distributions, so you shouldn’t need to worry about installing it. However, if you run into an edge case the package you want to look is pciutils. In this post we will dig into the syntax, what the results mean, and other flags you may find useful.
Basic Syntax
The simplest syntax of the lspci command is:
lspci
All instances of the command will follow the following syntax:
lspci [options]
Troubleshooting Note: If you receive a permissions denied error when trying to run the lspci command, try again using sudo or a user with elevated privileges.
Results Explained
00:00.0 Host bridge: Intel Corporation 440FX – 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Red Hat, Inc. QXL paravirtual graphic card (rev 05)
00:03.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
00:05.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge
00:07.0 SATA controller: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode] (rev 02)
00:09.0 Communication controller: Red Hat, Inc. Virtio console
00:12.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:1e.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge
00:1f.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge
01:01.0 SCSI storage controller: Red Hat, Inc. Virtio SCSI
Let’s break one of these down by section:
00:12.0 Ethernet controller: Red Hat, Inc. Virtio network device
- The bus ID
- The device class
- The Vendor and device information
- In some cases a revision number may be included
What Is The Bus ID?
Indicates how the device is connected to the system, this consists of the PCI bus, the slot, and the function. The function is relevant for devices that do more than a single thing for example a dual port Ethernet card.
What Is The Device Class?
The device class indicates the type of device by its function.
What Is The Revision Number?
This indicates the revision or iteration of the device.
Flags
Below are some of the flags I believe you will find most useful.
-t Show a tree-like diagram of the buses, bridges, and devices.
-v Be verbose and display detailed information about all devices.
-vv Be very verbose and display more details. This level includes everything deemed useful.
-vvv Be even more verbose and display everything.
-k Show kernel drivers handling each device and also kernel modules capable of handling it. Turned on by default when -v is given in the normal mode of output.
-b Bus-centric view. Show all IRQ numbers and addresses as seen by the cards on the PCI bus instead of as seen by the kernel.
-D Always show PCI domain numbers. By default, lspci suppresses them on machines that have only domain 0.
-P Identify PCI devices by path through each bridge, instead of by bus number.
-PP Identify PCI devices by path through each bridge, showing the bus number as well as the device number.
-n Show PCI vendor and device codes as numbers instead of looking them up in the PCI ID list.
-nn Show PCI vendor and device codes as both numbers and names.
-Q Query the central database even for entries that are recognized locally. Use this if you suspect that the displayed entry is wrong.
-M Invoke bus mapping mode which performs a thorough scan of all PCI devices, including those behind misconfigured bridges, etc. This option gives meaningful results only with a direct hardware access mode, which usually requires root privileges.
–version Shows lspci version.
The above list is not exhaustive, for a full list check out an online man page or check your local man page by running man lspci.
Formatting For Parsing
In addition to the above flags if you’re looking to use the output of the lspci command in a script or another pragmatic fashion it is recommended you use one of the sets of flags below:
-m Dump PCI device data in a backward-compatible machine-readable form.
-mm Dump PCI device data in a machine-readable form for easy parsing by scripts.
-vm In this mode, lspci tries to be perfectly compatible with its old versions. It’s almost the same as the regular verbose format, but the Device tag is used for both the slot and the device name, so it occurs twice in a single record. Please avoid using this format in any new code.
-vmm The verbose output is a sequence of records separated by blank lines. Each record describes a single device by a sequence of lines, each line containing a single ‘tag: value’ pair. The tag and the value are separated by a single tab character. Neither the records nor the lines within a record are in any particular order. Tags are case-sensitive.
Conclusion
In this post we answer the question of how do I list connected PCI devices. The lspci command is the perfect command to answer this question. From basic usage, what the results mean, flags you may find useful, and flags recommend for scripts/programs.
Additional Links
Are you done reading and looking for more, why not check these links out?
Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.
Leave a Reply