FreeBSD: Monitor Your Disks’ Health with Smartmontools

Whether you’re using FreeBSD for your workstation, a simple home server, or in a complex IT environment where reliability is critical, losing the data on your hard disk(s) is probably the worst type of failure you can have.  I’ve already gone over a backup strategy for FreeBSD, but it’s best to try to prevent data loss before it happens.

As it turns out, pretty much all modern hard disks have built-in SMART technology (SMART stands for Self-Monitoring, Analysis and Reporting Technology).  It can alert you before many types of problems will occur, and hopefully provide you with enough time to get your data off the drive safely, before catastrophic failure occurs.

It’s pretty easy to take advantage of this technology on FreeBSD with a package called Smartmontools.

Installation

Easily done through the ports collection.  Make sure your ports are up-to-date, and then:

# cd /usr/ports/sysutils/smartmontools && make install clean

Configuration

Smartmontools will have installed a sample configuration file in /usr/local/etc/smartd.conf.sample – copy that over to smartd.conf.  This file controls how smartd operates – smartd is the daemon that monitors the SMART status of your drive(s).  The only uncommented line by default is “DEVICESCAN” – this will cause smartd to monitor and log (to syslog) errors on all of the SMART-capable devices it finds on your system.

Here’s a good configuration line to get started:

DEVICESCAN -a -m [email protected]

That’s the only line you need – and anything after it will be ignored.  It’s pretty straightforward.  By the way, we can do without the -a switch – it’s the default – but I included it for verbosity.  That switch will monitor the following: Overall health status, failures in usage, self-test failures, ATA errors, and some other attributes (see the man page for smartd.conf for more detailed information).   The -m switch specifies that any errors should be sent via e-mail to the specified address.

Next, enable smartd by adding the following line to your /etc/rc.conf so that it will start every time the system boots:

smartd_enable="YES"

Testing

Next, let’s test and validate that the e-mail works.  At the end of your DEVICESCAN line, add “-M test” (note the capital M), then start smartd:

/usr/local/etc/rc.d/smartd start

You should receive an e-mail to the address you specified for each of the devices you have in your system – in my case, I have 3 hard disks, and I received 3 e-mails.  We now know that it can send e-mail successfully, and that it’s detected all of my devices.

Go back into your smartd.conf and remove the “-M test” parameter, and restart smartd:

/usr/local/etc/rc.d/smartd restart

Daily Status E-Mail

Hopefully, you at least skim the daily, weekly, and monthly e-mails from periodic(8) – if you don’t, you should.  If you would like to see your overall disk status included in the “daily run” e-mail, simply add this line to your /etc/periodic.conf:

daily_status_smart_devices="/dev/ad4 /dev/ad8 /dev/ad10"

You will, of course, need to change the list of devices to suit your needs.

Further Reading

That’s it! You’re done.  You’ve installed and configured smartmontools and are probably better off for it.  There’s a lot of detailed configuration that we didn’t go over, but that you might find useful – and there are also some caveats for certain types of disks (they don’t all work the same way and sometimes smartmontools has special configuration directives for those disks).  First, read their FAQ at http://smartmontools.sourceforge.net.  Then, read over the man pages.  Happy monitoring!

Leave a Comment

Your email address will not be published. Required fields are marked *

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