linux下硬盤健康的檢測

http://www.turbolinux.com.cn/turbo/wiki/doku.php?do=export_xhtml&id=%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86:smartmontools

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
發佈了3 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章