ddrescue To The Rescue!

Ronald Farrer
4 min readJun 5, 2023
Photo by Vincent Botta on Unsplash

If you’re dealing with a failing hard drive and need to recover important data, ddrescue can be a valuable tool to have in your toolkit. ddrescue is a data recovery tool designed to copy data from one file or block device to another while handling errors and bad sectors. In this article, we will guide you through how to use ddrescue to recover data from a failing hard drive.

Step 1: Install ddrescue The first step is to install ddrescue on your system. If you’re using a Linux-based system, you can install it using your system’s package manager. For example, on Ubuntu, you can install ddrescue by running the following command in your terminal:

sudo apt-get install gddrescue

On macOS, you can install ddrescue using Homebrew. To install Homebrew, run the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Once Homebrew is installed, you can install ddrescue by running the following command:

brew install ddrescue

Step 2: Connect the failing hard drive Connect the failing hard drive to your system. If you’re using a desktop computer, you can connect the hard drive using a SATA cable. If you’re using a laptop, you may need a USB to SATA adapter.

Step 3: Determine the device name of the hard drive To use ddrescue, you’ll need to determine the device name of the hard drive you want to recover data from. To do this, run the following command:

sudo fdisk -l

This will list all the connected storage devices on your system. Look for the device that corresponds to the failing hard drive. The device name will typically be something like /dev/sda or /dev/sdb.

Step 4: Create a destination image file Before you start the data recovery process, you’ll need to create a destination image file where ddrescue will copy the recovered data. To create a destination image file, run the following command:

sudo dd if=/dev/zero of=/path/to/destination/image bs=1M count=0 seek=SIZE

Replace “/path/to/destination/image” with the path where you want to save the destination image file. Replace “SIZE” with the size of the failing hard drive in bytes. You can use the following command to determine the size of the failing hard drive:

sudo blockdev --getsize64 /dev/sdX

Replace “/dev/sdX” with the device name of the failing hard drive.

Step 5: Run ddrescue Once you have created the destination image file, you can run ddrescue to recover the data from the failing hard drive. Run the following command:

sudo ddrescue -d -f -r3 /dev/sdX /path/to/destination/image /path/to/logfile

Replace “/dev/sdX” with the device name of the failing hard drive. Replace “/path/to/destination/image” with the path to the destination image file you created in step 4. Replace “/path/to/logfile” with the path where you want to save the log file.

The options used in the above command are:

  • “-d”: Direct input mode. This tells ddrescue to read the input file directly without using the system cache.
  • “-f”: Force overwrite mode. This tells ddrescue to overwrite the destination image file if it already exists.
  • “-r3”: Retry 3 times. This tells ddrescue to retry each sector up to 3 times before givingup.
  • “/dev/sdX”: The device name of the failing hard drive.
  • “/path/to/destination/image”: The path to the destination image file.
  • “/path/to/logfile”: The path where you want to save the log file.

Step 6: Monitor the progress ddrescue will start copying data from the failing hard drive to the destination image file. You can monitor the progress by running the following command:

sudo ddrescueview /path/to/logfile

This will open a graphical interface that displays the progress of the data recovery process. You can also use the following command to check the status of the data recovery process:

sudo ddrescue --show-progress /dev/sdX /path/to/destination/image /path/to/logfile

This will display the progress of the data recovery process in the terminal.

Step 7: Verify the recovered data Once ddrescue has completed the data recovery process, you should verify the recovered data to ensure that it’s intact. You can use the following command to verify the integrity of the destination image file:

sudo ddrescue -v --verify /dev/sdX /path/to/destination/image /path/to/logfile

This will compare the data on the failing hard drive with the data on the destination image file and report any errors.

Step 8: Mount the destination image file If the data recovery process was successful, you can mount the destination image file and access the recovered data. To mount the destination image file, run the following command:

sudo mount -o loop /path/to/destination/image /mnt/recovery

Replace “/path/to/destination/image” with the path to the destination image file. “/mnt/recovery” is the mount point where the destination image file will be mounted.

Conclusion Using ddrescue to recover data from a failing hard drive can be a time-consuming process, but it’s often the only way to recover important data from a damaged disk. With the help of this guide, you should be able to recover data from a failing hard drive using ddrescue. Remember to always backup your data regularly to avoid data loss in the event of a hardware failure.

I Love Coffee! https://ko-fi.com/canutethegreat

--

--