Linuxでハードウェアの情報(CPUやメモリの型番やマザーボードの型番、シリアルナンバーなど)を取得する場合、dmidecodeを使って取得する場合が多い…のだが、このdmidecodeが利用できない場合、どうやってマザーボードやCPU、メモリの情報を得ればいいだろう。 というわけで、ちょっと調べてみた。

1. CPUについて

dmidecodeでは、以下のようにコマンドを実行することで、CPUのハードウェア情報を得ることができる。

dmidecode --type processor
# dmidecode --type processor
# dmidecode 2.12-dmifs
SMBIOS 2.7 present.

Handle 0x0004, DMI type 4, 42 bytes
Processor Information
        Socket Designation: SOCKET 0
        Type: Central Processor
        Family: Xeon
        Manufacturer: Intel
        ID: D7 06 02 00 FF FB EB BF
        Signature: Type 0, Family 6, Model 45, Stepping 7
        Flags:
                FPU (Floating-point unit on-chip)
                VME (Virtual mode extension)
                DE (Debugging extension)
                PSE (Page size extension)
                TSC (Time stamp counter)
                MSR (Model specific registers)
                PAE (Physical address extension)
                MCE (Machine check exception)
                CX8 (CMPXCHG8 instruction supported)
                APIC (On-chip APIC hardware supported)
                SEP (Fast system call)
                MTRR (Memory type range registers)
                PGE (Page global enable)
                MCA (Machine check architecture)
                CMOV (Conditional move instruction supported)
                PAT (Page attribute table)
                PSE-36 (36-bit page size extension)
                CLFSH (CLFLUSH instruction supported)
                DS (Debug store)
                ACPI (ACPI supported)
                MMX (MMX technology supported)
                FXSR (FXSAVE and FXSTOR instructions supported)
                SSE (Streaming SIMD extensions)
                SSE2 (Streaming SIMD extensions 2)
                SS (Self-snoop)
                HTT (Multi-threading)
                TM (Thermal monitor supported)
                PBE (Pending break enabled)
        Version: Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
        Voltage: 0.0 V
        External Clock: 100 MHz
        Max Speed: 4000 MHz
        Current Speed: 2600 MHz
        Status: Populated, Enabled
        Upgrade: Socket LGA2011
        L1 Cache Handle: 0x0005
        L2 Cache Handle: 0x0006
        L3 Cache Handle: 0x0007
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified
        Core Count: 8
        Core Enabled: 8
        Thread Count: 16
        Characteristics:
                64-bit capable

Handle 0x0008, DMI type 4, 42 bytes
Processor Information
        Socket Designation: SOCKET 1
        Type: Central Processor
        Family: Xeon
        Manufacturer: Intel
        ID: D7 06 02 00 FF FB EB BF
        Signature: Type 0, Family 6, Model 45, Stepping 7
        Flags:
                FPU (Floating-point unit on-chip)
                VME (Virtual mode extension)
                DE (Debugging extension)
                PSE (Page size extension)
                TSC (Time stamp counter)
                MSR (Model specific registers)
                PAE (Physical address extension)
                MCE (Machine check exception)
                CX8 (CMPXCHG8 instruction supported)
                APIC (On-chip APIC hardware supported)
                SEP (Fast system call)
                MTRR (Memory type range registers)
                PGE (Page global enable)
                MCA (Machine check architecture)
                CMOV (Conditional move instruction supported)
                PAT (Page attribute table)
                PSE-36 (36-bit page size extension)
                CLFSH (CLFLUSH instruction supported)
                DS (Debug store)
                ACPI (ACPI supported)
                MMX (MMX technology supported)
                FXSR (FXSAVE and FXSTOR instructions supported)
                SSE (Streaming SIMD extensions)
                SSE2 (Streaming SIMD extensions 2)
                SS (Self-snoop)
                HTT (Multi-threading)
                TM (Thermal monitor supported)
                PBE (Pending break enabled)
        Version: Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
        Voltage: 0.0 V
        External Clock: 100 MHz
        Max Speed: 4000 MHz
        Current Speed: 2600 MHz
        Status: Populated, Enabled
        Upgrade: Socket LGA2011
        L1 Cache Handle: 0x0009
        L2 Cache Handle: 0x000A
        L3 Cache Handle: 0x000B
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified
        Core Count: 8
        Core Enabled: 8
        Thread Count: 16
        Characteristics:
                64-bit capable

