搜尋此網誌

2014年4月21日 星期一

使用smartctl去取得你硬碟的SMART狀態資訊(Linux)

這裡有些小技巧,關於使用smartmontools軟體去取得重要資訊,關於你的硬碟的健康,可以提供簡單的警告信息。

計算機硬碟嵌入SMART(Self-Monitoring, Analysis, and Reporting Technology)功能,它允許你去監控狀一個硬碟所有的健康的狀態;此資訊是非常的重要在於遇到問題時,提供簡單警告信號。
所有的Linux的分支都提供這smartmontools套件,它包含smartctl程式使用於顯示SMART資訊從連接的硬碟上。此套件也提供smartd,它會定時的輪詢裝置去取得狀態。

在UBUNTU上,使用下面指令安裝smartmontools套件
#sudo apt-get install smartmontools

使用smartd是不可或缺的,因為它可以讓你立即知道,當一個SMART屬性是故障的。開始編輯/etc/smartd.conf與加入一個欄位來監控你的硬碟:
/dev/sda -d ata -H -m root
/dev/sdb -d ata -H -m root
...

上面說明此smartd執行是沈默的檢查與發寄郵件給root user,如果綜合的SMART健康狀態不合格時。

當smartd被裝配;請確認去致能監控助手,如果它還沒開始。在Red Hat Enterprise Linux system使用方式:

# chkconfig smartd on
# service smartd start

此smartctl程式也允許,關於你去觀察與測試硬碟的SMART屬性。你能快速檢查一個硬碟綜合健康狀態,藉由使用:

# smartctl -H /dev/sda
smartctl version 5.38 [x86_64-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

獲得一個硬碟的資訊是同樣有效的。以-i的選項,你可以查看硬碟的型態,它的序號...等等。在一個擁有許多硬碟的系統,有此資訊記錄能幫助去知道哪一個硬碟裝置(i.e., /dev/sda)對應哪一個實體硬碟,例如:

# smartctl -i /dev/sda
smartctl version 5.38 [x86_64-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF INFORMATION SECTION ===
Model Family:     Seagate Barracuda 7200.10 family
Device Model:     ST3320620AS
Serial Number:    9QF26NGD
Firmware Version: 3.AAJ
User Capacity:    320,072,933,376 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   7
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Sun Mar  7 14:20:18 2010 MST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

致能SMART support的指令:
#smartctl --smart=on /dev/sda

除能的指令:
#smartctl --smart=off /dev/sda

接下來-a的選項,它會顯示詳細的SMART屬性與測試的歷史記錄。這顯示許多的SMART狀態資訊,例如:硬碟的溫度,它已經開啟電源幾個鐘頭...等等。它也指示當測試影經被執行,還有他那些測試結果。
最後,對於硬碟smartctl能被使用於啟始操作long與short測試。這些應該被定期的執行,快速,或全部,硬碟的自我測試。

# smartctl --test=short /dev/sda
# smartctl --test=long /dev/sda
# smartctl -a /dev/sda

上面第一個執行/dev/sda裝置的短測試。這通常花大約執行一分鐘,與smartctl輸出將告訴你,讓你能檢查此結果。 接下來的長測試,這一個能做非常徹底有點久(在320G的硬碟大約需要2個鐘頭)。 最後使用-a的選項去顯示結果,它可能看起來像:

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%     17877         -
# 2  Extended offline    Completed without error       00%      8449         -
# 3  Short offline       Completed without error       00%      8446         -
# 4  Short offline       Completed without error       00%      1307         -
# 5  Short offline       Completed without error       00%         2         -
# 6  Extended offline    Self-test routine in progress 90%     17877         -

在上面範例,測試被執行在一個硬碟的生命時間裡,與短暫離線測試是近來完成沒有錯誤,在這裡仍有延伸測試剩餘90%。
在它們能導致故障災難之前,可藉由多數問題的察覺去主動預知你的硬碟健康狀態。在SMART監控不是精確無誤的事情(它將經常不報告故障,在它們發生之前),更多抓住問題機會的可能與能夠恢復資料,在替換一個硬碟之前不發生。比起你不使用它,所資料遺失或其他問題的後果。

From: http://www.techrepublic.com/blog/linux-and-open-source/using-smartctl-to-get-smart-status-information-on-your-hard-drives/