If you built your own NAS with a PC, a Linux OS and some disks, you will need to monitor the health of your hard drives. Wouldn’t it be nice to know by advance if a hard disk will fail? Being proactive is essential here. And it also works if you only have a Linux workstation…

For this, we will use the smartmontools package. It contains two utility programs (smartctl and smartd) to control and monitor storage systems using the Self-Monitoring, Analysis and Reporting Technology System (SMART) built into ATA and SCSI harddisks. In many cases, these utilities will provide advanced warning of disk degradation and failure.

Installation

First we will install mail-utils package. This will install a postfix mail server too if not already installed:

Then we install the smartmontools:

Once installed, open the file /etc/default/smartmontools. Uncomment the line start_smartd=yes.
This will make the daemon to start at boot time.

Next, in /etc/smartd.conf add one line per device you want to monitor (for example /dev/sda):

In this example, smartd will:

  • check the SMART health status (-H);
  • report increases in both SMART error logs (-l);
  • check for failure of any Usage Attributes (-f);
  • schedule an Offline Immediate Test every Friday at 11 am, a Long Self-Test every Friday at 1 pm, and a Conveyance Self-Test every Friday at 3 pm (-s) — see the smartd manual page for what these tests do so you can choose what suits you.

Test

The last thing to do is to test the email notifications. For this open up the /etc/smartd.conf file again and change the option -M  to test (“-M test” instead of “-M exec /usr/share/smartmontools/smartd-runner”) to all lines you have added before. This sends a test email after the smartd service is restarted. Now do a restart of it with the following command:

You should receive a test email from smartd. If you don’t receive the email see the mail server logs or the system logs for more information. If you successfully received the email you can remove the test option and restart the smartd service.

Voila! You will now receive warnings if your hard disks go South. Nice right?