代码改变世界

如何使用dmidecode命令查看硬件信息

2012-04-20 23:41  bangerlee  阅读(5061)  评论(0编辑  收藏  举报

引言

当我们需要获取机器硬件信息时,可使用linux系统自带的dmidecode工具进行查询。

dmidecode命令通过读取系统DMI表,显示服务器硬件和BIOS信息。除了可使用dmidecode查询机器现有配置,还可以查询机器最大的可支持配置(例如现有的内存,机器最多可支持的内存)

 

dmidecode命令输出格式

执行dmidecode命令,输出如下:

#dmidecode | head -10
# dmidecode 2.9
SMBIOS 2.4 present.
25 structures occupying 844 bytes.
Table at 0x000DC010.
 
Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
  Vendor: LENOVO
  Version: 05CN39WW(V1.10)     
  Release Date: 08/29/2007

以上输出中,前面4条是dmidecode命令整体信息,“25 structures occupying 844 bytes.”该行指示该机器的DMI记录项总共有25条。

 

后面就是DMI表中各条记录,每条记录的输出格式如下:

Record Header:  Handle {record id}, DMI type {dmi type id}, {record size} bytes

Record Value:   {multi line record value}

 

record id: DMI表中每条记录唯一的标识

dmi type id记录的类型,比如BIOS,Memory

record size: DMI表中该条记录的大小

multi line record values多行与该DMI类型相关的字段描述

 

DMI类型

DMI表包含以下DMI类型,每个DMI Type值对应一项硬件信息:

Type   Information
----------------------------------------
  0      BIOS
  1      System
  2      Base Board
  3      Chassis
  4      Processor
  5      Memory Controller
  6      Memory Module
  7      Cache
  8      Port Connector
  9      System Slots
  10     On Board Devices
  11     OEM Strings
  12     System Configuration Options
  13     BIOS Language
  14     Group Associations
  15     System Event Log
  16     Physical Memory Array
  17     Memory Device
  18     32-bit Memory Error
  19     Memory Array Mapped Address
  20     Memory Device Mapped Address
  21     Built-in Pointing Device
  22     Portable Battery
  23     System Reset
  24     Hardware Security
  25     System Power Controls
  26     Voltage Probe
  27     Cooling Device
  28     Temperature Probe
  29     Electrical Current Probe
  30     Out-of-band Remote Access
  31     Boot Integrity Services
  32     System Boot
  33     64-bit Memory Error
  34     Management Device
  35     Management Device Component
  36     Management Device Threshold Data
  37     Memory Channel
  38     IPMI Device
  39     Power Supply

 

根据上表我们亦可知道,可以通过dmidecode命令查到哪些硬件信息,例如要查询主板(Base Board)的信息,可以执行以下命令:

#dmidecode -t 2
# dmidecode 2.9
SMBIOS 2.4 present.
 
Handle 0x0002, DMI type 2, 8 bytes
Base Board Information
Manufacturer: LENOVO
Product Name: IGT30
Version: REFERENCE
Serial Number: 2083601501567 

 

除了使用DMI Type_id作为索引进行查询外,还可以通过设备关键词查询,设备关键词与Type_id对应关系如下:

Keyword       Types
------------------------------
bios          0, 13
system        1, 12, 15, 23, 32
baseboard     2, 10
chassis       3
processor     4
memory        5, 6, 16, 17
cache         7
connector     8
slot          9

这样,执行“dmidecode –t baseboard”命令将显示type_id210项的信息。

 

使用dmidecode命令查询内存(RAM)信息

最后来看个使用dmidecode命令的例子,如何使用dmidecode命令查询内存信息。

 

首先,可以通过以下命令查询机器最大支持的内存总量:

#dmidecode -t 16
# dmidecode 2.9
SMBIOS 2.4 present.
 
Handle 0x000D, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 4 GB
Error Information Handle: Not Provided
Number Of Devices: 2

从以上输出可知,该机器理论上支持的最大内存为4G

 

然后使用以下命令查询机器可用的内存:

#grep MemTotal /proc/meminfo
MemTotal:        2055764 kB

可以看到机器可用的内存为2G,也即我们可以再扩2G内存。

 

但是在用的2G内存是怎么组成的?是1条2G内存?是2条1G内存?

我们可以通过以下命令进行查询:

#dmidecode -t 17
# dmidecode 2.9
SMBIOS 2.4 present.
 
Handle 0x000E, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x000D
Error Information Handle: No Error
Total Width: 32 bits
Data Width: 32 bits
Size: 1024 MB
Form Factor: SODIMM
Set: 1
Locator: M1
Bank Locator: Bank 0
Type: DDR2
⋯⋯
 
Handle 0x000F, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x000D
Error Information Handle: No Error
Total Width: 32 bits
Data Width: 32 bits
Size: 1024 MB
⋯⋯

从以上信息可以看出,该机器插了2条1G的内存。

 

小结

使用linux系统自带工具dmidecode可以查看机器硬件信息,较常用到以下几条命令。

查询机器型号:

#dmidecode | grep -i product
Product Name: TIANYI F41A                     
Product Name: IGT30

查询内存条数:

#dmidecode -t 17 | grep "Size.*MB" | wc -l
2

查询物理CPU信息:

#dmidecode -t 4

 

另外也可通过/proc查询CPU相关信息。

查询物理CPU个数:

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

查询CPU核数:

#cat /proc/cpuinfo | grep 'core id'| wc -l
2

 

本文翻译自 How To Get Hardware Information On Linux Using dmidecode Command