硬碟是伺服器最脆弱的機械部件。S.M.A.R.T.(Self-Monitoring, Analysis and Reporting Technology)提供硬碟自我監測能力,透過 smartctl 工具可即時掌握健康狀態,在災難發生前完成遷移與更換。
modprobe libata(SATA)、modprobe scsi_mod(SCSI/SAS)yum install -y smartmontools 或 apt install smartmontoolssmartctl -i /dev/sda
關鍵輸出:
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
若顯示 Disabled,啟用之:
smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda
smartctl -H /dev/sda
輸出關鍵行:
SMART overall-health self-assessment test result: PASSED
smartctl -A /dev/sda
重點關注屬性(ID 對應):
| ID | 屬性名稱 | 關鍵含義 | 警戒閾值 |
|---|---|---|---|
| 5 | Reallocated_Sector_Ct | 重新配置扇區計數(壞軌替換) | > 0 即關注,> 10 嚴重 |
| 197 | Current_Pending_Sector | 待測扇區計數(可能壞軌) | > 0 需關注 |
| 198 | Offline_Uncorrectable | 離線不可修正扇區 | > 0 極度危險 |
| 199 | UDMA_CRC_Error_Count | CRC 錯誤(傳輸線/介面問題) | 持續增長檢查纜線 |
| 190/194 | Airflow_Temperature / Temperature_Celsius | 溫度 | > 50℃ 需改善散熱 |
| 9 | Power_On_Hours | 通電時數 | > 40000h 進入老化期 |
| 12 | Power_Cycle_Count | 開關機次數 | 參考廠商壽命 |
| 1 | Raw_Read_Error_Rate | 讀取錯誤率(廠商編碼) | 需參考 RAW 值 |
| 7 | Seek_Error_Rate | 尋找錯誤率 | 機械故障前兆 |
# 短時間測試(約 2 分鐘)
smartctl -t short /dev/sda
# 長時間測試(數小時,建議離峰時段)
smartctl -t long /dev/sda
# 指定區塊測試
smartctl -t select,100-200 /dev/sda
# 查看測試進度/結果
smartctl -l selftest /dev/sda
smartctl -a /dev/sda
包含:裝置資訊、健康狀態、所有屬性、錯誤日誌、自我測試日誌。建議定期導出存檔趨勢分析。
啟動 smartd 守護程式(/etc/smartd.conf):
# 範例:每 30 分鐘檢查,健康狀態變化發郵件
DEVICESCAN -H -m admin@example.com -M exec /usr/share/smartmontools/smartd-runner
systemctl enable smartd
systemctl start smartd
smartctl 會報錯或回傳虛擬資料# NVMe 使用 nvme-cli 而非 smartctl
nvme smart-log /dev/nvme0
# 關鍵指標:percentage_used(壽命百分比)、critical_warning、temperature
smartctl -A 關鍵屬性趨勢