How to view PCI devices with lspci
How to View PCI Devices with lspci
Table of Contents
1. [Introduction](#introduction)
2. [Prerequisites](#prerequisites)
3. [Understanding PCI and lspci](#understanding-pci-and-lspci)
4. [Basic lspci Usage](#basic-lspci-usage)
5. [Advanced lspci Options](#advanced-lspci-options)
6. [Practical Examples and Use Cases](#practical-examples-and-use-cases)
7. [Output Interpretation](#output-interpretation)
8. [Troubleshooting Common Issues](#troubleshooting-common-issues)
9. [Best Practices and Tips](#best-practices-and-tips)
10. [Related Tools and Commands](#related-tools-and-commands)
11. [Conclusion](#conclusion)
Introduction
The `lspci` command is an essential tool for Linux system administrators, hardware enthusiasts, and developers who need to examine the Peripheral Component Interconnect (PCI) devices installed on their systems. This comprehensive guide will teach you everything you need to know about using `lspci` to view, analyze, and troubleshoot PCI devices on Linux systems.
Whether you're diagnosing hardware issues, verifying device compatibility, checking driver support, or simply inventorying your system's hardware components, `lspci` provides detailed information about all PCI devices connected to your system. This article covers basic usage, advanced options, practical examples, and troubleshooting techniques to help you master this powerful command-line tool.
Prerequisites
Before diving into `lspci` usage, ensure you have the following:
System Requirements
- A Linux-based operating system (Ubuntu, CentOS, RHEL, Debian, Fedora, etc.)
- Terminal or command-line access
- Basic familiarity with Linux command-line interface
Required Packages
The `lspci` command is part of the `pciutils` package, which is typically pre-installed on most Linux distributions. If it's not available, install it using your distribution's package manager:
Ubuntu/Debian:
```bash
sudo apt update
sudo apt install pciutils
```
CentOS/RHEL/Fedora:
```bash
sudo yum install pciutils
or for newer versions
sudo dnf install pciutils
```
Arch Linux:
```bash
sudo pacman -S pciutils
```
Permissions
Most `lspci` functions work with regular user privileges, but some advanced features require root access for complete information display.
Understanding PCI and lspci
What is PCI?
Peripheral Component Interconnect (PCI) is a standard for connecting hardware devices to a computer's motherboard. Modern systems use various PCI standards including:
- PCI Express (PCIe) - The current standard for high-speed connections
- Legacy PCI - Older parallel bus standard
- PCI-X - Extended PCI for server applications
What is lspci?
The `lspci` command lists all PCI devices detected by the Linux kernel. It reads information from the `/proc/bus/pci/` directory or `/sys/bus/pci/` filesystem, depending on your kernel version, and displays detailed information about each device including:
- Device identification numbers
- Vendor and device names
- Device classes and functions
- Memory addresses and IRQ assignments
- Driver information
- Capabilities and features
Basic lspci Usage
Simple Device Listing
The most basic `lspci` command displays a simple list of all PCI devices:
```bash
lspci
```
Example output:
```
00:00.0 Host bridge: Intel Corporation 8th Gen Core Processor Host Bridge/DRAM Registers (rev 07)
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07)
00:14.0 USB controller: Intel Corporation Sunrise Point-LP USB 3.0 xHCI Controller (rev 21)
00:16.0 Communication controller: Intel Corporation Sunrise Point-LP CSME HECI #1 (rev 21)
00:17.0 SATA controller: Intel Corporation Sunrise Point-LP SATA Controller [AHCI mode] (rev 21)
00:1c.0 PCI bridge: Intel Corporation Sunrise Point-LP PCI Express Root Port #1 (rev f1)
00:1f.0 ISA bridge: Intel Corporation Sunrise Point-LP LPC Controller (rev 21)
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)
00:1f.4 SMBus: Intel Corporation Sunrise Point-LP SMBus (rev 21)
02:00.0 Network controller: Intel Corporation Wireless-AC 9560 [Jefferson Peak] (rev 10)
```
Understanding the Output Format
Each line in the basic output follows this format:
```
[bus]:[device].[function] [device class]: [vendor] [device name] (rev [revision])
```
- Bus: PCI bus number (hexadecimal)
- Device: Device number on the bus (hexadecimal)
- Function: Function number (hexadecimal)
- Device class: Type of device (VGA controller, Network controller, etc.)
- Vendor: Manufacturer name
- Device name: Specific device model
- Revision: Hardware revision number
Verbose Output
For more detailed information, use the verbose flag:
```bash
lspci -v
```
This displays additional details including:
- Memory addresses
- IRQ assignments
- Kernel drivers in use
- Kernel modules
- Device capabilities
Example verbose output:
```
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07) (prog-if 00 [VGA controller])
Subsystem: Lenovo ThinkPad X1 Carbon 6th Gen
Flags: bus master, fast devsel, latency 0, IRQ 16
Memory at eb000000 (64-bit, non-prefetchable) [size=16M]
Memory at 80000000 (64-bit, prefetchable) [size=256M]
I/O ports at e000 [size=64]
Expansion ROM at 000c0000 [virtual] [disabled] [size=128K]
Capabilities:
Kernel driver in use: i915
Kernel modules: i915
```
Advanced lspci Options
Displaying Numeric IDs
To show vendor and device IDs in hexadecimal format:
```bash
lspci -n
```
Example output:
```
00:00.0 0600: 8086:3e34 (rev 07)
00:02.0 0300: 8086:3ea0 (rev 07)
00:14.0 0c03: 8086:9d2f (rev 21)
```
Combining Verbose and Numeric
Show both descriptive names and numeric IDs:
```bash
lspci -vn
```
Extra Verbose Output
For maximum detail, including all available information:
```bash
lspci -vv
```
This shows additional capabilities, power management features, and more technical details.
Tree View
Display devices in a tree format showing the PCI bus hierarchy:
```bash
lspci -t
```
Example output:
```
-[0000:00]-+-00.0
+-02.0
+-14.0
+-16.0
+-17.0
+-1c.0-[01]--
+-1c.4-[02]----00.0
+-1f.0
+-1f.3
\-1f.4
```
Verbose Tree View
Combine tree view with device names:
```bash
lspci -tv
```
Machine-Readable Output
For scripting purposes, use machine-readable format:
```bash
lspci -m
```
Example output:
```
00:00.0 "Host bridge" "Intel Corporation" "8th Gen Core Processor Host Bridge/DRAM Registers" -r07 "Lenovo" "ThinkPad X1 Carbon 6th Gen"
00:02.0 "VGA compatible controller" "Intel Corporation" "UHD Graphics 620" -r07 "Lenovo" "ThinkPad X1 Carbon 6th Gen"
```
Practical Examples and Use Cases
Finding Specific Device Types
Network Controllers
To find all network devices:
```bash
lspci | grep -i network
```
or
```bash
lspci | grep -i ethernet
```
Graphics Cards
To identify graphics hardware:
```bash
lspci | grep -i vga
```
or for more comprehensive graphics device detection:
```bash
lspci | grep -i "vga\|3d\|display"
```
USB Controllers
To list USB controllers:
```bash
lspci | grep -i usb
```
Storage Controllers
To find storage-related devices:
```bash
lspci | grep -i "sata\|ide\|scsi\|storage"
```
Examining Specific Devices
By Bus Address
To examine a specific device using its bus address:
```bash
lspci -v -s 00:02.0
```
This shows verbose information for the device at bus 00, device 02, function 0.
By Vendor ID
To find devices from a specific vendor (e.g., Intel - vendor ID 8086):
```bash
lspci -d 8086:
```
By Device Class
To show only devices of a specific class (e.g., network controllers - class 02):
```bash
lspci -d ::02
```
Hardware Inventory and Documentation
Generate Complete Hardware Report
Create a comprehensive hardware inventory:
```bash
lspci -vv > hardware_inventory.txt
```
Extract Vendor Information
List all unique vendors in your system:
```bash
lspci | cut -d: -f3 | cut -d' ' -f2-3 | sort | uniq
```
Check Driver Usage
See which kernel drivers are in use:
```bash
lspci -k
```
This shows kernel driver and module information for each device.
Troubleshooting Hardware Issues
Verify Device Detection
Check if a specific device is detected:
```bash
lspci | grep -i "device_name"
```
Compare Before and After
When troubleshooting hardware changes:
```bash
Before changes
lspci > before.txt
After changes
lspci > after.txt
Compare
diff before.txt after.txt
```
Check Device Capabilities
Examine advanced features of a device:
```bash
lspci -vv -s 00:02.0 | grep -A 20 "Capabilities:"
```
Output Interpretation
Understanding Device Classes
Common PCI device classes include:
| Class Code | Description | Examples |
|------------|-------------|----------|
| 01 | Mass storage controller | SATA, IDE, SCSI controllers |
| 02 | Network controller | Ethernet, WiFi adapters |
| 03 | Display controller | VGA, 3D graphics cards |
| 04 | Multimedia controller | Audio, video devices |
| 06 | Bridge device | PCI-to-PCI bridges |
| 0C | Serial bus controller | USB, FireWire controllers |
Memory and I/O Information
When examining verbose output, you'll see memory and I/O assignments:
```
Memory at eb000000 (64-bit, non-prefetchable) [size=16M]
Memory at 80000000 (64-bit, prefetchable) [size=256M]
I/O ports at e000 [size=64]
```
- Memory addresses: Physical memory ranges assigned to the device
- Prefetchable: Memory that can be cached for better performance
- I/O ports: Input/output port addresses for device communication
Capability Flags
Device capabilities indicate supported features:
- MSI: Message Signaled Interrupts
- MSI-X: Extended Message Signaled Interrupts
- PM: Power Management
- PCIe: PCI Express specific features
- AER: Advanced Error Reporting
Troubleshooting Common Issues
lspci Command Not Found
Problem: `bash: lspci: command not found`
Solution: Install the pciutils package:
```bash
Ubuntu/Debian
sudo apt install pciutils
CentOS/RHEL
sudo yum install pciutils
Fedora
sudo dnf install pciutils
```
Permission Denied for Detailed Information
Problem: Some information shows "access denied" or is incomplete
Solution: Run with sudo for complete access:
```bash
sudo lspci -vv
```
Device Not Showing Up
Problem: Expected device doesn't appear in lspci output
Possible causes and solutions:
1. Device not properly connected
- Check physical connections
- Ensure device is properly seated
2. Device not powered
- Verify power connections for PCIe devices
- Check if device requires external power
3. BIOS/UEFI settings
- Enable the PCI slot in BIOS/UEFI
- Check for disabled onboard devices
4. Kernel support
- Update kernel to latest version
- Check if device requires specific kernel modules
Outdated Device Names
Problem: Devices show as "Unknown device" or with generic names
Solution: Update the PCI ID database:
```bash
sudo update-pciids
```
This downloads the latest PCI ID database from the internet.
Incomplete Information Display
Problem: Some fields show incomplete or missing information
Solutions:
1. Use verbose mode:
```bash
lspci -vv
```
2. Run as root:
```bash
sudo lspci -vv
```
3. Check kernel modules:
```bash
lspci -k
```
Best Practices and Tips
Regular Hardware Monitoring
1. Create baseline inventories: Document your system's PCI devices when first setting up
2. Schedule regular checks: Include lspci in system monitoring scripts
3. Monitor driver changes: Track kernel driver assignments over time
Scripting with lspci
Extract Specific Information
Create scripts to extract specific hardware information:
```bash
#!/bin/bash
Script to check graphics hardware
echo "Graphics Hardware Information:"
echo "============================="
lspci -v | grep -A 10 -i vga
```
Hardware Compatibility Checking
```bash
#!/bin/bash
Check for specific vendor devices
VENDOR_ID="8086" # Intel
echo "Intel devices found:"
lspci -d ${VENDOR_ID}: | wc -l
```
Performance Considerations
1. Use specific queries: Instead of parsing full lspci output, use specific filters
2. Cache results: For repeated queries, cache lspci output temporarily
3. Combine with other tools: Use with `dmesg`, `lsmod`, and `/proc` filesystem
Documentation and Reporting
Creating Hardware Reports
```bash
#!/bin/bash
Comprehensive hardware report
DATE=$(date +%Y%m%d_%H%M%S)
REPORT="hardware_report_${DATE}.txt"
echo "Hardware Report - $(date)" > $REPORT
echo "================================" >> $REPORT
echo "" >> $REPORT
echo "PCI Devices Summary:" >> $REPORT
lspci >> $REPORT
echo "" >> $REPORT
echo "Detailed Device Information:" >> $REPORT
lspci -vv >> $REPORT
echo "Report saved to: $REPORT"
```
Security Considerations
1. Sensitive information: Be aware that lspci output may contain system-specific information
2. Log analysis: Include lspci output in security audits to detect unauthorized hardware changes
3. Access control: Limit access to detailed hardware information in multi-user environments
Related Tools and Commands
Complementary Commands
lsusb
List USB devices:
```bash
lsusb
```
lscpu
Display CPU information:
```bash
lscpu
```
lsblk
List block devices:
```bash
lsblk
```
dmidecode
Display DMI/SMBIOS information:
```bash
sudo dmidecode
```
hwinfo
Comprehensive hardware detection (if available):
```bash
hwinfo --pci
```
System Files and Directories
/proc/bus/pci/
Legacy interface for PCI information:
```bash
ls -la /proc/bus/pci/
```
/sys/bus/pci/
Modern sysfs interface:
```bash
ls -la /sys/bus/pci/devices/
```
/usr/share/misc/pci.ids
PCI ID database file:
```bash
head -20 /usr/share/misc/pci.ids
```
Integration with Other Tools
Combining with grep and awk
Extract vendor IDs:
```bash
lspci -n | awk '{print $3}' | cut -d: -f1 | sort | uniq
```
Find devices by class:
```bash
lspci | awk -F: '/Network controller/ {print $1}'
```
Using with system monitoring tools
Integrate with monitoring scripts:
```bash
Check for new devices
CURRENT=$(lspci | wc -l)
if [ $CURRENT -ne $EXPECTED ]; then
echo "Hardware change detected!"
fi
```
Conclusion
The `lspci` command is an indispensable tool for Linux system administrators and users who need to understand and manage their system's PCI hardware. This comprehensive guide has covered everything from basic usage to advanced troubleshooting techniques, providing you with the knowledge needed to effectively use `lspci` in various scenarios.
Key Takeaways
1. Basic Usage: Use `lspci` for quick hardware overviews and `lspci -v` for detailed information
2. Filtering: Combine lspci with grep and other tools for specific device queries
3. Troubleshooting: Use verbose modes and root privileges for complete hardware analysis
4. Scripting: Integrate lspci into automation scripts for hardware monitoring and reporting
5. Maintenance: Keep PCI ID databases updated for accurate device identification
Next Steps
To further enhance your hardware management skills:
1. Explore related commands: Learn `lsusb`, `lscpu`, and `dmidecode` for comprehensive hardware analysis
2. Study PCI architecture: Understand PCI Express lanes, bandwidth, and device communication
3. Practice scripting: Create custom hardware monitoring and reporting scripts
4. Learn driver management: Understand how to manage and troubleshoot device drivers
5. Explore advanced topics: Study PCI passthrough for virtualization and hardware optimization
Additional Resources
- PCI-SIG Official Documentation: Learn about PCI standards and specifications
- Linux Kernel Documentation: Understand how Linux handles PCI devices
- Distribution-specific guides: Explore your Linux distribution's hardware management tools
- Community forums: Participate in Linux hardware communities for troubleshooting support
By mastering `lspci` and understanding PCI device management, you'll be better equipped to handle hardware-related tasks, troubleshoot system issues, and maintain robust Linux systems. Whether you're managing servers, workstations, or embedded systems, the knowledge gained from this guide will serve as a solid foundation for effective hardware administration.