2016年2月8日 星期一

Linux用dmesg或dmidecode看硬體資訊

在維修機器前會需要知道系統的硬體資訊,以下介紹兩個能夠看硬體資訊的指令:dmesg 與 dmidecode,使用方式如下:
  • $ dmesg | less
  • # dmidecode --type keywords
dmesg不需要superuser,但要慢慢找; dmidecode則是需要keyword來知道要看的硬體是什麼。指令就這麼簡單,剩下的就是有耐心去讀輸出的訊息~


dmesg - print or control the kernel ring buffer

很古老的方式,用這種方式需要約莫知道自己想要的硬體是什麼。例如說一台安裝Ubuntu的舊型MacBookPro使用dmesg來看相關資訊:

$ dmesg | less
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.16.0-55-generic (buildd@lgw01-42) (gcc version 4.
8.2 (Ubuntu 4.8.2-19ubuntu1) ) #74~14.04.1-Ubuntu SMP Tue Nov 17 10:15:59 UTC 20
15 (Ubuntu 3.16.0-55.74~14.04.1-generic 3.16.7-ckt19)
這邊可以看到系統的核心與作業系統資訊

[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved
BIOS用e820來看系統記憶體的使用

[    0.000000] DMI: Apple Inc. MacBookPro5,5/Mac-F2268AC8, BIOS    MBP55.88Z.00AC.B03.0906151708 06/15/09
這裏可以看到硬體是MacBookPro5,5/編號是F2268AC8,去查會是2009年中的機器

[    0.075605] smpboot: CPU0: Intel(R) Core(TM)2 Duo CPU     P8700  @ 2.53GHz (fam: 06, model: 17, stepping: 0a)
[    0.076000] Performance Events: PEBS fmt0+, 4-deep LBR, Core2 events, Intel PMU driver.
[    0.076000] ... version:                2
[    0.076000] ... bit width:              40
[    0.076000] ... generic registers:      2
[    0.076000] ... value mask:             000000ffffffffff
[    0.076000] ... max period:             000000007fffffff
[    0.076000] ... fixed-purpose events:   3
[    0.076000] ... event mask:             0000000700000003
[    0.076000] x86: Booting SMP configuration:
[    0.076000] .... node  #0, CPUs:      #1
[    0.088036] x86: Booted up 1 node, 2 CPUs
使用的處理器是Intel Core2Duo P8700, 雙核心

[    2.316106] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[    2.316189] ata2: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[    2.316349] ata1.00: HPA detected: current 500116079, native 500118192
[    2.316416] ata1.00: ATA-8: PLEXTOR PX-256M5S, 1.02, max UDMA/133
[    2.316480] ata1.00: 500116079 sectors, multi 16: LBA48 NCQ (depth 31/32)
[    2.316966] ata1.00: configured for UDMA/133
[    2.317175] scsi 0:0:0:0: Direct-Access     ATA      PLEXTOR PX-256M5 1.02 PQ: 0 ANSI: 5
[    2.317499] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    2.317620] sd 0:0:0:0: [sda] 500116079 512-byte logical blocks: (256 GB/238 GiB)
[    2.317697] sd 0:0:0:0: [sda] 4096-byte physical blocks
[    2.317806] sd 0:0:0:0: [sda] Write Protect is off
[    2.317866] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    2.317883] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.318130] ata2.00: ATAPI: MATSHITADVD-R   UJ-868, KB19, max UDMA/66
[    2.320357] ata2.00: configured for UDMA/66
[    2.320469]  sda: sda1 sda2 sda3
[    2.320887] sd 0:0:0:0: [sda] Attached SCSI disk
這邊可以看到硬碟是256G的Plextor固態硬碟,裝置會是/dev/sda

裡面有需多資訊可以挖,不過需要一些計算機系統的相關背景知識,像是必須要知道各種硬體的device name等等。


dmidecode - DMI table decoder

這個指令必須要是root才能夠使用,以下內容參考了FourDollars的文章
# dmidecode --type 1
SMBIOS 2.4 present.

Handle 0x000F, DMI type 1, 27 bytes

System Information
Manufacturer: Apple Inc.
Product Name: MacBookPro5,5
Version: 1.0
Serial Number: 機器的序號
UUID: 機器的編號
Wake-up Type: Power Switch
SKU Number: System SKU#
Family: MacBook

直接可以看到這台機器的內容。上述的DMI type總共有42種,man dmidecode可以得知
       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可以不用記憶DMI type,下面兩個指令是一樣的:
dmidecode --type memory
# dmidecode --type 5,6,16,17

與keyword相關也可以man dmidecode得知:

       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

這邊舉例看處理器
dmidecode --type processor
SMBIOS 2.4 present.

Handle 0x0000, DMI type 4, 35 bytes

Processor Information
Socket Designation: U2E1
Type: Central Processor
Family: Other
Manufacturer: Intel(R) Corporation
ID: 處理器的編號
Signature: Type 0, Family 6, Model 23, Stepping 10
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) Core(TM)2 Duo CPU     P8700  @ 2.53GHz
Voltage: 1.6 V
External Clock: 266 MHz
Max Speed: 2530 MHz
Current Speed: 2530 MHz
Status: Populated, Enabled
Upgrade: ZIF Socket
L1 Cache Handle: 0x0002
L2 Cache Handle: Not Provided
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Unknown
Part Number: Not Specified
這台是雙核心,所以會重複出現兩次一樣的資訊。Flag那一部分是支援的指令集

沒有留言:

張貼留言