How to restore data from a deleted or damaged hard drive

I'll explain how to copy a hard-disk, CD-ROM, etc., deleted or damaged, to another device (another hard drive), and to do this, we will use the GNU program, ddrescue and with losetup, we will mount it, on the hard disk where we have to take the copy.




The GNU Ddrescue programm, is a data recovery tool, which is usually used to copy data from a deleted or damaged hard drive to another, in order to rescue the information in case of read errors.

With the copy obtained, you can make another copy with the Mouse (copy + paste), so it allows you to recover deleted or damaged data of the copy and in case of error, you will only have to make a copy, from the original copy.


Here I will talk about how to install and use Ddrescue on Debian and its derivatives such as Ubuntu and Linux Mint.


Install Ddrescue, write in your Terminal

sudo apt-get install gddrescue


The ddrescue program is corporate in the gddrescue package. There is also the previous dd_rescue program (with the stripe down). Here we will use ddrescue, which has a much wide range of functions, in comparison to the old dd_rescue.


1- Search for devices which are currently connected to your machine


1- I will recommend your removing all USB device which connect to your computer.

2- I recommend using lsblk first without the hard drive (if it is an external hard drive) that you have deleted or is damaged, and then connect the hard drive or USB to the computer so that you will know the name given by lsblk, sdb, sdc, sdd ...

Open a Terminal, give the key combination

Ctrl + Alt + T


With the lsblk command show which devices are currently connected to your machine and so you'll know what name the damaged hard drive has.

show the devices that are connected to my computer

As seen in the image, my damaged external hard drive is sdb and sdb1 is the partition where my data was. Usually, with lsblk, sda is the hard drive where we are, sdb, sdc .. when we have more hard drives and USB sticks connected to the computer.




2- Unmount your hard disk damaged


Unmount the hard drive you deleted or is damaged. Disconnecting does not mean physically disconnecting our hard drive. What we do is eliminate the junction between our hard drive and the file system.

The command

sudo umount /dev/you hard disk

My damaged external hard drive is sdb, and the partition where the data was is sdb1, so the point where we have to unmount is sdb1..

sudo umount /dev/sdb1


3- Copy the damaged hard drive with ddrescue


Before you begin, you should to know the capacity of the damaged hard disk, in the previous step we to see that my hard drive sdb has a size of 14.3G, so, to avoid surprises, on the hard drive where you want to take the copy, it should have a minimum 10% more capacity. The formula for determining a percentage, p = the amount we have, multiply them by percent which we want to know and divide it by 100.

I have 14.3G, we multiply it by ten and divide it by 100. 14.3 x 10 = 143, 143/100 = 1.43 GB is the extra capacity I need. So the hard drive where I want to take it has to have a minimum capacity of 15.6 GB, 14.3 + 1.43 = 15.6 GB.


We connect the hard drive where we want to take the copy to our computer, and with lsblk, we will know the name it has.

to show the new device that is connected to my Computer

As seen in the picture, my new hard drive is sdc and has a capacity of 20 GB.

Now we know;

Now we are going to create an exact copy of our damaged hard disk, sdb, and we are going to take it to our new hard drive, sdc in the form .img off.

First, we copy each block without reading errors and create the log file, which will give us the opportunity in case we want to stop the copy process with, Ctrl + C
, to continue from where we stopped it, but to do this, we have to write on the Terminal, the same as when we stop it.

When you want to take the copy to a hard disk, use /dev/sd .., but when you want to make the copy to an external hard drive, you better use /media/username/UUID_hard_disk. When you want to copy a damaged CD-ROM or DVD, you can use these methods.


As I want to take the copy to an external hard drive, I will not use /dev/. I will use the UUID, which gives us lsblk, which is something similar to this
/media/linux/cfh201e9-c3bd-4517-75d9-862c547f26t8, which is different in each device.

With sudo, write in your terminal,

sudo ddrescue -f -n /dev/sdb /media/username/cfh201e9../copy.img /media/username/cfh201e9../copy.log

-f

Force ddrescue execution, even if the destination file already exists.

-n

Skip the split-phase to avoid wasting a lot of time trying to rescue the most complicated parts of a file.


If the hard drive is not badly damaged, with the first option, we will have a copy of our damaged hard drive, and with that copy, we can recover the data with TestDisk or another program.

Second, if on the contrary, the hard disk is very damaged, we will use this option, ddrescue will read three times (or as many times as you write), before making a copy of your damaged hard disk.

With sudo, write in your terminal,

sudo ddrescue -d -f -r3 /dev/sdb /media/username/cfh201e9../copy.img /media/username/cfh201e9../copy.log

-d

Use the shortcut in the input unit.

-f

Force ddrescue execution, even if the destination file already exists.

-r3

Read the sectors three times, before copying the hard drive.


4- Mount the image which you have copied


Now we are going to mount the copy of our hard disk, to do this, we will create an empty file in /mnt which use as a temporary mount point for devices.

Create the dir file in mnt

sudo mkdir /mnt/dir

See if you are using a Loop device

sudo losetup -f

If you not used any of them, it will show like /dev/loop0, which is the one we will use to associate with our image.

With losetup, we associate our loop0 with our image that we have copied from our damaged hard drive.

sudo losetup -P /dev/loop0 /address_image/copy.img

Mount the loop in the directory that acts as the mount point, which is /mnt/dir.

sudo mount /dev/loop0 /mnt/dir


5- Unmount


Now we are going to disassemble (unmount) the directory that acts as a mount point.

sudo umount /mnt/dir

Disconnect loop0

sudo losetup -d /dev/loop0


With this, you will have the copy of your damaged hard drive, and the image of it mounted, you need to restart the device.









You comment is welcome: