tl;dr note you can just skip to the script below if you want

This script uses ddrescue (the newer one between gddrescue and ddrescue, so it uses gddrescue – note gddrescues command is actually ‘ddrescue’ and ddrescues command is actually ‘dd_rescue’, so below we are using ‘ddrescue’ which means we are using gddrescue… thus the newer one). You will need gddrescue, a simple apt-get update; “apt-get install gddrescue” will get it.

I use two commands to clone the a drive, as recommended in their man page. First I clone the good sections (its a quick run thru). Then all of the bad areas get reported to a log file (the good areas get reported as well), then the second run thru tells it to retry once per trouble area.

For example if we have a bad drive /dev/sdb and we are copying to /dev/sdg which is the good drive. Imagine /dev/sdb has 50 realloacted sectors and like 2 ata errors (thus its about to die soon).

NOTE – HOW TO TELL IF A DRIVE IS BAD: I get my SMART/health data about the drive with smartctl “smartctl -a /dev/sdb” Im used to the thumb rule that if you have over 50 reallocated sectors OR 1 or more ATA errors then its time for a drive replacement. ALSO if you have a count of both current pending sectors and offline uncorrectable that keeps growing (or doesnt go away) then its time for a clone.

Before starting the clone I need to make sure that /dev/sdb and /dev/sdg are not mounted (so that they just dont get in the way during the clone – this is for logical reasons). Also for logical reasons you need to save the log somewhere safe (obviously it cant be on /dev/sdb and it cant be on /dev/sdg per the previous requirement). Note the log files dont get that big, they are never over a megabyte. If you want… You can tail the log file during a clone to see what I mean (That they dont get that big, you will see why), log files of gddrescue are just bitmaps of what range of sectors are good and bad as the recovery goes on.

ddrescue -n /dev/sdb /dev/sdg /root/b2g.log
ddrescue -r1 /dev/sdb /dev/sdg /root/b2g.log

If this command cries about the file being not regular, then add the -f argument for force.

ddrescue -fn /dev/sdb /dev/sdg /root/b2g.log
ddrescue -fr1 /dev/sdb /dev/sdg /root/b2g.log

NOTE: you can increase -r1 to 2 or 3 or whatever number you wish if you wish to retry more then once on a bad sector (realize that with -r1 the system would have already tried 3 times if it fails, once with -n, and once with -r1 before the retry event, and three times after the first and only retry event – so with -r2 you will actaully be trying the bad sector 4 times, and with -r3 you will be trying it 5 times)


The script speaks for it self in the comments


Leave a Reply

Your email address will not be published. Required fields are marked *