tilde-site/content/blog/2024-12-11-ddrescue.md

3.1 KiB
Raw Blame History

+++ title = "Introduction to ddrescue" date = "2024-12-11" updated = "2024-12-11" [extra] authors = ["Ydreniv"] +++

Lets suppose one of your friends come to you with a computer issue. Theyve got a failing hard drive, and want to recover the data stored on their device. They are quite worried, as they have important files on it, and its their only copy. Of course, this would never happen to you, because you keep multiple encrypted backups of all your data, in multiple place. Only a worldwide apocalypse would get you a dataloss. So this definitely could only happen to a friend, or a family member, but not you. It would be preposterous to think otherwise.

So anyway, you want to copy the hard-drive. You quickly plug it in your computer, mount it and open the file explorer. But the mount takes a long time, accessing the files is very slow, and copying them does not always work. Plus, the SMART statistics show that this drive has issues. How do you extract the important data then ? By the look of it, the vast majority of the drive sectors are fine, so what youre looking for still exists. Its merely hard to access. Its only a hardware problem.

If you manage to image the drive, you can then either use it as a mounted file, or burn it to another drive. You could use good old dd. Maybe this would work. But here, with your friends disk on its deathbed, youd like a tool adapted for this situation. Here comes… ddrescue.

ddrescue operates on unmounted devices, and will copy a device block by block. Even better, it has error handling integrated. When it cannot read a block, it will either retry or pass it, depending on the options youve selected. And, crucially, it can store its status in a file, meaning that if you stop the process, youll be able to resume it later. This way, you can quickly recover all easily available blocks, while still retaining the ability to do several passes on the failing ones.

Im still a novice in ddrescue, so read the Archlinux wiki page to get specific instructions. The Archlinux wiki is overall pretty good, and is one of my main source of help on Linux, even with other distributions. In my experiment, it has been able to recover all the disks sectors, except for 47 of them. I let it run for at least 50 hours I guess (I havent counted) over multiple sessions. I could probably try to make more passes, to eventually recover the full disk, but Im not sure its worth it (and even possible).

Its reassuring to know that Ive now safeguarded most of the data. Now that I have a mostly complete image, Ive started trying to read them. Unfortunately, the missing blocks do prevent me from simply mounting the resulting image. So Ive still gotta do some work to actually get what I wanted (copying the files to another drive), but at least I know that the current image is safe, and that there shouldnt be further data loss.

So if youre confronted with data recovery, I recommend giving ddrescue a look. Its quite a useful tool !