How to recover data from dying hard drive that constantly disconnects on linux
I have an external USB hard drive that's in the process of dying.
I'm trying to use Linux Mint Cinnamon 20 to recover the files, just by cutting and pasting them. However, every ~30 seconds or so the drive will stop showing up, and the operation will fail. If I disconnect the cable and reconnect it the drive will show up once more and the operation will continue. This happens with known good cables.
Any suggestions for how best to get the data off this drive, without sitting there and disconnecting and reconnecting the cable every 30 seconds for 10 hours? I'm open to trying different distros, or performing a clone of the disk if either of these would work better.
11 Answer
Obviously paid recovery services are the best option, they can replace the motor and any other failed components.
So it is going to take some experimentation but since paid recovery doesn't sound like an option try this.
Sounds like the hardware is failing you can't fix that your going to have to accept some amount of tedious into this process. It could be the hard drives motor failing, in which case changing that is beyond 90% of peoples skill set.
You will need an output device larger than the source.
The only way to automate this is if you have an controlled outlet strip that you can periodically have a script turn OFF and ON with the hard drive on a separate power supply plugged into said outlet strip.
I am sure other brands of outlet strip might be able to do it, but I know for sure the kasa hs300 ($69.99 - $89.99 depending on the store and sale prices) has a python API on github () that can control there outlet strip from within linux. I have done it, but not for this purpose.
So basically if you put the hard drive in an external usb chassis then an outlet strip could be used to automatically turn it OFF and ON to wake it up for 30 more seconds. However, I don't know if your ready for this kind of complexity.
You could try ddrescue
ddrescue -d -r3 /dev/sda test.img test.logfileHowever, the hard drive will stop working every 30 seconds, and it will still have to be unplugged and re plugged every 30 seconds.
or
dd bs=512 if=/dev/sda of=/location/of/output/drv.img count=1000Ok so now you have the first 1000 sectors.
dd bs=512 if=/dev/sda of=/location/of/output/drv.img count=1000 -skip=1000 seek=1000So "skip" should skip the first 1000 sectors you already have. "seek" advances the start position in the output file.
So now you just have to keep advancing the skip and seek values by the same factor as the count value.
dd bs=512 if=/dev/sda of=/location/of/output/drv.img count=1000 -skip=2000 seek=2000
dd bs=512 if=/dev/sda of=/location/of/output/drv.img count=1000 -skip=3000 seek=3000
dd bs=512 if=/dev/sda of=/location/of/output/drv.img count=10000 -skip=4000 seek=4000
dd bs=512 if=/dev/sda of=/location/of/output/drv.img count=10000 -skip=14000 seek=14000You can experiment with larger and larger count,skip,seek values to reduce the time it takes.
Basically you need to reach the maximum number of sectors you can read in 30 seconds (the fail time). Then keep reading it in, in blocks of that size.
Eventually you will have your entire drive imaged.
then you can mount the image
mkdir /mnt/whatever
mount -o loop /blah.img /mnt/whateverThen copying your files off is easy.
5