Prerequisites

hardware basic knowledge

What are Linux hardware information commands?

Linux hardware information commands provide system administrators with powerful utilities to discover, analyze, and manage physical devices without opening the computer case. The primary tools include lshw for comprehensive hardware inventories, lspci for PCI devices, lsusb for USB peripherals, lscpu for processor details, dmidecode for BIOS/firmware data, and lsblk for storage devices. These commands deliver complete visibility into CPU specifications, memory configurations, storage controllers, network adapters, and all connected peripherals.

Quick Hardware Overview Command:

sudo lshw -short

Expected Output:

H/W path           Device      Class          Description
=========================================================
                               system         Dell Inc. PowerEdge R740
/0                             bus            0H4RMC
/0/0                           memory         64GiB System Memory
/0/1                           processor      Intel(R) Xeon(R) Gold 6130
/0/100/1f.2        /dev/sda    storage        C610/X99 SATA Controller
/0/2               eth0        network        Ethernet Connection I219-LM

Table of Contents


How Does lshw Display Complete Hardware Inventory?

The lshw (list hardware) command generates comprehensive hierarchical listings of system hardware components and is a must for Linux hardware information commands. Consequently, this utility probes various system buses and configuration files to build a complete device tree. Moreover, lshw extracts information from the kernel, DMI tables, and sysfs filesystem to provide detailed specifications for every component.

Basic lshw Usage

# Comprehensive hardware listing (requires root)
sudo lshw

# Brief summary format
sudo lshw -short

# Specific hardware class
sudo lshw -class processor
sudo lshw -class memory
sudo lshw -class disk
sudo lshw -class network

# Output formats
sudo lshw -html > hardware-report.html
sudo lshw -xml > hardware-report.xml
sudo lshw -json > hardware-report.json

Understanding lshw Output Structure

The hierarchical output organizes hardware into logical groups:

sudo lshw -short

Sample Output Breakdown:

H/W path        Device     Class          Description
=======================================================
                           system         ProLiant DL380 Gen10
/0                         bus            ProLiant DL380 Gen10 System Board
/0/0                       memory         96GiB System Memory
/0/0/0                     memory         32GiB DIMM DDR4 Synchronous 2933 MHz
/0/0/1                     memory         32GiB DIMM DDR4 Synchronous 2933 MHz
/0/0/2                     memory         32GiB DIMM DDR4 Synchronous 2933 MHz
/0/1                       processor      Intel Xeon Gold 6248R
/0/1/2                     memory         1280KiB L1 cache
/0/1/3                     memory         24MiB L2 cache
/0/1/4                     memory         35.75MiB L3 cache
/0/100          /dev/sda   storage        MR9361-8i
/0/2            eth0       network        I350 Gigabit Network Connection

Filtering Hardware Classes

Therefore, targeting specific hardware categories improves efficiency:

# Show only network interfaces
sudo lshw -class network

# Display storage controllers
sudo lshw -class storage

# List all memory modules
sudo lshw -class memory

# Show PCI bridges
sudo lshw -class bridge

# Display multimedia devices
sudo lshw -class multimedia

Advanced lshw Options

# Disable tests (faster execution)
sudo lshw -disable test

# Show bus information
sudo lshw -businfo

# Sanitize output (remove sensitive serial numbers)
sudo lshw -sanitize

# Enable/disable specific tests
sudo lshw -enable dmi,memory -disable usb,pci

Practical Use Cases:

  • Hardware inventory documentation
  • System specification verification
  • Pre-purchase hardware validation
  • Capacity planning assessments
  • Warranty and support ticket preparation

Authoritative Reference: lshw Official Documentation


What Information Does lspci Reveal About PCI Devices?

The lspci utility displays detailed information about all PCI buses and connected devices. Furthermore, this command proves invaluable for identifying graphics cards, network adapters, storage controllers, and other expansion cards. Subsequently, understanding PCI device information assists in driver troubleshooting and hardware compatibility verification.

Basic lspci Commands

# List all PCI devices
lspci

# Verbose output (single -v)
lspci -v

# Very verbose (double -v)
lspci -vv

# Extremely verbose (triple -v)
lspci -vvv

# Numeric IDs instead of names
lspci -nn

# Tree format showing relationships
lspci -tv

Sample PCI Device Listing

lspci

Typical Output:

