最後更新: 2019-03-11
安裝
# Debian
apt-get install smartmontools
# Centos
yum install smartmontools
提供
- /usr/sbin/smartd
- /usr/sbin/smartctl
Scripts
- /etc/init.d/smartmontools
- /etc/init.d/smartd
* Default 只有 /etc/rc2.d/S04smartmontools
主程式
/usr/sbin/smartd
開機時啟動
/etc/default/smartmontools
# List of devices you want to explicitly enable S.M.A.R.T. enable_smart="/dev/sda /dev/sdb" # start smartd on system startup start_smartd=yes # Sets the interval between disk checks to N seconds smartd_opts="--interval=1800"
它會影響以 /etc/init.d/smartmontools 的啟動, 原因
[ -r /etc/default/smartmontools ] && . /etc/default/smartmontools
人手觸發一次 checking
killall -USR1 smartd
log: /var/log/syslog
Mar 11 12:05:38 server smartd[19950]: Signal USR1 - checking devices now rather than in 1662 seconds. ... /dev/sdb [SAT], SMART Usage Attribute: 194 Temperature_Celsius changed from 104 to 103 ... /dev/sdc [SAT], SMART Usage Attribute: 194 Temperature_Celsius changed from 103 to 104 ... /dev/sda [SAT], state written to /var/lib/smartmontools/smartd.ST500DM002_1BC142-S2A38N69.ata.state ... /dev/sdb [SAT], state written to /var/lib/smartmontools/smartd.WDC_WD2002FAEX_007BA0-WD_WMAWP0494646.ata.state ... /dev/sdc [SAT], state written to /var/lib/smartmontools/smartd.WDC_WD2002FAEX_007BA0-WD_WMAWP0494761.ata.state
smartd 的主設定檔
/etc/smartd.conf
# DEVICESCAN cause any remaining lines in this configuration file to be ignored # It will be applied directives to all devices that are found. # It tells smartd to scan for all ATA and SCSI devices # smartd will scan for devices /dev/hd[a-l] and /dev/sd[a-z] # Most users should comment out DEVICESCAN and explicitly list the devices that they wish to monitor. #DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner # 最簡單的設定 # -a The default setting for ATA devices. # 相當於: -H -f -t -l error -l selftest -l selfteststs -C 197 -U 198 # # -W D,I,C Monitor Temperature D)ifference, I)nformal limit, C)ritical limit # the limit INFO is reached, only a message with loglevel 'LOG_INFO' will be logged. # # -I ID Ignore Attribute ID when tracking changes in the Attribute values # temperature(194), power-on hours(9) # This Directive modifies the behavior of the '-p', '-u', and '-t' tracking Directives # # -o VAL Enable/disable automatic offline tests (on/off) # # -S VAL Enable/disable attribute autosave (on/off) # # -m ADDR Send warning email to "ADDR" # if the '-H', '-l', '-f', '-C', or '-O' Directives detect a failure or a new error, # or if a SMART command to the disk fails. # continue lines'\' # "DEFAULT" => all directives in this entry are set as defaults for the next device entries DEFAULT -a -W 5,55,65 -I 194 -o on -S on -m root@localhost # 被 smartd 監測的 HDD /dev/sda /dev/sdb /dev/sdc -a -m admin@localhost # 個別 HDD 的設定
"-a" 說明
-H # to check the SMART health status -f # to report failures of Usage (rather than Prefail) Attributes -t # to track changes in both Prefailure and Usage Attributes -l error # to report increases in the number of ATA errors, -l selftest # to report increases in the number of Self-Test Log errors, -l selfteststs # to report changes of Self-Test execution status -C ID # Report if Current Pending Sector count non-zero -U ID # Report if Offline Uncorrectable count non-zero
# Re-read configure file
killall -s HUP smartd
進階設定
# USB Disk (-d sat)
# If a SCSI to ATA Translation (SAT) layer is between the OS and the device
/dev/sda -a -d sat
# RAW value (-R)
# to report more useful raw temperature
DEVICESCAN -R 194
# raw temperature changes >= N Celsius
# -W D,I,C # Monitor Temperature D)ifference, I)nformal limit, C)ritical limit
# 10 <= X < 50 AND Diff > 5
DEVICESCAN -I 194 -W 5,10,50
# POWERMODE
-n POWERMODE[,N][,q] # [ATA only] This 'nocheck' Directive
It is used to prevent a disk from being spun-up when it is periodically polled by smartd.
ATA disks have five different power states: 'OFF', 'SLEEP', 'STANDBY', 'IDLE', and 'ACTIVE'
MODE:
-
never - smartd will poll (check) the device regardless of its power mode.
This is the default behavior if the '-n' Directive is not given. - sleep - check the device unless it is in SLEEP mode.
- standby - check the device unless it is in SLEEP or STANDBY mode.
- idle - check the device unless it is in SLEEP, STANDBY or IDLE mode.
# Maximum number of skipped checks
# After N checks are skipped in a row, powermode is ignored and the check is performed anyway.
# -n standby,15
# skipped log message (防止為了 log 而叫醒 Harddisk )
# When a periodic test is skipped, smartd normally writes an informal log message.
# The message can be suppressed by appending the option ',q'
# -n standby,15,q
Example Mail
This email was generated by the smartd daemon running on: host name: server DNS domain: local NIS domain: (none) The following warning/error was logged by the smartd daemon: Device: /dev/sda [SAT], Temperature 37 Celsius reached critical limit of 35 Celsius (Min/Max ??/37) For details see host's SYSLOG. You can also use the smartctl utility for further investigation. Another email message will be sent in 24 hours if the problem persists.
Offline Test
HDD 的 test 特性
smartctl -c /dev/sda
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-4-amd64] (local build) Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === General SMART Values: Offline data collection status: (0x82) Offline data collection activity was completed without error. Auto Offline Data Collection: Enabled. Self-test execution status: ( 0) The previous self-test routine completed without error or no self-test has ever been run. Total time to complete Offline data collection: ( 592) seconds. Offline data collection capabilities: (0x7b) SMART execute Offline immediate. Auto Offline data collection on/off support. Suspend Offline collection upon new command. Offline surface scan supported. Self-test supported. Conveyance Self-test supported. Selective Self-test supported. SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer. Error logging capability: (0x01) Error logging supported. General Purpose Logging supported. Short self-test routine recommended polling time: ( 1) minutes. Extended self-test routine recommended polling time: ( 77) minutes. Conveyance self-test routine recommended polling time: ( 2) minutes. SCT capabilities: (0x103f) SCT Status supported. SCT Error Recovery Control supported. SCT Feature Control supported. SCT Data Table supported.
設定
-s REGEXP
Run Self-Tests or Offline Immediate Tests, at scheduled times.
REGEXP Fomat:
T/MM/DD/d/HH
'.' matches any single character
i.e.
# To schedule a short Self-Test between 2–3 am every morning
-s S/../.././02
# To schedule a long Self-Test between 4–5 am every Sunday morning, use:
-s L/../../7/04
# Offline Immediate test, Short Self-Test, Long Self-Test
-s (O/../.././(00|06|12|18)|S/../.././01|L/../../6/03)
# automatic online data collection, automatic Attribute autosave, and
# start a short self-test every day between 2-3am, and
# a long self test Saturdays between 3-4am.
/dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03)
說明
-o on | off
[ATA only] Enables or disables SMART Automatic Offline Testing when smartd starts up and has no further effect.
The delay between tests is vendor-specific, but is typically four hours.
-S on | off
Enables or disables Attribute Autosave when smartd starts up and has no further effect.
另外參考
http://datahunter.org/smartmontools