Linux系统硬件信息检测工具hwinfo

我们在排查系统问题时,很多时候需要确认服务器硬件信息。我发现 hwinfo 工具能够提供有序组织的硬件系统,对于问题排查,以及为客户提供运维服务时采集需要排查问题的服务器信息非常有用。

hwinfo 使用 libhd.so 系统库来搜集所有硬件的详细信息,例如BIOS, CPU, 架构, 内存, 硬盘, 分区, 摄像头, 蓝牙, CD/DVD, 键盘鼠标, 图形卡, 显示器, Modem, 扫描仪, 打印机, PCI, IDE, SCSI, 声卡, 网卡, USB 等等…

安装

  • Fedoa:

    sudo dnf install hwinfo
    
  • CentOS(需要激活EPEL):

    sudo dnf install epel-release
    sudo yum install hwinfo
    
  • debian/ubuntu:

    sudo apt install hwinfo
    
  • openSUSE:

    sudo zypper install hwinfo
    

使用

  • 可以不使用任何参数来使用 hwinfo 命令:

    sudo hwinfo
    

或者:

sudo hwinfo --all

输出信息类似如下:

...
  Processor Info: #3
    Socket: "Proc 1"
    Socket Type: 0x2b (Other)
    Socket Status: Populated
    Type: 0x03 (CPU)
    Family: 0xb3 (Xeon)
    Manufacturer: "Intel(R) Corporation"
    Version: "Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz"
    Asset Tag: "UNKNOWN"
    Processor ID: 0xbfebfbff000306f2
    Status: 0x01 (Enabled)
    Voltage: 1.6 V
    External Clock: 100 MHz
    Max. Speed: 4000 MHz
    Current Speed: 2300 MHz
    L2 Cache: #1
    L3 Cache: #2
...

上述硬件信息输出非常繁多,有可能过于庞杂,所以也有一个简单输出方式,使用参数 --short

sudo hwinfo --short

输出类似:

cpu:
                       Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz, 1200 MHz
                       Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz, 1200 MHz
...

使用hwinfo显示特定设备信息

  • 检查CPU的相信信息:

    sudo hwinfo --cpu
    

显示输出非常详细的CPU规格:

01: None 00.0: 10103 CPU                                        
  [Created at cpu.465]
  Unique ID: rdCR.j8NaKXDZtZ6
  Hardware Class: cpu
  Arch: X86-64
  Vendor: "GenuineIntel"
  Model: 6.63.2 "Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz"
  Features: 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,arch_perfmon,pebs,bts,rep_good,nopl,xtopology,nonstop_tsc,cpuid,aperfmperf,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,xsave,avx,f16c,rdrand,lahf_lm,abm,cpuid_fault,epb,invpcid_single,pti,intel_ppin,ssbd,ibrs,ibpb,stibp,tpr_shadow,vnmi,flexpriority,ept,vpid,ept_ad,fsgsbase,tsc_adjust,bmi1,avx2,smep,bmi2,erms,invpcid,cqm,xsaveopt,cqm_llc,cqm_occup_llc,dtherm,ida,arat,pln,pts,md_clear,flush_l1d
  Clock: 1200 MHz
  BogoMips: 4594.71
  Cache: 30720 kb
  Units/Processor: 32
  Config Status: cfg=new, avail=yes, need=no, active=unknown

02: None 01.0: 10103 CPU
  [Created at cpu.465]
...
  • 同样也有简略输出CPU信息参数 --short

    sudo hwinfo --short --cpu
    

输出类似:

cpu:
                       Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz, 1200 MHz
                       ...

使用hwinfo显示系统架构

  • 系统架构:

    sudo hwinfo --arch
    

显示输出:

Arch: X86_64/grub

使用hwinfo显示内存详情

  • 内存信息详情:

    sudo hwinfo --memory
    

输出:

