使用dmidecode命令查看服务器硬件信息
工具简介
dmidecode命令主要是通过DMI获取主机的硬件信息,其输出的信息包括BIOS、系统、主板、处理器、内存、缓存等等。
什么是DMI?
DMI (Desktop Management Interface, DMI)的主要组成部分是Management InformationFormat (MIF)数据库,这个数据库包括了所有有关电脑系统和配件的信息。
安装dmidecode
1、以CentOS 7.9 操作系统为例:
1 2 | [root@linuxyz~]#cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) |
2、安装dmidecode
1 | [root@linuxyz~]# yum -y install dmidecode |
命令语法
1 2 3 4 5 6 7 8 9 10 | dmidecode [选项] 选项 -d:(default:/dev/mem)从设备文件读取信息,输出内容与不加参数标准输出相同。 -h:显示帮助信息。 -s:只显示指定DMI字符串的信息。(string) -t:只显示指定条目的信息。(type) -u:显示未解码的原始条目内容。 --dump-bin file:将DMI数据转储到一个二进制文件中。 --from-dump FILE:从一个二进制文件读取DMI数据。 -V:显示版本信息。 |
常见用法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@localhost ~]$ dmidecode # 打印所有硬件信息 [root@localhost ~]$ dmidecode -q # 打印所有硬件信息,比较简洁 [root@localhost ~]$ dmidecode -h # 获取帮助 [root@localhost ~]$ dmidecode | grep 'Product Name' # 以过滤的方式来查看指定的硬件信息 [root@localhost ~]$ dmidecode --type bios # 查看BIOS相关的硬件信息 [root@localhost ~]$ dmidecode --type system # 查看系统相关的硬件信息 [root@localhost ~]$ dmidecode --type baseboard # 查看主板相关的硬件信息 [root@localhost ~]$ dmidecode --type chassis # 查看机箱相关的硬件信息 [root@localhost ~]$ dmidecode --type processor # 查看处理器相关的硬件信息 [root@localhost ~]$ dmidecode --type memory # 查看内存相关的硬件信息 [root@localhost ~]$dmidecode |grep 'Serial Number' # 查看主板的序列号 [root@localhost ~]$dmidecode -s system-serial-number # 查看系统序列号 [root@localhost ~]$dmidecode -t 11 # 查看OEM信息 [root@localhost ~]$dmidecode -s system-product-name # 系统产品类型 |
dmidecode支持的数字参数如下:
dmidecode支持的数字参数如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 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 |
使用举例
1 查询内存信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # 查询内存条数: [root@linuxyz~]#dmidecode -t 17 | grep "Size.*MB" | wc -l 1 # 查询机器最大支持的内存总量 [root@mysql ~]#dmidecode -t 16 Handle 0x0036, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: Multi-bit ECC Maximum Capacity: 96 GB ## 这里可以查看到当前服务器允许扩容的最大内存为96G。 Error Information Handle: Not Provided Number Of Devices: 12 |
2 更精简的信息显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | [root@localhost ~]$ dmidecode -q //BIOS相关的硬件信息 BIOS Information Vendor: Bochs Version: Bochs Release Date: 01/01/2011 Address: 0xE8000 Runtime Size: 96 kB ROM Size: 64 kB Characteristics: BIOS characteristics not supported Targeted content distribution is supported BIOS Revision: 1.0 //系统相关的硬件信息 System Information Manufacturer: Bochs # 厂商 Product Name: Bochs # 服务器型号 Version: Not Specified # 版本号 Serial Number: 641ab5b5-f6c0-431f-864c-4e750d27de04 # 主板序列号 UUID: 641AB5B5-F6C0-431F-864C-4E750D27DE04 # UUID Wake-up Type: Power Switch SKU Number: Not Specified Family: Not Specified //机箱相关的硬件信息 Chassis Information Manufacturer: Bochs Type: Other Lock: Not Present Version: Not Specified Serial Number: Not Specified Asset Tag: Not Specified Boot-up State: Safe Power Supply State: Safe Thermal State: Safe Security Status: Unknown OEM Information: 0x00000000 Height: Unspecified Number Of Power Cords: Unspecified //处理器相关的硬件信息 Processor Information Socket Designation: CPU 1 Type: Central Processor Family: Other Manufacturer: Bochs ID: F1 06 04 00 FF FB 8B 1F Version: Not Specified Voltage: Unknown External Clock: Unknown Max Speed: 2000 MHz Current Speed: 2000 MHz Status: Populated, Enabled Upgrade: Other //物理内存阵列 Physical Memory Array Location: Other Use: System Memory Error Correction Type: Multi-bit ECC Maximum Capacity: 2 GB Number Of Devices: 1 //内存设备 Memory Device Total Width: 64 bits Data Width: 64 bits Size: 2048 MB Form Factor: DIMM Set: None Locator: DIMM 0 Bank Locator: Not Specified Type: RAM Type Detail: None //内存阵列映射地址 Memory Array Mapped Address Starting Address: 0x00000000000 Ending Address: 0x0007FFFFFFF Range Size: 2 GB Partition Width: 1 //内存设备映射地址 Memory Device Mapped Address Starting Address: 0x00000000000 Ending Address: 0x0007FFFFFFF Range Size: 2 GB Partition Row Position: 1 //系统引导 System Boot Information Status: No errors detected |
判断是否是云主机
1 2 3 4 5 6 7 8 | dmidecode -t 1 dmidecode -s system-product-name PowerEdge R730 # 这个代表物理机 SYS-4028GR-TR # 这个代表物理机 VMware Virtual Platform # 这个代表虚拟机 OpenStack Nova # 这个代表华为云云主机 Alibaba Cloud ECS # 这个代表阿里云云主机 |
华为云:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@eas-ora ~]# dmidecode -t 1 # dmidecode 3.2 Getting SMBIOS data from sysfs. SMBIOS 2.8 present. Handle 0x0100, DMI type 1, 27 bytes System Information Manufacturer: OpenStack Foundation Product Name: OpenStack Nova Version: 13.2.1-20210707213230_d1da3e2 Serial Number: 88f22f46-0843-4ccd-afe9-2929c08e7292 UUID: 88f22f46-0843-4ccd-afe9-2929c08e7292 Wake-up Type: Power Switch SKU Number: Not Specified Family: Virtual Machine |
阿里云:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@xmmup ~]# dmidecode -t 1 # dmidecode 3.2 Getting SMBIOS data from sysfs. SMBIOS 2.8 present. Handle 0x0100, DMI type 1, 27 bytes System Information Manufacturer: Alibaba Cloud Product Name: Alibaba Cloud ECS Version: pc-i440fx-2.1 Serial Number: da419577-4e99-4c00-90f2-d2ef8cbb8571 UUID: da419577-4e99-4c00-90f2-d2ef8cbb8571 Wake-up Type: Power Switch SKU Number: Not Specified Family: Not Specified |