Analyze hard drive with tools badblocks and smartctl
So one of the disks under our HTPC array has finally failed after nearly 2 years. However we did not sustain any data loss as a result since it's only the first disk in a RAID6 system meaning we could still sustain a second disk failure without any data loss. So we are still good and no harm is coming to our data. This is the good part. As it's less then 2 years, we still have a warranty on the disk so we'll RMA this thing later on if it proves that it can't be written to again. Before we RMA anything, we'll analyze the disk a bit with smartctl and the bacblocks commands. Here's how we'll go about this:
First and foremost let's get some statistics on our disk from smartctl:
[root@mbpc log]# smartctl -a /dev/rsde
smartctl 5.42 2011-10-20 r3458 [x86_64-linux-2.6.32-358.6.2.el6.x86_64.debug] (local build)
Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
=== START OF INFORMATION SECTION ===
Model Family: Seagate Barracuda LP
Device Model: ST31000520AS
Serial Number: 9VX0WK55
LU WWN Device Id: 5 000c50 026cc0da7
Firmware Version: CC32
User Capacity: 1,000,204,886,016 bytes [1.00 TB]
Sector Size: 512 bytes logical/physical
Device is: In smartctl database [for details use: -P show]
ATA Version is: 8
ATA Standard is: ATA-8-ACS revision 4
Local Time is: Sun Jul 21 20:08:31 2013 EDT
SMART support is: Available – device has SMART capability.
SMART support is: Enabled
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
General SMART Values:
Offline data collection status: (0x00) Offline data collection activity
was never started.
Auto Offline Data Collection: Disabled.
Self-test execution status: ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
Total time to complete Offline
data collection: ( 623) seconds.
Offline data collection
capabilities: (0x73) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
No Offline surface scan supported.
Self-test supported.
Conveyance Self-test supported.
Selective Self-test supported.
SMART capabilities: (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
Error logging capability: (0x01) Error logging supported.
General Purpose Logging supported.
Short self-test routine
recommended polling time: ( 1) minutes.
Extended self-test routine
recommended polling time: ( 214) minutes.
Conveyance self-test routine
recommended polling time: ( 2) minutes.
SCT capabilities: (0x103f) SCT Status supported.
SCT Error Recovery Control supported.
SCT Feature Control supported.
SCT Data Table supported.
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 111 099 006 Pre-fail Always – 36947726
3 Spin_Up_Time 0x0003 095 095 000 Pre-fail Always – 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always – 234
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always – 0
7 Seek_Error_Rate 0x000f 067 060 030 Pre-fail Always – 5348086
9 Power_On_Hours 0x0032 089 089 000 Old_age Always – 10081
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always – 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always – 111
183 Runtime_Bad_Block 0x0032 030 030 000 Old_age Always – 70
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always – 0
188 Command_Timeout 0x0032 100 093 000 Old_age Always – 10
189 High_Fly_Writes 0x003a 100 100 000 Old_age Always – 0
190 Airflow_Temperature_Cel 0x0022 065 059 045 Old_age Always – 35 (Min/Max 25/37)
194 Temperature_Celsius 0x0022 035 041 000 Old_age Always – 35 (0 22 0 0 0)
195 Hardware_ECC_Recovered 0x001a 030 028 000 Old_age Always – 36947726
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always – 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline – 0
199 UDMA_CRC_Error_Count 0x003e 200 199 000 Old_age Always – 66
240 Head_Flying_Hours 0x0000 100 253 000 Old_age Offline – 258170484172838
241 Total_LBAs_Written 0x0000 100 253 000 Old_age Offline – 1965397429
242 Total_LBAs_Read 0x0000 100 253 000 Old_age Offline – 943470985
SMART Error Log Version: 1
No Errors Logged
SMART Self-test log structure revision number 1
No self-tests have been logged. [To run self-tests, use: smartctl -t]
SMART Selective self-test log data structure revision number 1
SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS
1 0 0 Not_testing
2 0 0 Not_testing
3 0 0 Not_testing
4 0 0 Not_testing
5 0 0 Not_testing
Selective self-test flags (0x0):
After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.
[root@mbpc log]#
The array also shows the disk in degraded mode:
[root@mbpc log]# mdadm –detail /dev/raidmd0
/dev/raidmd0:
Version : 1.2
Creation Time : Mon Mar 26 00:06:24 2012
Raid Level : raid6
Array Size : 3907045632 (3726.05 GiB 4000.81 GB)
Used Dev Size : 976761408 (931.51 GiB 1000.20 GB)
Raid Devices : 6
Total Devices : 6
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Sun Jul 21 19:49:28 2013
State : active, degraded
Active Devices : 5
Working Devices : 5
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
Name : mbpc:0 (local to host mbpc)
UUID : 2f36ac48:5e3e4c54:72177c53:bea3e41e
Events : 19746
Number Major Minor RaidDevice State
0 8 64 0 active sync /dev/sde
1 8 32 1 active sync /dev/sdc
2 8 16 2 active sync /dev/sdb
3 8 48 3 active sync /dev/sdd
4 0 0 4 removed
5 8 0 5 active sync /dev/sda
4 8 80 – faulty spare /dev/sdf
[root@mbpc log]#
[root@mbpc log]#
[root@mbpc log]# ls -al /dev/rsd*
lrwxrwxrwx. 1 root root 3 Jul 19 15:52 /dev/rsda -> sde
lrwxrwxrwx. 1 root root 3 Jul 19 15:52 /dev/rsdb -> sdc
lrwxrwxrwx. 1 root root 3 Jul 19 15:52 /dev/rsdc -> sdb
lrwxrwxrwx. 1 root root 3 Jul 19 15:52 /dev/rsdd -> sdd
lrwxrwxrwx. 1 root root 3 Jul 19 15:52 /dev/rsde -> sdf
lrwxrwxrwx. 1 root root 3 Jul 19 15:52 /dev/rsdf -> sda
[root@mbpc log]#
The other disks pass with no errors (A sanity check to ensure we're not loosing another one):
[root@mbpc log]# smartctl -A /dev/rsda|grep -Ei "error|bad"
1 Raw_Read_Error_Rate 0x000f 120 099 006 Pre-fail Always – 239444191
7 Seek_Error_Rate 0x000f 068 060 030 Pre-fail Always – 6491443
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always – 0
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always – 0
[root@mbpc log]# smartctl -A /dev/rsdb|grep -Ei "error|bad"
1 Raw_Read_Error_Rate 0x000f 118 099 006 Pre-fail Always – 194771007
7 Seek_Error_Rate 0x000f 067 060 030 Pre-fail Always – 5868122
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always – 0
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always – 0
[root@mbpc log]# smartctl -A /dev/rsdc|grep -Ei "error|bad"
1 Raw_Read_Error_Rate 0x000f 117 092 006 Pre-fail Always – 155397639
7 Seek_Error_Rate 0x000f 067 060 030 Pre-fail Always – 5801960
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always – 0
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always – 0
[root@mbpc log]# smartctl -A /dev/rsdd|grep -Ei "error|bad"
1 Raw_Read_Error_Rate 0x000f 118 099 006 Pre-fail Always – 183790403
7 Seek_Error_Rate 0x000f 068 060 030 Pre-fail Always – 6662630
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always – 0
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always – 0
[root@mbpc log]# smartctl -A /dev/rsde|grep -Ei "error|bad"
1 Raw_Read_Error_Rate 0x000f 111 099 006 Pre-fail Always – 36947726
7 Seek_Error_Rate 0x000f 067 060 030 Pre-fail Always – 5348086
183 Runtime_Bad_Block 0x0032 030 030 000 Old_age Always – 70
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
199 UDMA_CRC_Error_Count 0x003e 200 199 000 Old_age Always – 66
[root@mbpc log]# smartctl -A /dev/rsdf|grep -Ei "error|bad"
1 Raw_Read_Error_Rate 0x000f 111 099 006 Pre-fail Always – 38940112
7 Seek_Error_Rate 0x000f 068 060 030 Pre-fail Always – 6748709
183 Runtime_Bad_Block 0x0032 100 100 000 Old_age Always – 0
184 End-to-End_Error 0x0032 100 100 099 Old_age Always – 0
191 G-Sense_Error_Rate 0x0032 100 100 000 Old_age Always – 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always – 0
[root@mbpc log]#
The -a option to smartctl is particularly useful. It prints virtually everything, including the serial number that we'll find at the front of the disk. This is how we'll know which disk to pull to take out of the system. In our case, because the HTPC is lying on it's side, we'll need to shut down the system, however this can be done easily enough while the system was online as we did earlier in our HTPC setup and configuration. First we'll remove the disk from the array like this:
[root@mbpc log]# mdadm –manage /dev/raidmd0 –remove /dev/rsde
mdadm: hot removed /dev/rsde from /dev/raidmd0
[root@mbpc log]#
Next, now that it's away from the array, we will analyze it further to test for suitability and if we need to RMA it (Note, we would not fail the device like this mdadm –manage /dev/raidmd0 –fail /dev/sdc because it's already in a failed state). We'll do the check in a non destructive way (This will take some time):
badblocks: Input/output error during test data write, block 576
badblocks: Input/output error during test data write, block 768
badblocks: Input/output error during test data write, block 1152
badblocks: Input/output error during test data write, block 1984
badblocks: Input/output error during test data write, block 3520
This is right off the start so definitely doesn't look good for the rest of the disk at this point. (Looks like we'll need to RMA this thing after all). We'll let that process run through to find out how bad this drive has turned out to really be (We're still at 0.00% at this point and 4:15 minutes have passed). While this was going on, we are referencing our HTPC page for commands. Fast forward one hour. After about:
0.01% done, 1:16:03 elapsed
The number of bad block sectors was:
[root@mbpc ~]# cat badblocks-Jun-21-2013.8.43PM|grep badblocks|wc -l
241
[root@mbpc ~]#
So needless to say, this wasn't going to look any better at the end either. So we'll pop in a new disk and let the array resync. We'll analyze this disk at a deeper level to see if any of the bad blocks can be recovered or not but we do not want to stop the array from syncing. Before we add the new disk in, we'll read in the serial number and reset ouf UDEV rules so it will be picked up automatically. In this case, we'll just use the short version and only plug in the serial number:
# SUBSYSTEM=="block",ACTION=="add",ENV{DEVTYPE}=="disk",PROGRAM="scsi_id –whitelisted –replace-whitespace -p0x80 -d$tempnode",RESULT=="?*",ENV{ID_SCSI_COMPAT}="$result",ENV{ID_SERIAL_SHORT}=="Z240QTB6",SYMLINK+="rsde"
And that should do it for UDEV (I've made the rest of the disk links simpler too and used the ID_SERIAL_SHORT ENV variable as well. Then triggered a refresh using udevadm trigger from the CLI).
[root@mbpc ~]# ls -altri /dev/rsde
107554 lrwxrwxrwx. 1 root root 3 Jul 21 23:03 /dev/rsde -> sdf
[root@mbpc ~]#
Now to add the drive back into the array using the rsde symlink.
[root@mbpc ~]# mdadm –add /dev/raidmd0 /dev/rsde
mdadm: added /dev/rsde
[root@mbpc ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid6 sdf[6] sdd[3] sdb[2] sdc[1] sda[5] sde[0]
3907045632 blocks super 1.2 level 6, 64k chunk, algorithm 2 [6/5] [UUUU_U]
[>………………..] recovery = 0.0% (182656/976761408) finish=801.9min speed=20295K/sec
bitmap: 6/8 pages [24KB], 65536KB chunk
unused devices: <none>
[root@mbpc ~]#
Dont' forget to set the write cache to OFF:
[root@mbpc ~]# hdparm -W 0 /dev/rsde;
/dev/rsde:
setting drive write-caching to 0 (off)
write-caching = 0 (off)
[root@mbpc ~]# for rdn in $(ls /dev/rsd*); do hdparm -I $rdn|grep -i "write cache"; done
Write cache
Write cache
Write cache
Write cache
Write cache
Write cache
[root@mbpc ~]#
And you're done. Wait until the array rebuilds and you're back in 100% active mode:
[root@mbpc ~]# mdadm –detail /dev/raidmd0
/dev/raidmd0:
Version : 1.2
Creation Time : Mon Mar 26 00:06:24 2012
Raid Level : raid6
Array Size : 3907045632 (3726.05 GiB 4000.81 GB)
Used Dev Size : 976761408 (931.51 GiB 1000.20 GB)
Raid Devices : 6
Total Devices : 6
Persistence : Superblock is persistent
Intent Bitmap : Internal
Update Time : Sun Jul 21 23:12:18 2013
State : active, degraded, recovering
Active Devices : 5
Working Devices : 6
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
Rebuild Status : 0% complete
Name : mbpc:0 (local to host mbpc)
UUID : 2f36ac48:5e3e4c54:72177c53:bea3e41e
Events : 19790
Number Major Minor RaidDevice State
0 8 64 0 active sync /dev/sde
1 8 32 1 active sync /dev/sdc
2 8 16 2 active sync /dev/sdb
3 8 48 3 active sync /dev/sdd
6 8 80 4 spare rebuilding /dev/sdf
5 8 0 5 active sync /dev/sda
[root@mbpc ~]#
And last but not least, set the max_sectors_kb:
for mskb in $(ls -al /dev/rsd*|awk '{ print $NF }'); do echo 8192 > /sys/block/$mskb/queue/max_sectors_kb; done
Hope this was helpful. Feel free to drop us a line.
Cheers,
TK