Understanding smartctl
I have what I think is a failing hard drive in my little Linux server. Unfortunately it’s a 2012 Mac Mini so replacing the drive is a huge PITA. So.. just how bad is that drive, do I really have to replace it?
The first thing to do is enable SMART on the drive. It might already be on. But if it’s not no big deal, just turn it on. Some of the historical data the drive has been tracking will suddenly be available, although the tables of attributes may not be. It’s safe to enable SMART and run tests while the drive is active. Here’s how to turn on SMART and also enable some automatic smart testing.
smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda
You can then do a quick health check, but beware that a drive with some errors may still show as healthy
smartctl -H /dev/sda
Attributes
The next thing to do is dump all the smart data on the drive
smartctl -x /dev/sda | less
There’s a lot of data there and you can kind of read it. The confusing thing is the table of attributes; this guide here helped me understand it better.
SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE
1 Raw_Read_Error_Rate PO-R-- 100 100 062 - 65536
2 Throughput_Performance P-S--- 100 100 040 - 0
3 Spin_Up_Time POS--- 208 208 033 - 1
4 Start_Stop_Count -O--C- 095 095 000 - 7921
5 Reallocated_Sector_Ct PO--CK 043 043 005 - 1490
7 Seek_Error_Rate PO-R-- 100 100 067 - 0
8 Seek_Time_Performance P-S--- 100 100 040 - 0
9 Power_On_Hours -O--C- 029 029 000 - 31378
10 Spin_Retry_Count PO--C- 100 100 060 - 0
12 Power_Cycle_Count -O--CK 100 100 000 - 158
160 Unknown_Attribute -O--CK 100 100 000 - 0
191 G-Sense_Error_Rate -O-R-- 100 100 000 - 0
192 Power-Off_Retract_Count -O--CK 100 100 000 - 22
193 Load_Cycle_Count -O--C- 001 001 000 - 1673246
194 Temperature_Celsius -O---- 200 200 000 - 30 (Min/Max 14/48)
195 Hardware_ECC_Recovered -O-R-- 100 100 000 - 0
196 Reallocated_Event_Count -O--CK 038 038 000 - 1614
197 Current_Pending_Sector -O---K 100 100 000 - 152
198 Offline_Uncorrectable ---R-- 100 100 000 - 0
199 UDMA_CRC_Error_Count -O-R-- 200 200 000 - 0
223 Load_Retry_Count -O-R-- 100 100 000 - 0
254 Free_Fall_Sensor -O--CK 100 100 000 - 3
||||||_ K auto-keep
|||||__ C event count
||||___ R error rate
|||____ S speed/performance
||_____ O updated online
|______ P prefailure warning
Long story short, “Value” is a number for 1-100. The higher the number the better, 100 is perfect. “Worst” is the worst it’s ever been; maybe forever, maybe since SMART was enabled. “Thresh” is the threshold below which the drive is considered to be in “pre-fail” state.
So how’s my drive? A lot of values are 100, so it’s not a total loss. Reallocated_Sector_Ct is at 043 which is troubling but not the end of the world; drives are designed to map over the occasional bad sector.
Error log
The other thing I find useful is the error log.
Error 518 [1] occurred at disk power-on lifetime: 31377 hours (1307 days + 9 hours)
When the command that caused the error occurred, the device was active or idle.
After command completion occurred, registers were:
ER -- ST COUNT LBA_48 LH LM LL DV DC
-- -- -- == -- == == == -- -- -- -- --
40 -- 51 00 08 00 00 31 41 12 30 01 00 Error: UNC at LBA = 0x31411230 = 826348080
Commands leading to the command that caused the error were:
CR FEATR COUNT LBA_48 LH LM LL DV DC Powered_Up_Time Command/Feature_Name
-- == -- == -- == == == -- -- -- -- -- --------------- --------------------
60 00 08 00 a8 00 00 31 41 12 30 40 00 00:07:11.085 READ FPDMA QUEUED
60 00 40 00 a0 00 00 31 40 11 00 40 00 00:07:11.074 READ FPDMA QUEUED
60 00 08 00 98 00 00 31 00 21 00 40 00 00:07:11.062 READ FPDMA QUEUED
60 01 00 00 90 00 00 31 00 12 c0 40 00 00:07:11.061 READ FPDMA QUEUED
60 01 00 00 88 00 00 31 00 11 c0 40 00 00:07:11.060 READ FPDMA QUEUED
The error details are not very useful. UNC means “Uncorrectable” and probably means some data was corrupted at that blog. But what’s super useful is the date stamp on the error along with the log. You can use that to estimate the rate of errors, whether it was a one time bad luck or something really wrong.
Running tests
SMART has a self-test built in.
smartctl --test=short /dev/sda
This runs for a couple of minutes asynchronously. Then you can see the result
smartctl -l selftest /dev/sda
=== 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: read failure 30% 31378 728636768
# 2 Short offline Completed: read failure 30% 31378 728636768
I’ve run two short tests and both show a read failure. Yep, my disk is definitely not entirely healthy.
Monitoring
The clever thing to do is run smartd to track smart for you and send an email alert when the disk is failing. I’ll be honest; I do this and then don’t know how to act on the email. Replacing a disk the very first time anything goes wrong is not crazy, but it is expensive and sometimes you can accept that you might lose a file or two because it’s a backup disk or something.