guy labs guy labs

Monitor S.M.A.R.T. with smartmontools in Ubuntu 13.04

 

 

Today we want to install and configure smartmontools to monitor the S.M.A.R.T. attributes. Additionally we want to be notified by email if a warning or an error occurred.

Install and check hard drives

Ok let’s start by installing smartmontools with the following command:

After that we want to check the hard drives with the following command:

Replace the /dev/sda with the hard drive you want to check. If smartctl doesn’t succeed you need to add the type of the hard drive interface to the command. To do this add the -d {TYPE} argument to the previous command and subsitute the {TYPE} with ata, scsi or sat (for sata).

This command outputs some information about your hard drive. Next we want to enable additional features by executing the following command:

This enables the S.M.A.R.T. support (-s on), the offline data collection (-o on) and the autosave of device vendor-specific attributes (-S on). You will find more information about the arguments in the man pages of smartctl.

After that we can check the overall health of the hard drive by executing the following command:

If the test result isn’t PASSED you should backup your data now and exchange the hard drive. We also want to check if your hard drive supports the self checks. To do this execute the following command:

Now check the ouput where it says “Offline data collection capabilities” and one of the values should be “Self-test supported”. Then your hard drive supports the self tests. What you also see in the output is how long the short and the extended self test will probably take to complete.

Ok lets do the short test and then the extended one to see if your hard drive has already some failures or not. Run the following commands: (just be patient, because there isn’t any progress. And the extended one can take some time. Maybe do it overnight.)

The above command tells you when the test should be finished. To see the results use this command:

Just wait till there is a result and if there is no error we will start the extended self-test with the following command:

Once again just wait till it finishes and check the results with the above command from the short test.

Ok if the results look ok, we can now configure the smartd daemon to do the tests periodically and send an email if there is a warning or an error.

Configure smartd

We don’t want to to the self-tests manually each day or week, so we configure the smartd daemon to do this for us. For that open up the file /etc/smartd.conf and comment out the line which starts with DEVICESCAN. We want to configure our own devices. To do that enter the following line to the end of the file:

Replace the /dev/sda hard drive with your specific one. The options of the command mean the following: (I just describe the new options which werent discussed before)

  • -a: Adds common options. See man page for detailed information.
  • -s (S/../.././03|L/../../6/03): This tells the daemon to execute the short self tests each day at 3 A.M and the long tests each Saturday at 03 A.M.
  • -m root: This option sets the user which is notified by email if a warning or an error occurs. This needs to have a proper mail server configured and the correct mail aliases for the root user account.
  • -M exec /usr/share/smartmontools/smartd-runner: This specifies which command to execute if an error occurs. The smartd-runner runs each script inside the /etc/smartmontools/run.d folder. One of these scripts sends the email to the in the -m option defined user.

Ok now duplicate this line, and adapt the drive path (/dev/sda), for each hard drive you want to monitor regurarly and save the file.

Next we need to enable to autostart of the smartd daemon by opening the file /etc/default/smartmontools and uncomment the following line:

Next restart the smartd daemon by executing the following command:

The last thing to do is to test the email notifications. For this open up the /etc/smartd.conf file again and append the option -M test 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 an email see the mail server logs or the system logs for more information.

If you successfully received the email you can remove the option again and restart the smartd service.

What to do if a hard drive has problems?

First of all do a backup. You never know if the hard disk will last for the next ten minutes or the next two years. The next thing to do is to read the smartmontools FAQ, http://smartmontools.sourceforge.net/faq.html, or ask for help in their mailing list.

That’s it for installing and configuring the smartmontools on Ubuntu 13.04.

Thanks for reading the post and stay tuned!  😉

Cheers,

Guy

31,401 total views, 8 views today

Share Post :

4 Comments

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.