Install and configure SMART on Ubuntu Server

Hard drives are wonderful things and normally give many years of trouble-free service. However, sometimes they can suddenly go bang and your data’s gone. To protect yourself against such an eventuality, apart from keeping your RAID array up to date and taking regular backups of critical data you can use a tool called SMART (Self-Monitoring Analysis and Reporting Tool) to keep an eye on your disks because sometimes they show signs of pending doom giving you the chance to take evasive action. Most modern drives support SMART and produce useful statistics which the SMART tool can read. So, let’s go ahead and install SMART and see if your drives support it:

So, first off let’s bring the Ubuntu Repository up to repository up to date:

TIP: If you’re using Putty and are going to be following this guide step-by-step then you can save yourself some typing by simply highlighting each command, right-clicking on it and selecting Copy. Then toggle over to your Putty Session and right-click once more. The command you’ve just copied from here will be automatically pasted into your Putty Session.

sudo apt-get update

Now install SMART

sudo apt-get install smartmontools

Checking your drives for SMART Capability

First off we need to list all the drives in our system. The lsblk (list block devices) command produces some nice output:

sudo lsblk

Mine comes back with this:

NAME MAJ:MIN RM SIZE  RO TYPE MOUNTPOINT
sda    8:0    0 3.7T   0 disk
├─sda1 8:1    0 1M     0 part
├─sda2 8:2    0 3.8G   0 part [SWAP]
├─sda3 8:3    0 46.6G  0 part /
└─sda4 8:4    0 3.6T   0 part /media/WD40EFRX
sdb    8:16   0 1.8T   0 disk
└─sdb1 8:17   0 1.8T   0 part /media/HD204UI
sdc    8:32   0 3.7T   0 disk
└─sdc1 8:37   0 3.7T   0 part /media/WD4000FYPS
sdd    8:48   0 3.7T   0 disk
└─sdd1 8:49   0 3.7T   0 part /media/ST4000VN_1
sde    8:64   0 3.7T   0 disk
└─sde1 8:65   0 3.7T   0 part /media/WD40EADS
sdf    8:80   0 3.7T   0 disk
└─sdf1 8:81   0 3.7T   0 part /media/HD403WI
sdg    8:96   0 3.7T   0 disk
└─sdg1 8:97   0 3.7T   0 part /media/ST4000VN_2
sr0    11:0   1 1024M  0 rom
sr1    11:1   1 1024M  0 rom

So, as you can see my drives are referred to as sda, sdb, sdc etc.

So, to determine if each of your drives support SMART issue the following command for each of them:

sudo smartctl -i /dev/sda

obviously substituting sda with the name of your drive as determined above. You should see output similar to this:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-44-generic] (local build)
Copyright(C)2002-13,Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model: ST4000VN000-1H4168
Serial Number: W300Q8RT
LU WWN Device Id: 5 000c50 06ac7eb03
Firmware Version: SC43
User Capacity: 4,000,787,030,016 bytes [4.00 TB]
Sector Sizes: 512 bytes logical, 4096 bytes physical
Rotation Rate: 5900 rpm
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: ACS-2, ACS-3 T13/2161-D revision 3b
SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Fri Jan 23 21:20:34 2015 GMT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

Note the last two lines which show the drive supports SMART and that SMART is enabled on this drive.

How to enable SMART

Possibly the output from the above ends as follows:

SMART support is: Available - device has SMART capability.
SMART support is: Disabled
SMART Disabled. Use option -s with argument 'on' to enable it.
(override with '-T permissive' option)

Here you can see the drive DOES support SMART it’s just not been enabled. So you can enable it as follows:

sudo smartctl -s on /dev/sdg

obviously substituting sdg with the name of the relevant drive.

How to run SMART self-tests

There a a few different self-tests you can run on your drives and they are the Short test, Extended test and what’s called a Conveyance test.

The Short-test is a collection of routines that have the greatest chance of detecting problems without taking too long to run. The routines perform things like checking the mechanical and electrical performance of the drive.

The Extended test is a very comprehensive test which tests the whole of the drive surface as well as performing all the tests in the short-test. This test can take a LONG time.

The Conveyance test is a quick check for damage which may have occurred during transit.

So, to run any of the above tests issue the following command on the drive you wish to check:

sudo smartctl -t short /dev/sda

which will run a short test on device sda. To perform a long/extended test substitute short in the command above with long. Or for the conveyance test use conveyance.

You should see output similar to this:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-44-generic] (local build)
Copyright(C)2002-13,Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Short self-test routine immediately in off-line mode".
Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 2 minutes for test to complete.
Test will complete after Sat Jan 24 14:20:56 2015

Use smartctl -X to abort test.

To see the progress or result issue the following command:

sudo smartctl -l selftest /dev/sda

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-44-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num Test_Description Status                   Remaining LifeTime(hours) LBA_of_first_error
# 1 Short offline Completed without error           00%     3242        -
# 2 Extended offline Completed without error        00%      228        -
# 3 Extended offline Completed without error        00%       21        -
# 4 Extended offline Aborted by host                90%       11        -
# 5 Extended offline Aborted by host                20%       10        -

As you can see the short-test I’ve just run completed without error.

How to run SMART as a daemon

Whilst it’s all well and good running the tests manually it’s much better to get our server to do it automatically for us. This is quite a simple task since smartmontools provides a daemon service which can additionally email us the results if it finds any issues.

How to enable the SMART Daemon

First off we need to enable the Daemon. We can do this as follows:

sudo vim /etc/default/smartmontools

Uncomment (by removing the #) the line start_smartd=yes so your script looks like this:

# Defaults for smartmontools initscript (/etc/init.d/smartmontools)
# This is a POSIX shell fragment

# List of devices you want to explicitly enable S.M.A.R.T. for
# Not needed (and not recommended) if the device is monitored by smartd
# enable_smart="/dev/hda /dev/hdb"

# uncomment to start smartd on system startup
# start_smartd=yes

# uncomment to pass additional options to smartd on startup
# smartd_opts="--interval=1800"

Then press the [Esc] key once and type :wq to save and quit out of the script. If you make a mistake then issue :q! instead of :wq to abort your changes.

How to configure the SMART Daemon

Now we’ve enabled the Daemon we need to tell it what to do. We do this using the /etc/smartd.conf file. Out of the box this file has one active command in it starting with DEVICESCAN. If you want to leave everything at the default settings then you can just skip this section. I’d recommend not doing so because the default isn’t particularly useful. So,

sudo vim /etc/smartd.conf

and comment out that DEVICESCAN line by adding a # to the beginning of it.
  
As and when you make any changes to the smartd.conf file you should restart the smartmontools service. You can do so using the following command:

sudo service smartmontools restart

The stop the service use stop in stead of restart. To start the service again use start