00:00.0 Host bridge: Intel Corporation 8th Gen Core Processor Host Bridge
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630
00:14.0 USB controller: Intel Corporation Sunrise Point-LP USB 3.0 xHCI Controller
00:16.0 Communication controller: Intel Corporation Sunrise Point-LP CSME HECI
00:17.0 SATA controller: Intel Corporation Sunrise Point-LP SATA Controller
00:1c.0 PCI bridge: Intel Corporation Sunrise Point-LP PCI Express Root Port
00:1f.0 ISA bridge: Intel Corporation Intel 200 Series PCH LPC Controller
00:1f.2 Memory controller: Intel Corporation Sunrise Point-LP PMC
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio
00:1f.4 SMBus: Intel Corporation Sunrise Point-LP SMBus
01:00.0 Ethernet controller: Intel Corporation I211 Gigabit Network Connection
02:00.0 Network controller: Intel Corporation Wireless 8265 / 8275

Detailed Device Information

# Show kernel drivers and modules
lspci -k

# Display specific device details
lspci -s 00:02.0 -vvv

# Show device IDs in both numeric and text
lspci -nn | grep VGA

Example Detailed Output:

lspci -vvv -s 01:00.0
01:00.0 Ethernet controller: Intel Corporation I211 Gigabit Network Connection (rev 03)
        Subsystem: ASUSTeK Computer Inc. Device 85c3
        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: 0
        Interrupt: pin A routed to IRQ 16
        Region 0: Memory at df100000 (32-bit, non-prefetchable) [size=128K]
        Region 2: I/O ports at d000 [size=32]
        Region 3: Memory at df120000 (32-bit, non-prefetchable) [size=16K]
        Capabilities: [40] Power Management version 3
        Capabilities: [50] MSI: Enable+ Count=1/1 Maskable+ 64bit+
        Capabilities: [70] MSI-X: Enable- Count=5 Masked-
        Capabilities: [a0] Express Endpoint, MSI 00
        Kernel driver in use: igb
        Kernel modules: igb

Identifying Hardware by Vendor and Device ID

# Find specific vendors (Intel example)
lspci -d 8086:

# Find network controllers
lspci | grep -i network

# Find VGA/graphics devices
lspci | grep -i vga

# Find SATA controllers
lspci | grep -i sata

# Show only Ethernet controllers
lspci | grep -i ethernet

PCI Device Class Codes

Class CodeDevice TypeExamples
00Pre-2.0 deviceLegacy hardware
01Mass storageSATA, SCSI, NVMe
02Network controllerEthernet, WiFi
03Display controllerVGA, GPU
04MultimediaAudio, video capture
06BridgePCI-to-PCI, ISA bridge
0cSerial busUSB, FireWire
0dWirelessBluetooth, 802.11

Authoritative Reference: PCI-SIG Specifications


How to List USB Devices with lsusb?

The lsusb command displays information about USB buses and connected devices. Additionally, this tool identifies keyboards, mice, external storage, webcams, printers, and other USB peripherals. Therefore, lsusb becomes essential when troubleshooting USB device recognition or verifying driver compatibility.

Basic lsusb Usage

# List all USB devices
lsusb

# Verbose output
lsusb -v

# Show USB device tree
lsusb -t

# Display specific device details
lsusb -d vendor:product

# Show speeds and bandwidth
lsusb -t

Understanding lsusb Output

lsusb

Sample Output:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 005: ID 8087:0a2b Intel Corp. Bluetooth wireless interface
Bus 001 Device 002: ID 0c45:6713 Microdia Integrated_Webcam_HD
Bus 001 Device 006: ID 0781:5581 SanDisk Corp. Ultra USB 3.0
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Output Breakdown:

  • Bus 002 – USB bus number
  • Device 001 – Device number on bus
  • ID 1d6b:0003 – Vendor:Product ID
  • Linux Foundation 3.0 root hub – Device description

Detailed USB Device Information

# Verbose details for specific device
sudo lsusb -v -d 0781:5581

# Show all descriptors
sudo lsusb -v -s 001:006

USB Device Tree Structure

lsusb -t

Tree Output:

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 10000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
    |__ Port 3: Dev 2, If 0, Class=Video, Driver=uvcvideo, 480M
    |__ Port 3: Dev 2, If 1, Class=Video, Driver=uvcvideo, 480M
    |__ Port 5: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 480M
    |__ Port 7: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 1: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 10: Dev 6, If 0, Class=Wireless, Driver=btusb, 12M
    |__ Port 10: Dev 6, If 1, Class=Wireless, Driver=btusb, 12M

Finding USB Device Details by Vendor

# List Logitech devices
lsusb -d 046d:

# Find all storage devices
lsusb -v | grep -i "mass storage"

# Show vendor and product names
lsusb | grep -i sandisk
lsusb | grep -i intel
lsusb | grep -i realtek

USB Speed Classification