dmidecodeを使わずにCPUに関する同様の情報を得る場合は、/proc/cpuinfoファイルから取得できる。 以下、KVM上で取得した際の実行例。

$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 6
model name      : Common KVM processor
stepping        : 1
microcode       : 0x1
cpu MHz         : 1999.958
cache size      : 4096 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl pni cx16 x2apic hypervisor lahf_lm
bugs            :
bogomips        : 3999.91
clflush size    : 64
cache_alignment : 128
address sizes   : 40 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 15
model           : 6
model name      : Common KVM processor
stepping        : 1
microcode       : 0x1
cpu MHz         : 1999.958
cache size      : 4096 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl pni cx16 x2apic hypervisor lahf_lm
bugs            :
bogomips        : 3999.91
clflush size    : 64
cache_alignment : 128
address sizes   : 40 bits physical, 48 bits virtual
power management:

ただ型番やコア数だけが知りたい場合だと、このままではちょっと見にくいので、少々加工しよう。 Model Nameのみを抽出して、かつ集計をすることで、コア数(スレッド数)もわかるようになる。 KVMのだと味気ないので、仮想基盤で使ってるProxmoxのを例にする。一番左がコア数。

awk -F: '/model name/{print $2}' /proc/cpuinfo | uniq -c
root@BS-PHY-PROX-01:~# awk -F: '/model name/{print $2}' /proc/cpuinfo | uniq -c
     24  Intel(R) Xeon(R) CPU           L5640  @ 2.27GHz

2. メモリについて

dmidecodeでは、以下のようにコマンドを実行することで、刺さっているメモリの情報を得ることができる(対応していれば、メモリのメーカーだったり型番も得られる)。

dmidecode --type memory
# dmidecode --type memory
# dmidecode 2.12-dmifs
SMBIOS 2.7 present.

Handle 0x0015, DMI type 16, 23 bytes
Physical Memory Array
        Location: System Board Or Motherboard
        Use: System Memory
        Error Correction Type: Multi-bit ECC
        Maximum Capacity: 128 GB
        Error Information Handle: Not Provided
        Number Of Devices: 8

Handle 0x0017, DMI type 17, 34 bytes
Memory Device
        Array Handle: 0x0015
        Error Information Handle: Not Provided
        Total Width: 72 bits
        Data Width: 64 bits
        Size: 8192 MB
        Form Factor: DIMM
        Set: None
        Locator: P1_DIMMA1
        Bank Locator: Node0_Bank0
        Type: DDR3
        Type Detail: Registered (Buffered)
        Speed: 1333 MHz
        Manufacturer: Samsung
        Serial Number: 837446CD
        Asset Tag: Dimm0_AssetTag
        Part Number: M393B1K70CH0-
        Rank: 1
        Configured Clock Speed: 1333 MHz
…

単純に、搭載している(使える)メモリ容量だけを見るのならfreeコマンドや/proc/meminfoで得られる。

free -h | awk '/^Mem/{print $2}'
cat /proc/meminfo | awk '/^MemTotal/{print $2}' | xargs -I@ echo "@ * 1024" | bc | numfmt --to=iec

そうじゃない、dmidecodeのように、メモリ何本刺さってるんだかとか、知れるならメモリのメーカーとかを知りたいんだ、といった内容については、/sys配下を調べてみたのだが見つけられなかった。 どっかには情報あると思うんだけどなぁ…(dmidecode自体は/dev/mem配下から情報を取ってきてるようなのだが…)。

