1.1 什麼是Smartmontools?
Smartmontools是一種硬碟偵查工具,通過控制和管理硬碟的SMART(Self Monitoring Analysis and Reporting Technology,自動檢測分析及報告技術)技術來實現的,SMART技術可以對硬碟的磁頭單元、碟片電機驅動系統、硬碟內部電路以及碟片表面介質材料等進行監測,當SMART監測並分析出硬碟可能出現問題時會及時向使用者警示以避免電腦資料受損失。SMART技術必須在主板支援的前提下才能發生作用,而且 SMART技術也不能保證能預報所有可能發生的硬碟故障。SMART(SFF-8035i) 是硬碟生產商們建立的一個工業標準,這個標準就是在硬碟上儲存一個跟執行情況,可靠程度,讀找錯誤率等屬性的表格。所有屬性都有一個1byte(大小範圍1-253)的標準化值,還包含另一個1byte的關鍵階段值,如果屬性工作表格內某個資料接近小於或達到關鍵階段值,表明硬碟工作不正常了。
2.1 Smartmontools的使用
1、啟動監控進程
# /etc/init.d/smartd start
啟動 smartd: [ 確定 ]
2、檢查硬碟是否支援SMART 1993年以後出廠的硬碟基本上都支援SMART技術,使用如下命令可以來查看:
# smartctl -i /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF INFORMATION SECTION ===
Device Model: ST3160212A
Serial Number: 5LS2EDKN
Firmware Version: 3.AAE
User Capacity: 160,041,885,696 bytes
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: 7
ATA Standard is: Exact ATA specification draft version not indicated
Local Time is: Mon Sep 17 02:13:37 2007 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
在上面的資訊可以看到,該硬碟是支援SMART技術,且當前是開啟的。如果SMART support is: Disabled表示SMART未啟用,執行如下命令,啟動SMART:
smartctl --smart=on --offlineauto=on --saveauto=on /dev/hdb
3、檢查硬碟健康狀態
# smartctl -H /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
請注意result後邊的結果:PASSED,這表示硬碟健康狀態良好,如果這裡顯示Failure,那麼最好立刻給伺服器更換硬碟。SMART只能報告磁碟已經不再健康,但是警示後還能繼續運行多久是不確定的,通常,SMART警示參數是有預留的,磁碟警示後,不會當場壞掉,一般能堅持一段時間,有的硬碟SMART警示後還繼續跑了好幾年,有的硬碟SMART報錯後幾天就壞了,千萬不要存在僥倖心理。執行如下命令可以看到詳細的參數:
# smartctl -A /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 114 100 006 Pre-fail Always - 81812244
3 Spin_Up_Time 0x0003 100 099 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 257
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 078 060 030 Pre-fail Always - 64781708
9 Power_On_Hours 0x0032 096 096 000 Old_age Always - 4365
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 276
187 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0
189 Unknown_Attribute 0x003a 100 100 000 Old_age Always - 0
190 Unknown_Attribute 0x0022 058 053 045 Old_age Always - 773324842
194 Temperature_Celsius 0x0022 042 047 000 Old_age Always - 42 (Lifetime Min/Max 0/21)
195 Hardware_ECC_Recovered 0x001a 052 048 000 Old_age Always - 1562815
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always - 0
200 Multi_Zone_Error_Rate 0x0000 100 253 000 Old_age Offline - 0
202 TA_Increase_Count 0x0032 100 253 000 Old_age Always - 0
FLAG是標記,標準數值(VALUE)應當小於或等於關索引值(THRESH)。WHEN_FAILED 代表錯誤資訊,上面顯示的WHEN_FAILED縱行是空行,說明硬碟沒有故障。如果WHEN_FAILED顯示數字,表明硬碟磁軌可能有比較大的壞道。
4、對硬碟進行檢測 手工對硬碟進行測試的方法有以下四種:
smartctl -t short <device> 後台檢測硬碟,消耗時間短
smartctl -t long <device> 後台檢測硬碟,消耗時間長
smartctl -C -t short <device> 前台檢測硬碟,消耗時間短
smartctl -C -t long <device> 前台檢測硬碟,消耗時間長
例如,在後台對硬碟進行詳細的檢查,命令如下:
# smartctl -t long /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Extended self-test routine immediately in off-line mode".
Drive command "Execute SMART Extended self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 54 minutes for test to complete.
Test will complete after Mon Sep 17 03:53:32 2007
Use smartctl -X to abort test.
上面的資訊顯示54分鐘後將完成檢查,同時可以使用 smartctl -X 終止檢查。終止硬碟檢查命令的使用方法是:
# smartctl -X /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Abort SMART off-line mode self-test routine".
Self-testing aborted!
5、查看硬碟日誌 使用“smartctl -l logtype <device>”可以查看硬碟的日誌,日誌又分為多種類型,如selftest、error等等。例如查看硬碟檢測的日誌,如下:
# smartctl -l selftest /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
# 1 Extended offline Aborted by host 90% 4365 -
# 2 Extended offline Completed without error 00% 4247 -
# 3 Short offline Aborted by host 30% 4246 -
# 4 Short offline Aborted by host 10% 4246 -
# 5 Extended offline Completed without error 00% 4229 -
查看硬碟錯誤記錄檔:
# smartctl -l error /dev/hdb
smartctl version 5.33 [i686-turbo-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART Error Log Version: 1
No Errors Logged