USB VersionSpeedDesignationCommon Use
USB 1.01.5 MbpsLow SpeedKeyboards, mice
USB 1.112 MbpsFull SpeedAudio devices
USB 2.0480 MbpsHigh SpeedExternal drives
USB 3.05 GbpsSuperSpeedFast storage
USB 3.110 GbpsSuperSpeed+NVMe drives
USB 3.220 GbpsSuperSpeed++High-bandwidth
USB440 GbpsUSB4Thunderbolt alt mode

Authoritative Reference: USB Implementers Forum


What CPU Details Can lscpu Provide?

The lscpu command gathers CPU architecture information from sysfs and /proc/cpuinfo. Moreover, this utility displays processor specifications including cores, threads, cache sizes, virtualization support, and CPU flags. Consequently, system administrators rely on lscpu for capacity planning and performance optimization.

Basic CPU Information

# Display CPU details
lscpu

# Output in parseable format
lscpu -p

# JSON output format
lscpu -J

# Extended CPU information
lscpu -e

Sample lscpu Output

lscpu

Typical Output:

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  16
  On-line CPU(s) list:   0-15
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz
    CPU family:          6
    Model:               85
    Thread(s) per core:  2
    Core(s) per socket:  8
    Socket(s):           1
    Stepping:            7
    CPU max MHz:         4000.0000
    CPU min MHz:         1200.0000
    BogoMIPS:            6000.00
Virtualization features:
  Virtualization:        VT-x
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):
  L1d:                   256 KiB (8 instances)
  L1i:                   256 KiB (8 instances)
  L2:                    8 MiB (8 instances)
  L3:                    35.75 MiB (1 instance)
NUMA:
  NUMA node(s):          1
  NUMA node0 CPU(s):     0-15
Vulnerabilities:
  Itlb multihit:         KVM: Mitigation: VMX disabled
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Mitigation; Clear CPU buffers
  Retbleed:              Mitigation; Enhanced IBRS
  Spec rstack overflow:  Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled
  Spectre v1:            Mitigation; usercopy/swapgs barriers
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional
  Srbds:                 Not affected
  Tsx async abort:       Mitigation; TSX disabled
Flags:                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
                         mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2
                         ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc
                         art arch_perfmon pebs bts rep_good nopl xtopology
                         nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq
                         dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16
                         xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt
                         tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm
                         3dnowprefetch cpuid_fault epb cat_l3 cdp_l3
                         invpcid_single intel_ppin ssbd mba ibrs ibpb stibp
                         ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid
                         ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms
                         invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx
                         smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl
                         xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc
                         cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku
                         ospke avx512_vnni md_clear flush_l1d arch_capabilities

Key CPU Metrics Explained

# Check CPU count
nproc

# Display only online CPUs
lscpu | grep "On-line CPU"

# Show CPU frequency
lscpu | grep MHz

# Check virtualization support
lscpu | grep Virtualization

# View cache information
lscpu | grep cache

Understanding CPU Topology

Socket β†’ Core β†’ Thread Hierarchy:

# Calculate total processing units
# Sockets Γ— Cores per socket Γ— Threads per core = Total CPUs
# Example: 1 Γ— 8 Γ— 2 = 16 CPUs

CPU Flag Importance

FlagFeaturePurpose
vmxIntel VT-xHardware virtualization
svmAMD-VAMD virtualization
aesAES-NIHardware AES encryption
avxAVX instructionsVector operations
sse4_2SSE 4.2Streaming SIMD extensions
rdrandRDRANDHardware RNG
lmLong mode64-bit support

Alternative CPU Information Sources

# Direct from /proc/cpuinfo
cat /proc/cpuinfo

# CPU model name only
grep "model name" /proc/cpuinfo | uniq

# Count physical processors
grep "physical id" /proc/cpuinfo | sort -u | wc -l

# Count cores per processor
grep "cpu cores" /proc/cpuinfo | uniq

Authoritative Reference: Linux Kernel CPU Documentation


How Does dmidecode Extract BIOS and Firmware Data?

The dmidecode utility reads DMI (Desktop Management Interface) tables from system firmware to display hardware configuration. Furthermore, this command accesses SMBIOS (System Management BIOS) data containing manufacturer information, serial numbers, BIOS versions, and detailed component specifications. Therefore, dmidecode proves essential for inventory management and warranty verification.

Basic dmidecode Usage

# Display all DMI information (requires root)
sudo dmidecode

# Brief summary
sudo dmidecode --type bios
sudo dmidecode --type system
sudo dmidecode --type processor
sudo dmidecode --type memory

