1. 程式人生 > 實用技巧 >硬碟監控和分析工具:Smartctl

硬碟監控和分析工具:Smartctl

Smartctl(S.M.A.R.T自監控,分析和報告技術)是類Unix下實施SMART任務命令列套件或工具,它用於列印SMART自檢和錯誤日誌,啟用並禁用SMRAT自動檢測,以及初始化裝置自檢。

Smartctl對於Linux物理伺服器非常有用,在這些伺服器上,可以智慧的對磁碟進行錯誤檢查,並將硬體RAID相關的磁碟資訊摘錄下來。

在Linux上很早就有了SMART支援了。如果把Linux裝在VMware等虛擬機器上,在系統啟動時可以看到有個服務啟動報錯:smartd
這個服務就是smart的daemon程序(因為VMware虛擬機器的硬碟不支援SMART,所以報錯)
首先通過dmesg工具,確認一下硬碟的裝置符號
hdb中的h代表IDE,如果顯示位sdb,則代表SATA和SCSI。
最後一個字幕b代表Primary匯流排,第二塊硬碟即Slave位置

下面是一些常用的smartctl命令:

命令描述
-i 指定裝置
-d 指定裝置型別,例如:ata,scsi,marvell,sat,3ware,N
-a或A 顯示所有資訊
-l 指定日誌型別,例如:TYPE:error,selftest,selecttive,directory,background,scttemp[sts,hist]
-H 檢視硬碟健康狀態
-t short 後臺檢測硬碟,消耗時間短
-t long 後臺檢測硬碟,消耗時間長
-C -t short 前臺檢測硬碟,消耗時間短
-C -t long 前臺檢測硬碟,消耗時間長
-X 中斷後臺檢測硬碟
-l selftest 顯示硬碟檢測日誌
首先應確認硬碟是否打開了SMART支援smartctl -i /dev/sda
[root@A01-R04-I255-59 bjzhangxinglong]# smartctl -i /dev/sda
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-504.16.2.el6.x86_64] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

Vendor:               DELL
Product:              PERC H710P
Revision:             
3.13 User Capacity: 1,197,759,004,672 bytes [1.19 TB] Logical block size: 512 bytes Logical Unit id: 0x6b083fe0c1c7230020b080c10502c367 Serial number: 0067c30205c180b0200023c7c1e03f08 Device type: disk Local Time is: Tue Dec 22 15:10:01 2020 CST Device does not support SMART

如果看到不支援這需要我們手動開啟支援

smartctl --smart=on --offlineauto=on --saveauto=on

命令:smartctl -a /dev/sda

smartctl 5.39 2008-10-24 22:33 [x86_64-suse-linux-gnu] (openSUSE RPM)
Copyright (C) 2002-8 by Bruce Allen, http://smartmontools.sourceforge.net

Device: SEAGATE  ST9146803SS      Version: 0006         #硬體廠商
Serial number: 6SD2A3ZZ0000B127LJJM                     #硬碟序列號
Device type: disk
Transport protocol: SAS                                 #介面型別
Local Time is: Fri Mar  4 16:58:30 2016 CST
Device supports SMART and is Enabled                    #是否支援smart管理,有的不支援
Temperature Warning Enabled
SMART Health Status: OK                                  #健康狀態ok
Current Drive Temperature:     21 C                       #當前溫度
Drive Trip Temperature:        68 C                       #此溫度是啥?有待考證
Elements in grown defect list: 0
Vendor (Seagate) cache information
  Blocks sent to initiator = 1044970503
  Blocks received from initiator = 2476401867
  Blocks read from cache and sent to initiator = 106869375
  Number of read and write commands whose size <= segment size = 364621421
  Number of read and write commands whose size > segment size = 0
Vendor (Seagate/Hitachi) factory information
  number of hours powered up = 37638.07
  number of minutes until next internal SMART test = 54

Error counter log:
           Errors Corrected by           Total   Correction     Gigabytes    Total
               ECC          rereads/    errors   algorithm      processed    uncorrected
           fast | delayed   rewrites  corrected  invocations   [10^9 bytes]  errors
read:   15099690        0         0  15099690   15099690       2734.048           0
write:         0        0         0         0          0      71719.613           0
verify:    10434        0         0     10434      10434          0.000           0

Non-medium error count:        0

[GLTSD (Global Logging Target Save Disable) set. Enable Save with '-S on']
No self-tests have been logged
Long (extended) Self Test duration: 3600 seconds [60.0 minutes]