Thursday, August 7, 2014

Test HDD using smartctl and automate status

I quite often test hard drives using various vendor specific live environments like SeaTools, etc. But what if you want to use a (live) Linux distro? This is quite doable with smartctl which is a part of smartmontools.

Below are steps to do this, complete with a cool way to automate the status of the test appearing on the screen. Without automating the status, you will not receive any stdout notification unless you run a command manually. Remember, on some distros you will need to use sudo. Also, you will need to have smartmontools installed. If you don't know how to install it, there is plenty of info on Google on that. Keep in mind, some drives don't support SMART, which is lame.

1. Start with looking at your disks to get the filename of the disk as it appears in /dev.

fdisk -l

2. Once you've determined the disk you need to check, you can do a basic health status check. This is not authoritative but gives you a basic idea. Be sure to replace [sda] with your disk.

smartctl /dev/[sda] -H

3. If you want to geek out on every last detail of the status/health of your disk which is currently available you can do that, too.

smartctl /dev/[sda] -a

4. Okay, now it's time to start a test. You can run a short test or a long test, etc. but I always like to run a long test because it's more thorough.

smartctl /dev/[sda] --test=long

5. Smartctl has one downside. It doesn't show you a status of the test running in the background unless you run smartctl -a and find the result within that information. To make things easier, I've provided a way to automate the status of the test so that it scrolls down the screen showing the percent complete. It will also display "...completed" when it is finished.

watch -n 1 smartctl /dev/[sda] -a | grep 'execution\|remaining'

(Note the backslash followed by a pipe for OR.)

6. When the test is complete, you will still need to manually check the result of the test to see if there were errors.

smartctl /dev/[sda] -a

7. Near the bottom of the output will be a section that begins with: "SMART Self-test log structure revision number..." Right below that, you will see the result of recent tests with the most recent (yours) listed first. The status will be shown, including the LBA of the first error, if there are any.

8. Here are a couple of other useful commands...

Help (useful in live Linux distros that do not contain man pages): smartctl -h

Abort a test that is currently running: smartctl /dev/[sda] -X


If this helped you, consider leaving a comment and saying hello!

Tested on...
smartctl: 6.0 2012-10-10 r3643
OS: AVG 2013-08-01 from live USB drive

No comments:

Post a Comment

Spammy/foul language comments or those with an explicit avatar will be tossed in a 55 gallon drum and a match thrown in after them. (Oooo, now I can warm my hands!!)