# Shorthand type codes
sudo dmidecode -t 0    # BIOS information
sudo dmidecode -t 1    # System information
sudo dmidecode -t 4    # Processor information
sudo dmidecode -t 17   # Memory device details

DMI Type Codes Reference

TypeCategoryDescription
0BIOSVendor, version, release date
1SystemManufacturer, product, serial
2BaseboardMotherboard details
4ProcessorCPU specifications
16Physical Memory ArrayTotal memory capacity
17Memory DeviceIndividual RAM module
32System BootBoot status

Extracting Specific Hardware Details

BIOS Information

sudo dmidecode -t bios

Sample Output:

# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.

Handle 0x0000, DMI type 0, 26 bytes
BIOS Information
        Vendor: American Megatrends Inc.
        Version: 2.20
        Release Date: 04/15/2023
        Address: 0xF0000
        Runtime Size: 64 kB
        ROM Size: 16 MB
        Characteristics:
                PCI is supported
                BIOS is upgradeable
                BIOS shadowing is allowed
                Boot from CD is supported
                Selectable boot is supported
                BIOS ROM is socketed
                EDD is supported
                ACPI is supported
                USB legacy is supported
                BIOS boot specification is supported
                Targeted content distribution is supported
                UEFI is supported
        BIOS Revision: 5.17

System Information

sudo dmidecode -t system

Sample Output:

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: Dell Inc.
        Product Name: PowerEdge R740
        Version: Not Specified
        Serial Number: 4ZGF6T2
        UUID: 4c4c4544-005a-4710-8046-b8c04f365432
        Wake-up Type: Power Switch
        SKU Number: 0704
        Family: PowerEdge

Memory Configuration

sudo dmidecode -t memory

Sample Memory Module Output:

Handle 0x0046, DMI type 17, 84 bytes
Memory Device
        Array Handle: 0x0043
        Error Information Handle: Not Provided
        Total Width: 72 bits
        Data Width: 64 bits
        Size: 32 GB
        Form Factor: DIMM
        Set: None
        Locator: DIMM_A1
        Bank Locator: NODE 0 CHANNEL 0 DIMM 0
        Type: DDR4
        Type Detail: Synchronous Registered (Buffered)
        Speed: 2933 MT/s
        Manufacturer: Samsung
        Serial Number: 21EA8C5D
        Asset Tag: 01234567
        Part Number: M393A4K40CB2-CVF
        Rank: 2
        Configured Memory Speed: 2933 MT/s
        Minimum Voltage: 1.2 V
        Maximum Voltage: 1.2 V
        Configured Voltage: 1.2 V

Practical dmidecode Queries

# Show system serial number
sudo dmidecode -s system-serial-number

# Display BIOS version
sudo dmidecode -s bios-version

# Get system manufacturer
sudo dmidecode -s system-manufacturer

# Show baseboard product name
sudo dmidecode -s baseboard-product-name

# Count memory slots
sudo dmidecode -t memory | grep -c "Memory Device"

# Check maximum memory capacity
sudo dmidecode -t 16 | grep "Maximum Capacity"

# List all populated memory slots
sudo dmidecode -t 17 | grep -E "Size|Locator" | grep -v "No Module"

Memory Slot Analysis

# Create memory inventory report
sudo dmidecode -t memory | awk '
  /Memory Device$/ {device=1}
  /^[[:space:]]*$/ {device=0}
  device && /Size:/ {size=$2}
  device && /Locator:/ {loc=$2}
  device && /Speed:/ {speed=$2" "$3}
  device && /Type:/ && !/Type Detail/ {type=$2}
  device && /Manufacturer:/ {mfr=$2; print loc,size,type,speed,mfr}
'

Authoritative Reference: DMTF SMBIOS Specification


How to Check Block Devices with lsblk?

The lsblk command lists information about block devices including disks, partitions, and logical volumes. Additionally, this tool displays device hierarchies, mount points, filesystem types, and storage capacities. Consequently, lsblk becomes indispensable for storage management and troubleshooting.

Basic lsblk Usage

# List all block devices
lsblk

# Include filesystem information
lsblk -f

# Show extended columns
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID

# Display in JSON format
lsblk -J

# Show device paths
lsblk -p

# Tree view with all information
lsblk -a

Sample lsblk Output

lsblk