219: PCI 00.0: 10600 Disk                                       
  [Created at block.245]
  Unique ID: wLCS.G8APaIbKzK8
  Parent ID: GBI1.Cm975qxIKm7
  SysFS ID: /class/block/nvme0n1
  SysFS BusID: nvme0
  SysFS Device Link: /devices/pci0000:00/0000:00:03.0/0000:08:00.0/nvme/nvme0
  Hardware Class: disk
  Model: "Samsung Electronics Disk"
  Vendor: pci 0x144d "Samsung Electronics Co Ltd"
  Device: pci 0xa80a 
  SubVendor: pci 0x144d "Samsung Electronics Co Ltd"
  SubDevice: pci 0xa801 
  Driver: "nvme"
  Driver Modules: "nvme"
  Device File: /dev/nvme0n1
  Device Files: /dev/nvme0n1, /dev/disk/by-id/nvme-eui.002538b911b37f97, /dev/disk/by-id/nvme-SAMSUNG_MZVL21T0HCLR-00B00_S676NF0R908202, /dev/disk/by-path/pci-0000:08:00.0-nvme-1
  Device Number: block 259:1
  Geometry (Logical): CHS 976762/64/32
  Size: 2000409264 sectors a 512 bytes
  Capacity: 953 GB (1024209543168 bytes)
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #57 (Non-Volatile memory controller)

220: IDE 300.0: 10600 Disk
  [Created at block.245]
  Unique ID: Rw8Y.3l_0qag+TnC
  Parent ID: w7Y8.AWGP+VY_LGA
  SysFS ID: /class/block/sdd
  SysFS BusID: 3:0:0:0
  SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/ata4/host3/target3:0:0/3:0:0:0
  Hardware Class: disk
  Model: "ST9500325AS"
  Device: "ST9500325AS"
  Revision: "BSM1"
  Serial ID: "5VE7X2Q7"
  Driver: "ahci", "sd"
  Driver Modules: "ahci"
  Device File: /dev/sdd
  Device Files: /dev/sdd, /dev/disk/by-id/scsi-0ATA_ST9500325AS_5VE7X2Q7, /dev/disk/by-path/pci-0000:00:1f.2-ata-4, /dev/disk/by-id/ata-ST9500325AS_5VE7X2Q7, /dev/disk/by-id/wwn-0x5000c5001eae2511, /dev/disk/by-id/scsi-35000c5001eae2511, /dev/disk/by-id/scsi-SATA_ST9500325AS_5VE7X2Q7, /dev/disk/by-id/scsi-1ATA_ST9500325AS_5VE7X2Q7
  Device Number: block 8:48-8:63
  Geometry (Logical): CHS 60801/255/63
  Size: 976773168 sectors a 512 bytes
  Capacity: 465 GB (500107862016 bytes)
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #7 (SATA controller)

...

使用hwinfo显示分区详情

  • 可以显示硬盘的分区详情:

    sudo hwinfo --partition
    

输出信息:

221: None 00.0: 11300 Partition                                 
  [Created at block.434]
  Unique ID: r_Ra.SE1wIdpsiiC
  Parent ID: Rw8Y.3l_0qag+TnC
  SysFS ID: /class/block/sdd/sdd1
  Hardware Class: partition
  Model: "Partition"
  Device File: /dev/sdd1
  Device Files: /dev/sdd1, /dev/disk/by-partuuid/1a99ca08-01, /dev/disk/by-id/ata-ST9500325AS_5VE7X2Q7-part1, /dev/disk/by-id/scsi-0ATA_ST9500325AS_5VE7X2Q7-part1, /dev/disk/by-id/scsi-1ATA_ST9500325AS_5VE7X2Q7-part1, /dev/disk/by-uuid/47D1-C570, /dev/disk/by-id/scsi-SATA_ST9500325AS_5VE7X2Q7-part1, /dev/disk/by-id/wwn-0x5000c5001eae2511-part1, /dev/disk/by-id/scsi-35000c5001eae2511-part1, /dev/disk/by-path/pci-0000:00:1f.2-ata-4-part1
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #220 (Disk)

...

使用hwinfo显示网卡详情

  • 显示网卡的详情:

    sudo hwinfo --network
    

输出信息:

226: None 00.0: 10701 Ethernet                                  
  [Created at net.126]
  Unique ID: 7iXG.ndpeucax6V1
  SysFS ID: /class/net/docker0
  Hardware Class: network interface
  Model: "Ethernet network interface"
  Driver: "bridge"
  Device File: docker0
  HW Address: 02:42:ee:c3:89:a7
  Link detected: no
  Config Status: cfg=new, avail=yes, need=no, active=unknown

