• Linux硬件信息查询


    一、lshw和getinfo

    1、lshw 是一个能帮我们列出硬件信息的小工具,它能为我们提供内存配置、固件版本、主板配置信息、CPU版本和速度、cache信息、总线速度等。它能运行在 DMI兼容的 x86、IA-64和一些 PowerPC的平台上。目前支持 DMI (x86 and IA-64 only), OpenFirmware device tree (PowerPC only), PCI/AGP, CPUID (x86), IDE/ATA/ATAPI, PCMCIA (only tested on x86), SCSI 和 USB。

    -version       :显示 lshw的版本
    -help          :显示帮助信息
    -X             :启动图形界面
    -html          :将设备信息以 html的格式输出
    -xml           :将设备信息以 xml的格式输出
    -json          :将设备信息以 json的格式输出
    -short         :带有设置路径的简短输出(类似与 HP-UX的 ioscan输出形式)
    -businfo       :输出详细的总线信息(包含 SCSI, USB, IDE and PCI地址)
    -dump filename :将收集到的信息输出到一个SQLite数据库中
    -class class   :仅仅显示指定类型的硬件,在使用 lshw -short or lshw -businfo时我们能见到这写 class,
                     常见的有这些:system、bus、memory、processor、bridge、display、communication、
                              multimedia、network、disk、volume、powoer
    -C class       :等同与 -class class
    -enable test   :启用测试,测试项能包含这些:
                     dmi (for DMI/SMBIOS extensions)
                     device-tree (for OpenFirmware device tree)
                     spd (for memory Serial Presence Detect)
                     memory (for memory-size guessing heuristics)
                     cpuinfo (for kernel-reported CPU  detection)
                     cpuid  (for  CPU  detection)
                     pci  (for  PCI/AGP access)
                     isapnp  (for ISA PnP extensions)
                     pcmcia (for PCMCIA/PCCARD)
                     ide (for IDE/ATAPI)
                     usb (for USB devices)
                     scsi (for SCSI)
                     network (for net‐work interfaces detection)
    -disable test
    -quiet         :不现实状态
    -sanitize      :移除IP地址、序列号等敏感信息
    -numeric       :显示 PCI和USB设备的数字 ID
    它在运行的时候会都去下列文件:
    /usr/local/share/pci.ids
    /usr/share/pci.ids
    /etc/pci.ids
    /usr/share/hwdata/pci.ids  :A list of all known PCI ID's (vendors, devices, classes and subclasses).
    /proc/bus/pci/*            :Used to access the configuration of installed PCI busses and devices.
    /proc/ide/*                :Used to access the configuration of installed IDE busses and devices.
    /proc/scsi/*, /dev/sg*     :Used to access the configuration of installed SCSI devices.
    /dev/cpu/*/cpuid           :Used on x86 platforms to access CPU-specific configuration.
    /proc/device-tree/*        :Used on PowerPC platforms to access OpenFirmware configuration.
    /proc/bus/usb/*            :Used to access the configuration of installed USB busses and devices.
    /sys/*                     :Used on 2.6 kernels to access hardware/driver configuration information.
    

    显示设备列表,输出包括设备路径(path)、类别(class)以及简单描述:

    # lshw -short
    

    显示设备列表,输出包括总线信息、SCSI、USB、IDE、PCI地址等:

    # lshw -businfo 
    

    显示内存相关的硬件:

    # lshw -C memory 
    

    2、getinfo

    # getconf -a 
    LINK_MAX                           2147483647
    _POSIX_LINK_MAX                    2147483647
    MAX_CANON                          255
    _POSIX_MAX_CANON                   255
    MAX_INPUT                          255
    

    查看系统分页大小

    #getconf PAGE_SIZE
    4096
    

    查看系统位数

    #getconf LONG_BIT
    64
    

    二、查看服务器硬件信息

    (1)查看服务器型号、序列号

    $ sudo dmidecode|grep "System Information" -A9|egrep  "Manufacturer|Product|Serial"
    	Manufacturer: NULL
    	Product Name: NULL
    	Serial Number: 217489153
    

    (2)查看主板型号

    # dmidecode | grep -A16 "System Information$"

    $ sudo dmidecode |grep -A16 "System Information$"
    System Information
    	Manufacturer: NULL
    	Product Name: NULL
    	Version: 00001
    	Serial Number: 217489153
    	UUID: 8585f61c-e6e9-11e7-b3fe-7df14fc9cc02
    	Wake-up Type: Power Switch
    	SKU Number: Default string
    	Family: Default string
    
    Handle 0x0002, DMI type 2, 15 bytes
    Base Board Information
    	Manufacturer: NULL
    	Product Name: NULL
    	Version: 0
    	Serial Number: MBHB16W10052A80
    	Asset Tag: 217489153
    

      (3)查看BIOS信息

    # dmidecode -t bios
    

    (4)查看内存槽及内存条

    # dmidecode -t memory | head -45 | tail -23
    

      (5)查看网卡信息

    dmesg | grep -i Ethernet
    

    (6) 查看pci信息,即主板所有硬件槽信息

    lspci | head -10
    

    、查看CPU信息

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 
    # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

    判断是否开启了抄超线程:
    如果多个逻辑CPU的"physical id"和"core id"均相同,说明开启了超线程
     逻辑CPU个数 > 物理CPU个数 * CPU内核数   开启了超线程
     逻辑CPU个数 = 物理CPU个数 * CPU内核数   没有开启超线程

    1)查看cpu型号

    $ cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
         32  Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
    

    2)查看系统中实际物理CPU的数量

    # grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l
    

    3)系统中实际物理CPU的数量(核数),即查看逻辑CPU个数

    # cat /proc/cpuinfo |grep 'processor'|wc -l
    # cat /proc/cpuinfo |grep "processor"|sort -u|wc -l   

    4)查看每个物理CPU中core的个数(即核数)

    $ sudo cat /proc/cpuinfo |grep "cores"|uniq
    cpu cores    : 8

    5)查看CPU的主频

    # cat /proc/cpuinfo |grep MHz|uniq 
    cpu MHz         : 1200.000
    cpu MHz         : 2300.000
    cpu MHz         : 1200.000
    

    6)每个物理CPU上逻辑CPU个数:

    $ sudo grep "siblings" /proc/cpuinfo|uniq
    siblings	: 16
    

    7)查看cpu运行模式

    # getconf LONG_BIT
    64
    

    8)查看cpu是否支持64bit

    #  cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
    40
    (结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)
    

    9)一次性查询所有信息:

    #!/bin/bash
    
    physicalNumber=0
    
    coreNumber=0
    
    logicalNumber=0
    
    HTNumber=0
    
    logicalNumber=$(grep "processor" /proc/cpuinfo|sort -u|wc -l)
    
    physicalNumber=$(grep "physical id" /proc/cpuinfo|sort -u|wc -l)
    
    coreNumber=$(grep "cpu cores" /proc/cpuinfo|uniq|awk -F':' '{print $2}'|xargs)
    
    HTNumber=$((logicalNumber / (physicalNumber * coreNumber)))
    
    echo "****** CPU Information ******"
    
    echo "Logical CPU Number  : ${logicalNumber}"
    
    echo "Physical CPU Number : ${physicalNumber}"
    
    echo "CPU Core Number     : ${coreNumber}"
    
    echo "HT Number           : ${HTNumber}"
    
    echo "*****************************"
    

    、查看内存信息

    1)查看内存硬件信息

    $ sudo  dmidecode -t memory | head -45 | tail -24
    	Set: None
    	Locator: CHA_0
    	Bank Locator: A1_Node0_Channel0_Dimm0
    	Type: DDR4
    	Type Detail: Synchronous
    	Speed: 2400 MT/s
    	Manufacturer: Samsung
    	Serial Number: 36AF6765
    	Asset Tag: CHA_0_AssetTag
    	Part Number: M393A4K40BB1-CRC
    	Rank: 2
    	Configured Memory Speed: 1867 MT/s
    	Minimum Voltage: 1.2 V
    	Maximum Voltage: 1.2 V
    	Configured Voltage: 1.2 V
    
    Handle 0x0040, DMI type 17, 40 bytes
    Memory Device
    	Array Handle: 0x003C
    	Error Information Handle: Not Provided
    	Total Width: Unknown
    	Data Width: Unknown
    	Size: No Module Installed
    	Form Factor: Unknown
    

    2)最大支持多少内存

    $ sudo dmidecode|grep -P 'Maximums+Capacity'
    	Maximum Capacity: 768 GB
    	Maximum Capacity: 768 GB
    

    3)Linux 查看内存的插槽数,已经使用多少插槽.每条内存多大:

    $ sudo dmidecode|grep -A5 "Memory Device" | grep Size| grep -v Rang
    	Size: 32 GB
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: 32 GB
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: 32 GB
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: 32 GB
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    	Size: No Module Installed
    

    4)Linux 查看内存的频率:

    # dmidecode|grep -A16 "Memory Device"|grep 'Speed'
    

    5)  查看挂接的分区状态

    # mount | column -t
    /dev/sda2  on  /                         type  ext4         (rw)
    proc       on  /proc                     type  proc         (rw)
    sysfs      on  /sys                      type  sysfs        (rw)
    devpts     on  /dev/pts                  type  devpts       (rw,gid=5,mode=620)
    tmpfs      on  /dev/shm                  type  tmpfs        (rw)
    /dev/sda1  on  /boot                     type  ext4         (rw)
    /dev/sda3  on  /home                     type  ext4         (rw)
    /dev/sda6  on  /tmp                      type  ext4         (rw)
    /dev/sda7  on  /usr                      type  ext4         (rw)
    /dev/sdb1  on  /PureDisk                 type  ext4         (rw)
    

    7) 硬盘检测命令smartctl

    # smartctl -a /dev/sda
    smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-642.el6.x86_64] (local build)
    Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net
    
    Vendor:               HP      
    Product:              LOGICAL VOLUME  
    Revision:             3.56
    User Capacity:        299,966,445,568 bytes [299 GB]
    Logical block size:   512 bytes
    Logical Unit id:      0x600508b1001cc8a1b9ec4dacc5ab35dc
    Serial number:        PDNNK0BRH9U0AG  
    Device type:          disk
    Local Time is:        Mon Feb  5 13:13:33 2018 CST
    Device supports SMART and is Enabled
    Temperature Warning Disabled or Not Supported
    SMART Health Status: OK
    
    Error Counter logging not supported
    Device does not support Self Test logging
    

    8)查看网卡硬件信息

    $  lspci | grep -i 'eth'
    02:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
    02:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
    84:00.0 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4]
    84:00.1 Ethernet controller: Mellanox Technologies MT27700 Family [ConnectX-4]
    

    9)查看所有网卡的链路状态

    # for i in `seq 0 9`;do ethtool eth${i} | egrep 'eth|Link';done
    

    、列出所有PCI设备信息

    # lspci -tv | more
    -+-[0000:ff]-+-08.0  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 QPI Link 0
     |           +-08.3  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 QPI Link 0
     |           +-09.0  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 QPI Link 1
     |           +-09.3  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 QPI Link 1
     |           +-0b.0  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 R3 QPI Link 0 & 1 Monitoring
     |           +-0b.1  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 R3 QPI Link 0 & 1 Monitoring
     |           +-0b.2  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 R3 QPI Link 0 & 1 Monitoring
     |           +-0c.0  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.1  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.2  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.3  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.4  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.5  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.6  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
     |           +-0c.7  Intel Corporation Xeon E7 v3/Xeon E5 v3/Core i7 Unicast Registers
    

    hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)

    dmesg | grep IDE # 查看启动时IDE设备检测状况网络

    crontab -l # 查看当前用户的计划任务 服务

    chkconfig –list # 列出所有系统服务#

    chkconfig –list | grep on # 列出所有启动的系统服务 程序

  • 相关阅读:
    tomcat常见报错解决方法汇总
    C++中socket编程
    Winsock解析
    等价类划分的原则
    在线编译器
    条件覆盖,路径覆盖,语句覆盖,分支覆盖解释
    并发测试
    针对C程序员的 C++
    缸中之脑
    什么是薛定谔的猫
  • 原文地址:https://www.cnblogs.com/zjz20/p/14223300.html
Copyright © 2020-2023  润新知