Linux Commands

DDRescue Command in Linux

The ddrescue package in the Linux operating system is a data recovery tool that is used to store the data from a crashed partition. It clones the data from an input device that is being corrupted and about to stop responding. It automatically copies the data from an input drive and saves it to another drive. The dd part in the ddrescue command creates an image backup of a partition or a drive. We will demonstrate the usage of the ddrescue package and command in the Ubuntu 22.04 system in this article.

How to Install the DDRescue Package in Ubuntu 22.04

The simplest way to install the ddrescue package in Ubuntu 22.04 is to use the apt or apt-get install command. Just update the repository of the apt or apt-get commnand and install the ddrescue package in the usual way. The following install gddrescue command allows you to install the gddrescue package in the Linux operating system:

Note that we installed the gddrescue instead of ddrescue. The gddrescue is the GNU version of the ddrescue that provides the /sbin/ddrescue executable. Hence, to install the ddrescue, the gddrescue package name is used. To execute the command, the ddrescue name is used. Find the following output of the install gddrescur command:

As you can see, the gddrescue package is installed successfully. Your system is ready to execute the ddrescue command.

Check the Manual of the DDRescue Command

When you use the ddrescue command for the first time, you may get confused as you are not familiar with it completely. The manual of the ddrescue allows you to understand it and get familiar with it. Refer to it when you need help. To get the manual page of the ddrescue package, you can use the following command:

Here is the manual page:




List the Available Devices to be Mounted

The available devices or the block devices can be displayed using the lsblk -e7 command. It displays all the available block devices excluding the RAM disks in a tree-like format. See the following command:

When you execute this command, you will get a tree-like formatted list of the block devices. See the list in the following illustration:

Here, you can see the subsequent parts of /sda disk in the tree-like format. From this list, you can determine which is your running Linux drive. If you do not understand from this list, you can unplug all your devices and connect them one by one and understand what device refers to what drive.

Recreate the Rescue File from the DDRescue Command

The main function of the ddrescue command is to clone a drive and recover the data from a corrupted device. Let us recreate the rescue file using the ddrescue command. The best and optimal way to save your data is to make a clone of the affected drive just before the drive completely becomes unresponsive. In such situations, the ddrescue command is frequently used to clone the hard drives since it is a free, useful, and powerful data recovery utility available in the Linux operating system. The best thing about the ddrescue command which makes it better than any other data recovery tool is that it does not write zeros to the output file or truncate files and fill in the bad sectors successively which were missed in earlier passes. The syntax of the ddrescue command is as follows:

Here, the ddrescue is the command name that performs the main function. The -option refers to the list of options available for the ddrescue command and is commonly known as flags. The “in-file” refers to the input file that needs to be cloned.  The “out-file” refers to the file where the input data will be cloned. And lastly, the “log-file” is used to store the logs of the cloning. Here is the actual sample command that recreates a rescue file by the ddrescue command. This is the first command that starts the process:

When you run this command, the following output is produced:

The second command is as follows:

Here, we use the -f and -n flag with the ddrescue command. The -f flag is used to make the ddrescue command overwrite the output partition. And the -n flag is used to make the ddrescue command not attempt to split or retry the failed blocks. The following result is what you will get when you execute this command:

Now, get a direct access to the input file using the -d flag. Also, use the -r3 flag to enforce the exit after 3 retries. To take the infinity retries, use -1.

Look at the following output:

The next step is to force check if the filesystem is marked clean or not:

Look at the following output:

Reread the rescued file from the /mnt drive:

List all the rescued files with the following command:

The result is given in the following:

Now, copy all the rescued files using the rsync:

Here is the process of copying the files:

How to Uninstall the DDRescue Package from Ubuntu 22.04

To uninstall the ddrescue package, you need to use the “remove” command. To uninstall the ddrescue package, data, dependencies, and all of its configurations, use the following command at once:

Notice that everything related to the ddrescue package is removed from the system:

Important Points to Remember

When you attempt to use the ddrescue file to rescue a damaged file, make sure that you follow the process safely. Keep the following points in your mind so that you can safely execute the complete process:

  • Make sure to use a logfile to resume a rescue.
  • Never execute a ddrescue command on a write/read mounted partition.
  • A drive with I/O errors should not be used to repair a file system.
  • The data on the destination drive will be overwritten when you make a clone. Be careful with your data and ensure that you do not have some important data in that device.

Conclusion

We explored the ddrescue command in this article. We learned how to install it in the Ubuntu 22.04 system and how to use it in our Linux operating system. We also learned how to clone a drive into another device while making a log file with the help of an example. Follow the example whenever you need to make a clone of the drive.

About the author

Omar Farooq

Hello Readers, I am Omar and I have been writing technical articles from last decade. You can check out my writing pieces.