227: None 02.0: 10701 Ethernet
  [Created at net.126]
  Unique ID: QTdc.ndpeucax6V1
  Parent ID: NotL.uEyeapd4E5E
  SysFS ID: /class/net/eno2
  SysFS Device Link: /devices/pci0000:00/0000:00:1c.4/0000:02:00.1
  Hardware Class: network interface
  Model: "Ethernet network interface"
  Driver: "tg3"
  Driver Modules: "tg3"
  Device File: eno2
  HW Address: 94:57:a5:5a:d9:c1
  Permanent HW Address: 94:57:a5:5a:d9:c1
  Link detected: no
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #137 (Ethernet controller)

228: None 34.0: 10701 Ethernet
  [Created at net.126]
  Unique ID: xzGl.ndpeucax6V1
  Parent ID: jbuf.tw96BiMW4x1
  SysFS ID: /class/net/eno52
  SysFS Device Link: /devices/pci0000:00/0000:00:02.2/0000:04:00.3
  Hardware Class: network interface
  Model: "Ethernet network interface"
  Driver: "igb"
  Driver Modules: "igb"
  Device File: eno52
  HW Address: 5c:b9:01:89:26:7b
  Permanent HW Address: 5c:b9:01:89:26:7b
  Link detected: no
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #54 (Ethernet controller)

...

使用hwinfo显示BIOS详情

  • 显示BIOS详情:

    sudo hwinfo --bios
    

输出信息:

01: None 00.0: 10105 BIOS
  [Created at bios.186]
  Unique ID: rdCR.lZF+r4EgHp4
  Hardware Class: bios
  BIOS Keyboard LED Status:
    Scroll Lock: off
    Num Lock: off
    Caps Lock: off
  SMBIOS Version: 2.8
  Cache Info: #0
    Designation: "L1-Cache"
    Level: L1
    State: Enabled
    Mode: 0x01 (Write Back)
    Location: 0x00 (Internal, Not Socketed)
    ECC: 0x05 (Single-bit)
    Type: 0x05 (Unified)
    Associativity: 0x07 (8-way Set-Associative)
    Max. Size: 768 kB
    Current Size: 768 kB
    Supported SRAM Types: 0x0020 (Synchronous)
    Current SRAM Type: 0x0020 (Synchronous)
  Cache Info: #1
    Designation: "L2-Cache"
    Level: L2
    State: Enabled
    Mode: 0x02 (Varies with Memory Address)
    Location: 0x00 (Internal, Not Socketed)
    ECC: 0x05 (Single-bit)
    Type: 0x05 (Unified)
    Associativity: 0x07 (8-way Set-Associative)
    Max. Size: 3072 kB
    Current Size: 3072 kB
    Supported SRAM Types: 0x0020 (Synchronous)
    Current SRAM Type: 0x0020 (Synchronous)
  Cache Info: #2
    Designation: "L3-Cache"
    Level: L3
    State: Enabled
    Mode: 0x02 (Varies with Memory Address)
    Location: 0x00 (Internal, Not Socketed)
    ECC: 0x05 (Single-bit)
    Type: 0x05 (Unified)
    Associativity: 0x0e (Other)
    Max. Size: 30720 kB
    Current Size: 30720 kB
    Supported SRAM Types: 0x0020 (Synchronous)
    Current SRAM Type: 0x0020 (Synchronous)
  Processor Info: #3
    Socket: "Proc 1"
    Socket Type: 0x2b (Other)
    Socket Status: Populated
    Type: 0x03 (CPU)
    Family: 0xb3 (Xeon)
    Manufacturer: "Intel(R) Corporation"
    Version: "Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz"
    Asset Tag: "UNKNOWN"
    Processor ID: 0xbfebfbff000306f2
...

注解

hwinfo 可以侦测所有其他硬件内容

输出硬件信息到文件

hwinfo 可以用来输出完整的系统硬件报告,也可以记录到文件中用于进一步排查和分析:

sudo hwinfo --all --log hardwareinfo.txt

或者:

sudo hwinfo --all > hardwareinfo.txt