3. マザーボード・BIOSについて

dmidecodeでは、以下のようにコマンドを実行することでマザーボードやBIOSの情報を得ることができる。 ここから、KVMとか使ってることを推測可能(それだと面白く無いので、実行例は手元の環境で実行)。

dmidecode -t BIOS
dmidecode -t System
dmidecode -t BaseBoard
root@BS-PHY-PROX-01:~# dmidecode -t BIOS
# dmidecode 2.12
SMBIOS 2.5 present.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
        Vendor: FUJITSU // Phoenix Technologies Ltd.
        Version: 6.00 Rev. 1.04.2619.N1
        Release Date: 05/18/2010
        Address: 0xE4120
        Runtime Size: 114400 bytes
        ROM Size: 2048 kB
        Characteristics:
                PCI is supported
                PNP is supported
                BIOS is upgradeable
                BIOS shadowing is allowed
                ESCD support is available
                Boot from CD is supported
                Selectable boot is supported
                EDD is supported
                Print screen service is supported (int 5h)
                8042 keyboard services are supported (int 9h)
                Serial services are supported (int 14h)
                Printer services are supported (int 17h)
                CGA/mono video services are supported (int 10h)
                ACPI is supported
                USB legacy is supported
                BIOS boot specification is supported
                Targeted content distribution is supported
        BIOS Revision: 1.4

Handle 0x0029, DMI type 13, 22 bytes
BIOS Language Information
        Language Description Format: Long
        Installable Languages: 1
                en|US|iso8859-1
        Currently Installed Language: en|US|iso8859-1

root@BS-PHY-PROX-01:~# dmidecode -t System
# dmidecode 2.12
SMBIOS 2.5 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: FUJITSU-SV
        Product Name: PRIMERGY
        Version: GS01
        Serial Number: MA6T003081
        UUID: FA32B660-6CF2-11DF-A847-00199982CD2A
        Wake-up Type: Power Switch
        SKU Number: S26361-K1344-Vxxx
        Family: SERVER

Handle 0x0028, DMI type 12, 5 bytes
System Configuration Options
        Option 1: DIP1 ON: Recovery BIOS active
        Option 2: DIP2 ON: Reserved
        Option 3: DIP3 ON: Flash BIOS write protect
        Option 4: DIP4 ON: Reserved

Handle 0x0050, DMI type 32, 11 bytes
System Boot Information
        Status: No errors detected

root@BS-PHY-PROX-01:~# dmidecode -t BaseBoard
# dmidecode 2.12
SMBIOS 2.5 present.

Handle 0x0002, DMI type 2, 109 bytes
Base Board Information
        Manufacturer: FUJITSU
        Product Name: D2619
        Version: S26361-D2619-N15 WGS10 GS01
        Serial Number: 33260167
        Asset Tag: -
        Features:
                Board is a hosting board
                Board is removable
        Location In Chassis: -
        Chassis Handle: 0x0003
        Type: Motherboard
        Contained Object Handles: 47
                0x0004
                0x0005
                0x000E
                0x000F
                0x0010
                0x0011
                0x0012
                0x0013
                0x0014
                0x0015
                0x0016
                0x0017
                0x0018
                0x0019
                0x001A
                0x001B
                0x001C
                0x001D
                0x001E
                0x001F
                0x0020
                0x0021
                0x0022
                0x0023
                0x0024
                0x0025
                0x0026
                0x0027
                0x0028
                0x002D
                0x002E
                0x002F
                0x0030
                0x0031
                0x0032
                0x0033
                0x0034
                0x0035
                0x0036
                0x0037
                0x0038
                0x0039
                0x003A
                0x003B
                0x003C
                0x003D
                0x003E

Handle 0x0026, DMI type 10, 10 bytes
On Board Device 1 Information
        Type: Video
        Status: Disabled
        Description: MATROX
