• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

AUTHORSH A D27-Jul-2013319 106

COPYINGH A D25-Sep-201117.6 KiB341281

ChangeLogH A D25-Sep-2011366 117

INSTALLH A D25-Sep-20119.3 KiB237179

Makefile.amH A D25-Sep-201197 62

Makefile.inH A D27-Jul-201320.8 KiB661571

NEWSH A D27-Jul-2013690 2115

READMEH A D25-Sep-201110.1 KiB235189

aclocal.m4H A D27-Jul-201334.5 KiB984881

config.h.inH A D27-Jul-2013923 3725

configureH A D27-Jul-2013173.1 KiB6,0264,972

configure.inH A D27-Jul-2013159 108

depcompH A D25-Sep-201115.6 KiB531330

hdrecover.cppH A D03-May-20229 KiB342277

install-shH A D25-Sep-20119 KiB324189

missingH A D25-Sep-201110.8 KiB361268

README

1hdrecover
2---------
3
4Attempts to recover a hard disk that has bad blocks on it.
5
6WARNING: A hard disk with bad blocks on it is likely to fail! If you
7value your data you should get a new hard disk instead of using this
8program!
9
10However, if you can't afford a new hard disk, or just like being
11reckless with your data then this tool might just help you out!
12
13Requirements:
14
15* A 2.6 kernel
16* A dead hard drive (well one with bad blocks - not completely dead)
17* smartmontools is handy although not strictly needed
18* root access
19
20When to use:
21
22First of all, if you haven't already got it - go download
23smartmontools! (http://smartmontools.sf.net). Then run:
24
25    smartctl -A /dev/hda
26
27Where hda is whichever drive you're interested in. The output should
28include three attributes that are interesting:
29
30* Reallocated_Event_Count
31
32  This is how many sectors have already been reallocated on the
33  drive. We're hoping to get the hard disk to increase this number!
34
35* Current_Pending_Sector
36
37  The number of sectors that the drive thinks are dodgy. Bear in mind
38  sometimes drives change their mind about whether a sector is bad or
39  not - so this number can go down without a reallocation occuring.
40
41* Offline_Uncorrectable
42
43  This is the number of sectors that the drive has attempted to
44  correct itself, but failed. Running the command:
45
46      smartctl -t offline /dev/hda
47
48  should cause the drive to test the sectors and attempt to fix
49  them. Not all drives support this though.
50
51So the attribute you're interested in at the moment is
52Current_Pending_Sector. If this is not 0 then there's something up
53with your disk. If Offline_Uncorrectable is less than
54Current_Pending_Sectors then you may want to run an offline test which
55may fix it, or you can dive straight in and use hdrecover which will
56test (and attempt to fix) it itself.
57
58So run (as root):
59
60    hdrecover /dev/hda
61
62and sit back and wait (or probably you're best off going and doing
63something else while you wait). If the program comes across a bad
64sector it will make several attempts at reading the sector. Between
65each attempt it will randomly seek so as to reposition the head,
66hopefully getting the data off the disk. If it succeeds then the drive
67should automatically reallocate the sector. If after several attempts
68the data still can't be read then the program will give you the option
69of overwriting the data in the sector. This will force the drive to
70reallocate the block.
71
72WARNING: Overwriting the sector WILL cause data loss (it's fairly
73obvious really!). Hopefully, since it is only one sector (or a handful
74if there are more bad sectors on the drive), it won't be too
75important. But bear in mind that you should at the very least run fsck
76to check the integrity of the filesystem.
77
78Once the program has finished (it takes a long time I'm afraid), a
79summary will be printed showing how many blocks had errors. If you
80repeat the smartctl command:
81
82    smartctl -A /dev/hda
83
84you should see that Current_Pending_Sector is now 0 and
85Reallocated_Event_Count will have risen by the number of sectors the
86drive decided to reallocate. Offline_Uncorrectable usually doesn't
87immediately update - you have to either wait for the drive to update
88it itself or run an offline test which should force the drive to
89update it.
90
91Have fun!
92
93DISCLAIMER: Hard disks with bad sectors could fail at anytime -
94although hdrecover appears to fix the drive you shouldn't trust it!
95And just to re-inforce the GPL licence: if it in any way breaks your
96computer then you get to keep both pieces! I accept no responsibility
97for any damage it causes!
98
99-------------------------------------------------------------------------------
100
101Sample run:
102
103SMART attribute table before:
104
105SMART Attributes Data Structure revision number: 11
106Vendor Specific SMART Attributes with Thresholds:
107ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
108  1 Raw_Read_Error_Rate     0x0029   100   100   020    Pre-fail  Offline      -       0
109  3 Spin_Up_Time            0x0027   064   063   020    Pre-fail  Always       -       4623
110  4 Start_Stop_Count        0x0032   096   096   008    Old_age   Always       -       2882
111  5 Reallocated_Sector_Ct   0x0033   099   099   020    Pre-fail  Always       -       5
112  7 Seek_Error_Rate         0x000b   100   093   023    Pre-fail  Always       -       0
113  9 Power_On_Hours          0x0012   080   080   001    Old_age   Always       -       13227
114 10 Spin_Retry_Count        0x0026   100   100   000    Old_age   Always       -       0
115 11 Calibration_Retry_Count 0x0013   100   090   020    Pre-fail  Always       -       0
116 12 Power_Cycle_Count       0x0032   097   097   008    Old_age   Always       -       1993
117 13 Read_Soft_Error_Rate    0x000b   100   093   023    Pre-fail  Always       -       0
118194 Temperature_Celsius     0x0022   078   073   042    Old_age   Always       -       57
119195 Hardware_ECC_Recovered  0x001a   100   100   000    Old_age   Always       -       295108
120196 Reallocated_Event_Count 0x0010   099   099   020    Old_age   Offline      -       1
121197 Current_Pending_Sector  0x0032   100   099   020    Old_age   Always       -       1
122198 Offline_Uncorrectable   0x0010   100   092   000    Old_age   Offline      -       0
123199 UDMA_CRC_Error_Count    0x001a   156   156   000    Old_age   Always       -       44
124
125Notice there is 1 Current_Pending_Sector. Running hdrecover /dev/hdb
126(it happens to be the second IDE drive):
127
128# hdrecover /dev/hdb
129hdrecover version 0.2
130By Steven Price
131
132Disk is 156355584 sectors big
133Sector 28000 (00%) ETR: 1 hours 33 minutes 3 seconds
134Sector 75920 (00%) ETR: 1 hours 8 minutes 36 seconds
135Sector 121520 (00%) ETR: 1 hours 4 minutes 16 seconds
136Sector 169400 (00%) ETR: 1 hours 1 minutes 27 seconds
137Sector 217120 (00%) ETR: 59 minutes 55 seconds
138Failed to read block at sector 257500, investigating futher...
139Error at sector 257505
140Attempting to pounce on it...
141Attempt 1 from sector    117727958: FAILED
142Attempt 2 from sector    149263364: FAILED
143Attempt 3 from sector     84429675: FAILED
144Attempt 4 from sector     81160097: FAILED
145Attempt 5 from sector    156272094: FAILED
146Attempt 6 from sector     75028634: FAILED
147Attempt 7 from sector     63238892: FAILED
148Attempt 8 from sector    116585171: FAILED
149Attempt 9 from sector    102184049: FAILED
150Attempt 10 from sector      5777672: FAILED
151Attempt 11 from sector     81154822: FAILED
152Attempt 12 from sector     69534256: FAILED
153Attempt 13 from sector     90633165: FAILED
154Attempt 14 from sector    150946922: FAILED
155Attempt 15 from sector     18909543: FAILED
156Attempt 16 from sector     29845152: FAILED
157Attempt 17 from sector     24976866: FAILED
158Attempt 18 from sector     52496797: FAILED
159Attempt 19 from sector    104093022: FAILED
160Attempt 20 from sector    127778471: FAILED
161Couldn't recover sector
162The data for this sector could not be recovered. However, destroying the
163contents of this sector (ie writing zeros to it) should cause the hard disk
164to reallocate it making the drive useable again
165Do you want to destroy the sector? [y/n]:
166
167
168/---------\
169| WARNING |
170\---------/
171
172Up until this point you haven't lost any data because of this program
173However, if you say yes below YOU WILL LOSE DATA!
174Proceed at your own risk!
175
176Type 'destroy data' to continue
177destroy data
178
179Wiping sector...
180Checking sector is now readable...
181Sector is now readable. But you have lost data!
182Sector 257520 (00%) ETR: 30 hours 58 minutes 53 seconds
183Sector 290700 (00%) ETR: 27 hours 35 minutes 18 seconds
184
185... (loads more status info) ...
186
187Sector 156197020 (99%) ETR: 3 seconds
188Sector 156242080 (99%) ETR: 2 seconds
189Sector 156287080 (99%) ETR: 1 seconds
190Sector 156332200 (99%) ETR: 0 seconds
191Summary:
192  1 bad sectors found
193  of those 0 were recovered
194  and 1 could not be recovered and were destroyed causing data loss
195
196*****************************************
197* You have wiped a sector on this disk! *
198*****************************************
199*  If you care about the filesystem on  *
200*  this disk you should run fsck on it  *
201*  before mounting it to correct any    *
202*  potential metadata errors            *
203*****************************************
204#
205
206So the sector had to be wiped to recover it. fsck was then run to
207check the metadata wasn't damaged (it wasn't) and smartctl now returns
208the following attribute table:
209
210SMART Attributes Data Structure revision number: 11
211Vendor Specific SMART Attributes with Thresholds:
212ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
213  1 Raw_Read_Error_Rate     0x0029   100   100   020    Pre-fail  Offline      -       0
214  3 Spin_Up_Time            0x0027   064   063   020    Pre-fail  Always       -       4623
215  4 Start_Stop_Count        0x0032   096   096   008    Old_age   Always       -       2882
216  5 Reallocated_Sector_Ct   0x0033   099   099   020    Pre-fail  Always       -       5
217  7 Seek_Error_Rate         0x000b   100   093   023    Pre-fail  Always       -       0
218  9 Power_On_Hours          0x0012   080   080   001    Old_age   Always       -       13227
219 10 Spin_Retry_Count        0x0026   100   100   000    Old_age   Always       -       0
220 11 Calibration_Retry_Count 0x0013   100   090   020    Pre-fail  Always       -       0
221 12 Power_Cycle_Count       0x0032   097   097   008    Old_age   Always       -       1993
222 13 Read_Soft_Error_Rate    0x000b   100   093   023    Pre-fail  Always       -       0
223194 Temperature_Celsius     0x0022   078   073   042    Old_age   Always       -       57
224195 Hardware_ECC_Recovered  0x001a   100   100   000    Old_age   Always       -       295108
225196 Reallocated_Event_Count 0x0010   099   099   020    Old_age   Offline      -       1
226197 Current_Pending_Sector  0x0032   100   099   020    Old_age   Always       -       0
227198 Offline_Uncorrectable   0x0010   100   092   000    Old_age   Offline      -       0
228199 UDMA_CRC_Error_Count    0x001a   156   156   000    Old_age   Always       -       44
229
230Current_Pending_Sector is now 0 so the drive is 'fixed' (for
231now). Also note that Reallocated_Event_Count hasn't gone up (it was 1
232before). This means that the drive now has confidence in the sector
233that has been overwritten and has not used a spare sector. Whether you
234still have confidence in the drive is another matter!
235