如果是在windows系统下,查询电脑硬件会容易的多,可以通过电脑属性、计算机管理等多种图形化界面中查到,如果安装了各种电脑管家,那查询这类信息就更方便了,但如果在linux系统下通常要使用命令来解决,特别是查询服务器配置时,一般不会给服务器安装图形化界面,所以掌握必要的查询命令对于合理使用服务器资源很有必要。
这个命令是偶然发现的,之前一般是查询电脑硬件资源的使用情况,比如 top
来看各个进程消耗的CPU和内存,使用 free -h
查询内存总体使用情况,最近电脑内存不太够了,想查询一下内存插槽状况,所以找到了这个命令 dmidecode
,英文解释为 “DMI table decoder”,也就是DMI表解码器,可以理解为DMI信息的解释器。
在学习什么是DMI
之前,先了解一下 SMBIOS
的概念,BOIS
是英文"Basic Input Output System"的缩略词,它是一组固化到计算机内主板上一个ROM芯片上的程序,它保存着计算机最重要的基本输入输出的程序、开机后自检程序和系统自启动程序,并可以从CMOS中读写系统设置的具体信息,为计算机提供最底层的、最直接的硬件设置和控制。
SMBIOS
全称是"System Management Basic Input/Output System",表示系统管理基本输入输出系统,是主板或系统制造者以标准格式显示产品管理信息所需遵循的统一规范。
DMI
全称 “Desktop Management Interface”,用于帮助收集电脑系统信息的管理系统,DMI信息的收集必须在严格遵照SMBIOS规范的前提下进行,其设计适用于任何的平台和操作系统,充当了管理工具和系统层之间接口的角色。它建立了标准的可管理系统,更加方便了电脑厂商和用户对系统的了解,同时提供更为友好的用户工作环境。SMBIOS 和 DMI 都是由行业指导机构 “Desktop Management Task Force (DMTF)” 起草的开放性的技术标准。
-q
:显示会简单点,一些未知的、不活动的和oem指定的条目不显示,元数据和句柄引用被隐藏。-t
: 一个非常重要的参数,用于显示指定类型的条目,可以使用数字,也可以使用一些代表数字组合的单词DMI TYPES
The SMBIOS specification defines the following DMI types:
Type Information
────────────────────────────────────────────
0 BIOS
1 System
2 Baseboard
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
40 Additional Information
41 Onboard Devices Extended Information
42 Management Controller Host Interface
数字组合的单词代表:
Keyword Types
──────────────────────────────
bios 0, 13
system 1, 12, 15, 23, 32
baseboard 2, 10, 41
chassis 3
processor 4
memory 5, 6, 16, 17
cache 7
connector 8
slot 9
Keywords are matched case-insensitively. The following command lines are equivalent:
· dmidecode --type 0 --type 13
· dmidecode --type 0,13
· dmidecode --type bios
· dmidecode --type BIOS
-s
:可以输出一些指定关键词相关信息,可用关键词如下: Valid string keywords are:
bios-vendor
bios-version
bios-release-date
system-manufacturer
system-product-name
system-version
system-serial-number
system-uuid
system-family
baseboard-manufacturer
baseboard-product-name
baseboard-version
baseboard-serial-number
baseboard-asset-tag
chassis-manufacturer
chassis-type
chassis-version
chassis-serial-number
chassis-asset-tag
processor-family
processor-manufacturer
processor-version
processor-frequency
以查看内存信息为例,可以使用 sudo dmidecode -t memory
命令查看内存所有信息,根据man手册知道这个命令包括5、6、16、17四项内容,但实际上我查询到的5、6为空,这个命令在我的电脑上只包含16、17两项
$ sudo dmidecode -t memory
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.
Handle 0x0002, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 32 GB
Error Information Handle: Not Provided
Number Of Devices: 2
Handle 0x0003, DMI type 17, 84 bytes
Memory Device
Array Handle: 0x0002
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: SODIMM
Set: None
Locator: ChannelA-DIMM0
Bank Locator: BANK 0
Type: DDR4
Type Detail: Synchronous
Speed: 2667 MT/s
Manufacturer: Micron
Serial Number: 00000000
Asset Tag: None
Part Number: 4ATF51264HZ-2G6E1
Rank: 1
Configured Memory Speed: 2667 MT/s
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: 1.2 V
Memory Technology: DRAM
Memory Operating Mode Capability: Volatile memory
Firmware Version: Not Specified
Module Manufacturer ID: Bank 1, Hex 0x2C
Module Product ID: Unknown
Memory Subsystem Controller Manufacturer ID: Unknown
Memory Subsystem Controller Product ID: Unknown
Non-Volatile Size: None
Volatile Size: 4 GB
Cache Size: None
Logical Size: None
Handle 0x0004, DMI type 17, 84 bytes
Memory Device
Array Handle: 0x0002
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: SODIMM
Set: None
Locator: ChannelB-DIMM0
Bank Locator: BANK 2
Type: DDR4
Type Detail: Synchronous
Speed: 2667 MT/s
Manufacturer: Micron
Serial Number: 00000000
Asset Tag: None
Part Number: 4ATF51264HZ-2G6E1
Rank: 1
Configured Memory Speed: 2667 MT/s
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: 1.2 V
Memory Technology: DRAM
Memory Operating Mode Capability: Volatile memory
Firmware Version: Not Specified
Module Manufacturer ID: Bank 1, Hex 0x2C
Module Product ID: Unknown
Memory Subsystem Controller Manufacturer ID: Unknown
Memory Subsystem Controller Product ID: Unknown
Non-Volatile Size: None
Volatile Size: 4 GB
Cache Size: None
Logical Size: None
可以直接指定单独的数字查询,比如查询内存阵列:
$ sudo dmidecode -t 16
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.
Handle 0x0002, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 32 GB
Error Information Handle: Not Provided
Number Of Devices: 2
查询内存设备(内存条)信息:
$ sudo dmidecode -t 17
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.
Handle 0x0003, DMI type 17, 84 bytes
Memory Device
Array Handle: 0x0002
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: SODIMM
Set: None
Locator: ChannelA-DIMM0
Bank Locator: BANK 0
Type: DDR4
Type Detail: Synchronous
Speed: 2667 MT/s
Manufacturer: Micron
Serial Number: 00000000
Asset Tag: None
Part Number: 4ATF51264HZ-2G6E1
Rank: 1
Configured Memory Speed: 2667 MT/s
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: 1.2 V
Memory Technology: DRAM
Memory Operating Mode Capability: Volatile memory
Firmware Version: Not Specified
Module Manufacturer ID: Bank 1, Hex 0x2C
Module Product ID: Unknown
Memory Subsystem Controller Manufacturer ID: Unknown
Memory Subsystem Controller Product ID: Unknown
Non-Volatile Size: None
Volatile Size: 4 GB
Cache Size: None
Logical Size: None
Handle 0x0004, DMI type 17, 84 bytes
Memory Device
Array Handle: 0x0002
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: SODIMM
Set: None
Locator: ChannelB-DIMM0
Bank Locator: BANK 2
Type: DDR4
Type Detail: Synchronous
Speed: 2667 MT/s
Manufacturer: Micron
Serial Number: 00000000
Asset Tag: None
Part Number: 4ATF51264HZ-2G6E1
Rank: 1
Configured Memory Speed: 2667 MT/s
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: 1.2 V
Memory Technology: DRAM
Memory Operating Mode Capability: Volatile memory
Firmware Version: Not Specified
Module Manufacturer ID: Bank 1, Hex 0x2C
Module Product ID: Unknown
Memory Subsystem Controller Manufacturer ID: Unknown
Memory Subsystem Controller Product ID: Unknown
Non-Volatile Size: None
Volatile Size: 4 GB
Cache Size: None
Logical Size: None
一共有2个存储插槽,每个插槽上装有一个4G的内存条,最大支持32G内存
测试查询内存信息命令 sudo dmidecode -t 16
时可以看到开头有一些版本信息,查询其他类型时也包含这些信息
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.
如果想屏蔽这些信息就可以使用 -q
参数,还可以屏蔽未知信息,可以对比一下:
$ sudo dmidecode -t 16 -q
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 32 GB
Number Of Devices: 2
$ sudo dmidecode -t 16
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.
Handle 0x0002, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 32 GB
Error Information Handle: Not Provided
Number Of Devices: 2
查询BOIS信息:
$ sudo dmidecode -s bios-vendor
LENOVO
$ sudo dmidecode -s bios-version
N2SET18P (1.12 )
$ sudo dmidecode -s bios-release-date
04/01/2020
查询系统信息:
$ sudo dmidecode -s system-uuid
a2d29e4c-2f08-11b2-a85c-8252d66b70f9
$ sudo dmidecode -s system-family
ThinkPad X390
$ sudo dmidecode -s system-manufacturer
LENOVO
查询机箱主板信息
$ sudo dmidecode -s chassis-type
Notebook
$ sudo dmidecode -s chassis-version
None
$ sudo dmidecode -s chassis-serial-number
PC1JX6X4
$ sudo dmidecode -s baseboard-manufacturer
LENOVO
$ sudo dmidecode -s baseboard-product-name
20SDA01ACD
$ sudo dmidecode -s baseboard-version
SDK0L77769 WIN
查询处理器信息
$ sudo dmidecode -s processor-family
Core i5
$ sudo dmidecode -s processor-version
Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
DMI
在遵守SMBIOS规范的前提下帮助收集电脑系统信息,适用于任何的平台和操作系统,可用 dmidecode
命令查询dmidecode
最重要的是 -t
参数,可以指定的特定数字类型0-42,可以使用具有组合命令的单词,bios
、system
、baseboard
、chassis
、processor
、memory
、cache
、connector
、slot
top
、htop
、free
命令,查询静态信息的 lscpu
、lsgpu
、lsmem
、lspci
、lsusb
命令等待挖掘管理的本质是管人理事。真诚待人,踏实做事,坚信自己的目标可以实现并全力以赴,用行动表明自己的态度,不要忘了沟通交流,了解每个人的核心诉求,不要大包大揽,学会做应该做的事而不是所有事~