Typical Output:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 465.8G  0 disk 
β”œβ”€sda1        8:1    0   512M  0 part /boot/efi
β”œβ”€sda2        8:2    0 457.3G  0 part /
└─sda3        8:3    0     8G  0 part [SWAP]
sdb           8:16   0 931.5G  0 disk 
└─sdb1        8:17   0 931.5G  0 part /data
sr0          11:0    1  1024M  0 rom  
nvme0n1     259:0    0 238.5G  0 disk 
β”œβ”€nvme0n1p1 259:1    0   100M  0 part 
β”œβ”€nvme0n1p2 259:2    0    16M  0 part 
└─nvme0n1p3 259:3    0 238.3G  0 part 

Understanding lsblk Column Headers

ColumnDescriptionExample Value
NAMEDevice namesda, sdb1, nvme0n1
MAJ:MINMajor:Minor numbers8:0, 8:1
RMRemovable device0=no, 1=yes
SIZEDevice size465.8G
RORead-only flag0=rw, 1=ro
TYPEDevice typedisk, part, lvm
MOUNTPOINTMount location/, /home, /boot

Filesystem Information with lsblk

lsblk -f

Output with Filesystem Details:

NAME   FSTYPE FSVER LABEL       UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda                                                                                   
β”œβ”€sda1 vfat   FAT32 EFI         1A2B-3C4D                             505.8M     1% /boot/efi
β”œβ”€sda2 ext4   1.0   root        a1b2c3d4-e5f6-7890-1234-567890abcdef  345.2G    22% /
└─sda3 swap   1     swap        f1e2d3c4-b5a6-9078-5634-210987654321                [SWAP]
sdb                                                                                   
└─sdb1 ext4   1.0   data-drive  9876fedc-ba09-8765-4321-0fedcba98765  678.4G    27% /data
nvme0n1                                                                               
β”œβ”€nvme0n1p1 ntfs                Windows     4D6A8B2C1E5F3A09
β”œβ”€nvme0n1p2 
└─nvme0n1p3 ntfs                System      E8F7D6C5B4A39281

Advanced lsblk Queries

# Show only specific columns
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID

# Exclude loop devices
lsblk -e 7

# Show device topology
lsblk -t

# Display all devices including empty ones
lsblk -a

# Sort by size
lsblk -o NAME,SIZE --sort SIZE

# Show device paths
lsblk -p -o NAME,SIZE,TYPE,MOUNTPOINT

Identifying Storage Device Types

# List only disks (no partitions)
lsblk -d

# Show NVMe devices
lsblk | grep nvme

# List SATA/SCSI devices
lsblk | grep sd

# Find mounted filesystems
lsblk | grep -v "^loop" | awk '$7 != "" {print}'

# Check for LVM volumes
lsblk | grep lvm

Device Size and Usage Analysis

# Show sizes in bytes
lsblk -b

# Display human-readable sizes
lsblk -h

# Check partition alignment
lsblk -t -o NAME,ALIGNMENT,MIN-IO,OPT-IO

# View disk scheduler information
lsblk -o NAME,SIZE,SCHED

# Show disk model information
lsblk -o NAME,SIZE,MODEL,SERIAL

Authoritative Reference: Linux Block Device Documentation


Device Management with udev and udevadm

The udev device manager dynamically creates and removes device nodes in /dev as hardware appears and disappears. Moreover, udev executes custom rules to handle device events, set permissions, and create symbolic links. Subsequently, the udevadm utility provides tools for querying devices, monitoring events, and testing rules.

Understanding udev Architecture

Udev operates through these components:

  • udevd daemon – Listens for kernel uevents
  • Rules files – Define device handling policies
  • Helper programs – Execute custom actions
  • /dev management – Creates device nodes dynamically

Basic udevadm Commands

# Query device information
udevadm info /dev/sda

# Monitor device events in real-time
udevadm monitor

# Trigger device event
sudo udevadm trigger

# Reload udev rules
sudo udevadm control --reload-rules

# Test rule matching
udevadm test /sys/class/net/eth0

Monitoring Hardware Events

# Watch all device events
udevadm monitor

# Monitor only kernel events
udevadm monitor --kernel

# Monitor only udev events
udevadm monitor --udev

# Show event properties
udevadm monitor --property

# Filter by subsystem
udevadm monitor --subsystem-match=block
udevadm monitor --subsystem-match=usb
udevadm monitor --subsystem-match=net

Sample Event Output:

KERNEL[1234.567890] add      /devices/pci0000:00/0000:00:14.0/usb1/1-3 (usb)
KERNEL[1234.567910] add      /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0 (usb)
UDEV  [1234.589012] add      /devices/pci0000:00/0000:00:14.0/usb1/1-3 (usb)
UDEV  [1234.590123] add      /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0 (usb)

Querying Device Attributes

# Display all device attributes
udevadm info --query=all --name=/dev/sda

# Show device path
udevadm info --query=path --name=/dev/sda

