SMART tests can give an early warning of impending hard disk failures. Tests can be run manually but this is inconvenient and results are not available immediately. Thankfully smartd can be used to run these tests automatically and email if any warnings occur. Before configuring automatic SMART monitoring you need to install smartmontools and check hard drives for SMART errors to make sure there are no failing hard drives. Smartmontools package also includes smartd daemon which will be used to run SMART tests automatically.
Open smartd configuration file.
sudo nano /etc/smartd.conf
Add a script to the end of the file repeating for each hard drive. Make sure a line with
DEVICESCAN is commented out.
DEVICESCAN -a -m email@example.com -M exec /usr/share/smartmontools/smartd-runner -M test -n standby,30 -s (S/../.././18|L/../../5/16) /dev/sdb -a -d ata -m root -n standby,30 -s (S/../.././18|L/../../5/16) /dev/sdc -a -d ata -m firstname.lastname@example.org -n standby,30 -s (S/../.././18|L/../../5/16)
The first option selects a hard drive to scan or to scan all hard disk devices use
DEVICESCAN. Repeat the entire line for each disk that needs to be scanned. Option
-a monitors all SMART features. To specify the hard drive interface explicitly use
-d option with values like
DEVICESCAN is used it is better to remove
-d option as smartd will fail to start if the type is not correct for any of the hard drives present. Specify an email address that will be used to send notifications or a local Linux user with
-m option. If a username is specified the email of that user will be used if configured properly. The type of email notifications can be specified with
-M option. Default value is
once which will send only a single warning email per error. Other possible values are
diminishing. To verify that email notifications are configured correctly use the
test option which will send a sample notification each time smartd starts. Another possibility is to specify the path to a script after the
exec option or both exec and test options to execute a script when smartd starts.
To prevent hard drive spin-up due to smartd polling use
-n option followed by the value. Default value of
never will poll regardless of power state.
sleep value will poll the hard drive unless it is in sleep mode.
standby will poll the hard drive unless the it is in sleep or standby power state.
idle value will never poll unless the hard drive is in
active state. Maximum number of skipped checks in a row can be specified by appending a comma followed by a positive number after the value. After a maximum number of skipped checks is exceeded a SMART check will be executed regardless of the power mode value. SMART support is turned
-o option turns offline data collection
-S turn autosave of device vendor-specific attributes
Configure a scan schedule with
-s option followed by regular expression in brackets. The letter
S sets the test type to
L sets the type to
long. Multiple test schedules are separated by a vertical bar
|. Values following the test type are separated by
/ and define when the test is to be carried out. Schedule values are listed in the following order:
day of the week and
hour. The hour value of
18 will perform the test at 6 pm while the day value of
5 and hour value of
16 will run the test on Friday at 4 pm. To repeat the test for every particular time period a
. can be used for the day of the week or
.. for other values.
Refer to the smartd.conf manual for full details.
Smartd can be configured to execute a script with
-M exec option. Another method is to execute a script which in turn executed any number of scripts in a specified directory.
Install smartd-runner script dependency.
sudo pacman -S run-parts
Create the smartd-runner script.
sudo nano /usr/share/smartmontools/smartd-runner
Copy the script.
#!/bin/bash tmp=tempfile cat >$tmp run-parts --report --lsbsysinit --arg=$tmp --arg="$1" \ --arg="$2" --arg="$3" -- /etc/smartmontools/run.d rm -f $tmp
Set execute permissions on the script.
sudo chmod +x /usr/share/smartmontools/smartd-runner
Create the scripts directory if it does not exist.
sudo mkdir -p /etc/smartmontools/run.d
Parent directories are created automatically as needed with
There is a variety of useful scripts that can be run to notify the user of an issue. To send an email configure email notifications or if you use one or more Kodi media centers it might be useful to configure XBMC / Kodi notifications. To cover every possibility also configure command line notifications and buzzer alarm notifications.
The systemd defaults will work out of the box but can be customized by changing smartd default arguments.
Open smartd service script.
sudo nano /usr/lib/systemd/system/smartd.service
$SMARTD_ARGS with smartd arguments.
[Unit] Description=Self Monitoring and Reporting Technology (SMART) Daemon Documentation=man:smartd(8) man:smartd.conf(5) After=syslog.target [Service] EnvironmentFile=-/etc/conf.d/smartd ExecStart=/usr/bin/smartd -n $SMARTD_ARGS ExecReload=/bin/kill -HUP $MAINPID StandardOutput=syslog [Install] WantedBy=multi-user.target
By default SMART data refreshes take place every 1800 seconds (30min). This can be changed by setting the
-i argument to any value in seconds.
Refer to systemd manual for the full list of arguments.
Start smartd manually.
sudo systemctl start smartd
sudo systemctl restart smartd
This is useful with
-M test option when testing email configuration.
Run smartd on boot.
sudo systemctl enable smartd
View recent log entries related to smartd.
journalctl -u smartd
If smartd script fails to accomplish the desired task this should provide the reasons it failed.
sudo nano /etc/smartd.conf man smartd.conf sudo pacman -S run-parts sudo nano /usr/share/smartmontools/smartd-runner sudo chmod +x /usr/share/smartmontools/smartd-runner sudo mkdir -p /etc/smartmontools/run.d
sudo nano /usr/lib/systemd/system/smartd.service man smartd sudo systemctl start smartd sudo systemctl restart smartd sudo systemctl enable smartd journalctl -u smartd