Easy disk recovery


I have some really old hard drives in my PC. There was a power failure, and when I booted up my PC again, I instantly heard the click of death. Not a good sign. Also, I couldn’t access the drive at all. I checked dmesg, and yeah, my shitty Seagate HDD was really dead.

Luckily, I had two new and unused 6TB Toshiba hard drives in storage.

Prepare new hard drive

I plugged in the new drive and create a new ext4 file system on it.

# mkfs.ext4 /dev/sdY

Next, I created a directory to mount it.

# mkdir /mnt/cool-name

and then mounted it.

# mount /dev/sdY /mnt/cool-name

That worked - I could see it, but I couldn’t create any files on this file system. The root user was being mean… Here’s how I fixed it:

# chmod o+w /mnt/cool-name

Much better.

ddrescue to the rescue

I followed the instructions on the ArchWiki Disk Cloning page.

Well, with one small alteration, it was not clear to me where the rescue.map file was stored, so I explicitly stored it in the /root/ directory.

I first cloned every block that did not have read errors.

# ddrescue --force -n /dev/sdX /dev/sdY /root/rescue.map

This took about 5 hours on my 2TB drive. You can pause this with Ctrl+C and then resume later by running the same command again. Using the rescue.map file, it will continue where it left off. I tested this multiple times.

Once that was done, I needed to copy all the faulty blocks.

# ddrescue --force -d -r3 -n /dev/sdX /dev/sdY /root/rescue.map

This didn’t take long at all for me, since it was comprised of only 0.01% of the remaining blocks.

Finally I ran fsck on the new partition to fix any corruption issues.

# fsck -f /dev/sdY

This also didn’t take long.

Final touches

Because the old partition was cloned onto the new one, the partition label and various metadata all get applied to the partition on the new hard drive.

To change the label of the new partition without formatting it, I needed to do the following:

sudo e2label /dev/sdY cool-name

where “cool-name” was the new label for your partition.

Then I resized the file system to fit to the size of the new disk.

sudo resize2fs /dev/sdY

Finally, I added this new partition as an entry on my /etc/fstab config to mount it to /mnt/cool-name on startup. And with that, I was done.

ddrescue did a great job, and I got all my files back from a completely useless hard drive that will soon have its platters become intimately familiar with an industrial-strength drill.