# Display symbolic links
udevadm info --query=symlink --name=/dev/sda

# Get device properties
udevadm info --query=property --name=/dev/sda

# Show attribute walking path
udevadm info --attribute-walk --name=/dev/sda

Creating Custom udev Rules

Rules are stored in /etc/udev/rules.d/ with .rules extension. Files are processed in lexical order.

Example: Auto-mount USB drive

sudo nano /etc/udev/rules.d/99-usb-automount.rules
# Auto-mount USB storage devices
ACTION=="add", KERNEL=="sd[b-z][0-9]", SUBSYSTEM=="block", \
  ENV{ID_FS_TYPE}=="vfat|ntfs|ext4", \
  RUN+="/usr/bin/udisksctl mount -b /dev/%k"

# Set permissions for serial devices
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", \
  MODE="0666", GROUP="dialout", SYMLINK+="arduino"

Testing udev Rules

# Test rule matching for device
sudo udevadm test /sys/block/sda

# Reload rules without reboot
sudo udevadm control --reload-rules
sudo udevadm trigger

# Debug rule processing
sudo udevadm test --action=add /sys/class/net/eth0

Common udev Rule Patterns

# Match by vendor/product ID
SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b"

# Match by serial number
SUBSYSTEM=="block", ENV{ID_SERIAL}=="WD-WMAV2FU80671"

# Match by filesystem label
ENV{ID_FS_LABEL}=="backup-drive"

# Network interface naming
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1a:2b:3c:4d:5e", \
  NAME="eth0"

Authoritative Reference: udev Man Pages


Hardware Information Commands Comparison Table

Understanding which command to use for specific hardware queries improves efficiency. Therefore, this comprehensive comparison helps select the optimal tool for each scenario.

CommandScopeBest ForSpeedRoot RequiredKey Features
lshwComplete systemComprehensive inventorySlowYesHTML/XML export, hierarchical view
lspciPCI devicesGraphics, network, storage controllersFastNoDriver information, verbose details
lsusbUSB devicesPeripherals, external storageFastNoDevice tree, bandwidth info
lscpuProcessorsCPU specs, virtualizationFastNoArchitecture, cache, flags
dmidecodeFirmware/BIOSSerial numbers, warranty infoMediumYesSMBIOS data, asset tracking
lsblkBlock devicesStorage, partitions, mountsFastNoFilesystem info, topology
hwinfoAll hardwareDetailed probingVery SlowNoExhaustive details
inxiSystem summaryQuick overviewFastNoSingle-line summary
dmesgKernel logsBoot errors, driver issuesFastSometimesReal-time kernel messages
udevadmDevice managementEvent monitoring, rules testingFastSometimesDynamic device handling

Command Selection Decision Tree

For comprehensive inventory:

sudo lshw -short        # Best overall summary

Specific hardware type:

lspci -v                # PCI devices (graphics, network)
lsusb -v                # USB peripherals
lscpu                   # CPU information
dmidecode -t memory     # RAM specifications
lsblk -f                # Storage devices

For troubleshooting:

dmesg | grep -i error   # Kernel errors
udevadm monitor         # Real-time events
hwinfo --short          # Detailed probing

For quick reference:

inxi -Fxz               # Comprehensive one-liner

Monitoring Hardware Events in Real-Time

Real-time hardware monitoring helps diagnose device recognition issues, driver loading problems, and hot-plug events. Furthermore, understanding kernel messages and device events enables proactive system management.

Kernel Message Monitoring

# Display kernel ring buffer
dmesg

# Follow new messages
dmesg -w

# Show with timestamps
dmesg -T

# Filter by priority
dmesg -l err,warn

# Clear ring buffer
sudo dmesg -C

# Show only recent messages
dmesg | tail -50

Hardware-Specific dmesg Queries

# USB device messages
dmesg | grep -i usb

# SATA/disk messages
dmesg | grep -i "sd[a-z]"

# PCI device detection
dmesg | grep -i pci

# Network interface messages
dmesg | grep -i eth

# Graphics/video messages
dmesg | grep -i "vga\|drm"

# Memory errors
dmesg | grep -i "memory\|ram"

Continuous Hardware Monitoring Script

#!/bin/bash
# Monitor hardware changes continuously

echo "Monitoring hardware events - Press Ctrl+C to stop"
echo "================================================"

# Monitor udev events in one terminal
udevadm monitor --property &
UDEV_PID=$!

# Monitor kernel messages in parallel
dmesg -w &
DMESG_PID=$!

# Cleanup on exit
trap "kill $UDEV_PID $DMESG_PID 2>/dev/null; exit" SIGINT SIGTERM

