Ny way to prevent a bad drive from disappearing from /dev

badblocksblock-devicedevicespartitionudev

I'm trying to recover a partition on a bad drive with ddrescue. I run:

$ sudo ddrescue -r -1 -v /dev/sdd3 OUT.img dd_rescue_logfile

and it seems to do great for a while, but after about an hour, the "current rate" drops to zero because the drive disappeared from /dev. To bring the drive back, the only thing I can think of is to reboot the system and run the ddrescue command to resume from where I left off. This makes it very difficult to run the program, as I can't just leave it and forget it for a few days – I have to constantly monitor it to make sure the disk didn't disappear. I have seen this behavior on both Arch linux, and Fedora 22.

I assume that at some point, the kernel has trouble accessing the drive and removes it from /dev. Is there any way to avoid this? To tell the kernel to keep the device there even if it looks like it's broken or non-existent?

Best Answer

You might be able to re-detect it without reboot, by unloading / re-loading the correct module (or just un-binding and re-binding the driver).

For example:

[  978.527221] sd 11:0:0:1: [sdk] Attached SCSI removable disk
#~> echo 11:0:0:1 > /sys/bus/scsi/drivers/sd/unbind
#~> echo 11:0:0:1 > /sys/bus/scsi/drivers/sd/bind
[ 5572.027119] sd 11:0:0:1: [sdk] Attached SCSI removable disk

Or if that does not work and you have no other devices hooked to the same controller, you could unbind and bind the entire controller for example via /sys/bus/pci/drivers/ahci/ if it's AHCI.

I don't have any defective HDD to test if it would actually work, but I used this method before to force re-detection of MicroSD/MMC cards in slots that were not hot-pluggable by default.

As for ddrescue dropping speed to zero, you might want to see if it supports the -a, --min-read-rate=<bytes> option so it would hopefully? consider slow regions as defective and skip them. Worst case you'll have to monitor the disk from the outside and forcibly restart ddrescue.

Related Question