On Board Device 2 Information
        Type: Ethernet
        Status: Disabled
        Description: Intel 82575EB
On Board Device 3 Information
        Type: Other
        Status: Disabled
        Description: IPMI iRMC S2

で、これら型番やシリアルナンバーをdmidecode使わずに得る場合、以下のディレクトリにあるファイルからある程度得ることができる。 (地味にdmidecodeで得た情報には載ってないサーバの型番が載ってたりする。)

/sys/devices/virtual/dmi/id/
root@BS-PHY-PROX-01:~# grep -R '' /sys/devices/virtual/dmi/id/
/sys/devices/virtual/dmi/id/product_name:PRIMERGY
/sys/devices/virtual/dmi/id/product_uuid:FA32B660-6CF2-11DF-A847-00199982CD2A
/sys/devices/virtual/dmi/id/board_name:D2619
/sys/devices/virtual/dmi/id/board_asset_tag:-
/sys/devices/virtual/dmi/id/power/control:auto
/sys/devices/virtual/dmi/id/power/async:disabled
/sys/devices/virtual/dmi/id/power/runtime_enabled:disabled
/sys/devices/virtual/dmi/id/power/runtime_active_kids:0
/sys/devices/virtual/dmi/id/power/runtime_active_time:0
grep: /sys/devices/virtual/dmi/id/power/autosuspend_delay_ms: Input/output error
/sys/devices/virtual/dmi/id/power/runtime_status:unsupported
/sys/devices/virtual/dmi/id/power/runtime_usage:0
/sys/devices/virtual/dmi/id/power/runtime_suspended_time:0
/sys/devices/virtual/dmi/id/chassis_serial:MA6T003081
/sys/devices/virtual/dmi/id/product_version:GS01
/sys/devices/virtual/dmi/id/chassis_vendor:FUJITSU-SV
/sys/devices/virtual/dmi/id/modalias:dmi:bvnFUJITSU//PhoenixTechnologiesLtd.:bvr6.00Rev.1.04.2619.N1:bd05/18/2010:svnFUJITSU-SV:pnPRIMERGY:pvrGS01:rvnFUJITSU:rnD2619:rvrS26361-D2619-N15WGS10GS01:cvnFUJITSU-SV:ct23:cvrRX300S6R1:
/sys/devices/virtual/dmi/id/chassis_version:RX300S6R1
/sys/devices/virtual/dmi/id/bios_date:05/18/2010
/sys/devices/virtual/dmi/id/bios_version:6.00 Rev. 1.04.2619.N1
/sys/devices/virtual/dmi/id/product_serial:MA6T003081
/sys/devices/virtual/dmi/id/sys_vendor:FUJITSU-SV
grep: warning: /sys/devices/virtual/dmi/id/subsystem/id: recursive directory loop
/sys/devices/virtual/dmi/id/bios_vendor:FUJITSU // Phoenix Technologies Ltd.
/sys/devices/virtual/dmi/id/board_serial:33260167
/sys/devices/virtual/dmi/id/uevent:MODALIAS=dmi:bvnFUJITSU//PhoenixTechnologiesLtd.:bvr6.00Rev.1.04.2619.N1:bd05/18/2010:svnFUJITSU-SV:pnPRIMERGY:pvrGS01:rvnFUJITSU:rnD2619:rvrS26361-D2619-N15WGS10GS01:cvnFUJITSU-SV:ct23:cvrRX300S6R1:
/sys/devices/virtual/dmi/id/chassis_asset_tag:MA6T003081
/sys/devices/virtual/dmi/id/chassis_type:23
/sys/devices/virtual/dmi/id/board_vendor:FUJITSU
/sys/devices/virtual/dmi/id/board_version:S26361-D2619-N15 WGS10 GS01

基本、dmidecode使えればなんとかなると思うが、使えない環境から色々と推測する際に利用できるのでは無いだろうか。