wait

Analyzing Boot Hardware Detection

# View boot-time hardware detection
journalctl -b | grep -i "hardware\|device\|driver"

# Check for failed device initialization
journalctl -b -p err

# Show hardware-related systemd units
systemctl list-units | grep -i "device\|hardware"

# Analyze boot timeline for hardware delays
systemd-analyze blame | grep -i "device"

Authoritative Reference: Linux Kernel Messages Documentation


Troubleshooting Hardware Detection Issues

When hardware fails to appear or function correctly, systematic troubleshooting identifies the root cause. Moreover, understanding the detection pipeline helps isolate whether issues stem from firmware, kernel, drivers, or udev rules.

Common Hardware Detection Problems

Issue 1: Device Not Appearing in lspci/lsusb

Diagnostic Steps:

# Check if kernel sees the device
dmesg | tail -50

# Verify PCI device is detected
lspci -nn | grep -i "vendor_name"

# Check USB device recognition
lsusb -v | grep -i "device_name"

# Examine sysfs for device
ls -la /sys/bus/pci/devices/
ls -la /sys/bus/usb/devices/

# Check kernel module loading
lsmod | grep driver_name

Solutions:

# Rescan PCI bus
echo 1 | sudo tee /sys/bus/pci/rescan

# Reload USB drivers
sudo modprobe -r usb_storage
sudo modprobe usb_storage

# Check BIOS settings (virtualization, USB, etc.)
# May require reboot into firmware setup

Issue 2: Missing or Incorrect Drivers

Diagnostic Commands:

# Check loaded kernel modules
lsmod

# Find module for specific device
lspci -k

# Get module information
modinfo driver_name

# Check for driver in kernel
find /lib/modules/$(uname -r) -name "driver_name.ko"

# View driver messages
dmesg | grep driver_name

Solutions:

# Load module manually
sudo modprobe driver_name

# Blacklist conflicting driver
echo "blacklist nouveau" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf

# Update kernel and firmware
sudo apt update && sudo apt install linux-firmware  # Debian/Ubuntu
sudo dnf update kernel firmware                     # Fedora/RHEL

Issue 3: USB Device Not Mounting

Troubleshooting Steps:

# Check device detection
lsusb

# View device in block devices
lsblk

# Check kernel messages
dmesg | grep -i "sd[a-z]\|usb"

# Verify filesystem recognition
sudo blkid /dev/sdb1

# Check mount points
mount | grep sdb

# Test manual mount
sudo mkdir -p /mnt/usb
sudo mount /dev/sdb1 /mnt/usb

Common Solutions:

# Fix filesystem errors
sudo fsck /dev/sdb1

# Force filesystem type
sudo mount -t vfat /dev/sdb1 /mnt/usb

# Check file permissions
ls -la /media/username/

# Restart udev
sudo systemctl restart systemd-udevd

Issue 4: Network Card Not Detected

Diagnostic Process:

# List network interfaces
ip link show

# Check PCI network devices
lspci | grep -i network

# View network drivers
lspci -k | grep -A 3 -i network

# Check interface status
nmcli device status

# View driver messages
dmesg | grep -i eth

Resolution Steps:

# Bring interface up
sudo ip link set eth0 up

# Load network driver
sudo modprobe e1000e  # Intel example

# Install firmware if missing
sudo apt install linux-firmware-nonfree  # Debian/Ubuntu

# Reset network manager
sudo systemctl restart NetworkManager

Hardware Detection Verification Checklist

#!/bin/bash
# Hardware verification script

echo "=== Hardware Detection Report ==="
echo

echo "1. CPU Information:"
lscpu | grep "Model name\|CPU(s)\|Architecture"
echo

echo "2. Memory:"
free -h
echo

echo "3. PCI Devices:"
lspci | wc -l
echo "Total PCI devices detected"
echo

echo "4. USB Devices:"
lsusb | wc -l
echo "Total USB devices detected"
echo

echo "5. Block Devices:"
lsblk -o NAME,SIZE,TYPE
echo

echo "6. Network Interfaces:"
ip -br link show
echo

echo "7. Recent Kernel Messages (errors):"
dmesg -T -l err | tail -10
echo

echo "8. Failed systemd units:"
systemctl --failed

Authoritative Reference: Linux Hardware Compatibility Lists


FAQ: Hardware Information Questions

How do I find my system’s hardware specifications quickly?

The fastest method uses inxi for a comprehensive summary or lshw -short for hierarchical overview. Run inxi -Fxz to display CPU, motherboard, memory, storage, graphics, audio, and network details in a sanitized format. Alternatively, sudo lshw -short provides manufacturer information and device hierarchies in a concise table format.

What command shows which driver is being used for a device?

Use lspci -k to display PCI devices along with their active kernel drivers and loaded modules. For example, lspci -k | grep -A 3 -i network shows network card drivers. Similarly, lsusb -t combined with lsmod reveals USB device drivers. The sysfs filesystem also provides driver information at /sys/class/device_type/device_name/driver.

How can I identify the manufacturer and model of my RAM?

Execute sudo dmidecode -t memory to extract detailed SDRAM specifications from SMBIOS tables. This command reveals manufacturer names, part numbers, serial numbers, module sizes, speeds, and physical slot locations. For a quick summary, use sudo dmidecode -t 17 | grep -E "Size|Speed|Manufacturer|Part Number" to filter essential memory module information.

Why doesn’t my USB device appear in lsusb?

Several factors cause USB detection failures including insufficient power, faulty cables, disabled USB ports in BIOS, or kernel driver issues. First, verify physical connection and try different USB ports. Check dmesg | grep -i usb for kernel messages indicating errors. Additionally, confirm USB controller appears in lspci and verify /sys/bus/usb/devices/ contains entries. Sometimes, USB 3.0 devices require USB 2.0 compatibility mode.

How do I check if my CPU supports virtualization?

Run lscpu | grep Virtualization to check for VT-x (Intel) or AMD-V (AMD) support. The output displays “VT-x” or “AMD-V” if virtualization extensions exist. Alternatively, examine CPU flags with grep -E "vmx|svm" /proc/cpuinfo where “vmx” indicates Intel VT-x and “svm” indicates AMD-V. Remember that BIOS settings may disable virtualization despite CPU support, requiring firmware configuration changes.

What’s the difference between lshw and hwinfo?

Both tools enumerate hardware, but lshw provides hierarchical device trees with bus relationships while hwinfo performs exhaustive hardware probing with more detailed technical specifications. Consequently, lshw executes faster and presents cleaner output for general inventory tasks. However, hwinfo offers deeper analysis including configuration hints and driver recommendations, making it valuable for troubleshooting complex hardware issues despite slower execution.

How can I monitor hardware changes without rebooting?

Use udevadm monitor to watch device events in real-time as hardware connects or disconnects. Additionally, dmesg -w follows kernel messages showing driver loading and device recognition. For USB-specific monitoring, combine both: udevadm monitor --subsystem-match=usb tracks USB events while watch -n1 lsusb periodically refreshes USB device listings. These approaches enable hot-plug monitoring without system interruption.

How do I find the serial number of my hard drive?

Multiple commands retrieve storage device serial numbers. Use sudo lshw -class disk for comprehensive disk information including serial numbers. Alternatively, sudo smartctl -i /dev/sda from smartmontools package displays detailed drive information. For quick serial lookup, execute sudo hdparm -I /dev/sda | grep "Serial Number" or check /dev/disk/by-id/ for symbolic links containing serial numbers.

Authoritative Reference: Linux System Administrator’s Guide


Additional Resources

Official Documentation

Linux Distribution Resources

Hardware Compatibility

Utilities and Tools

Community Support

Specifications


Conclusion

Mastering Linux hardware information commands empowers system administrators to maintain comprehensive hardware inventories, diagnose device recognition issues, and optimize system configurations. From lshw‘s hierarchical overviews to dmidecode‘s firmware details, each tool serves specific purposes in the hardware discovery ecosystem.

Moreover, understanding when to use lspci for PCI devices, lsusb for USB peripherals, lscpu for processor analysis, and lsblk for storage management creates efficient troubleshooting workflows. Additionally, mastering udevadm for device event monitoring and rule creation enables dynamic hardware management in modern Linux environments.

Key Takeaways:

  • Combine multiple commands for comprehensive hardware analysis
  • Use appropriate tools based on specific hardware subsystems
  • Monitor kernel messages and udev events for troubleshooting
  • Maintain hardware inventory documentation for capacity planning
  • Leverage output formats (JSON, XML, HTML) for automation and reporting

Next Steps:

  • Create hardware inventory scripts using these commands
  • Develop custom udev rules for automatic device configuration
  • Set up monitoring for hardware failures and changes
  • Document your system’s hardware baseline for future reference
  • Explore hardware-specific tuning based on discovered capabilities

Remember: Understanding your hardware through command-line tools provides deeper system insights than any GUI utility can offer. These commands form the foundation of professional Linux system administration.

Mark as Complete

Did you find this guide helpful? Track your progress by marking it as completed.