How to use the command ddrescue (with examples)
- Linux
- December 25, 2023
This article will guide you through two different use cases of the ddrescue
command, which is a data recovery tool that reads data from damaged block devices.
Use case 1: Take an image of a device, creating a log file
Code:
sudo ddrescue /dev/sdb path/to/image.dd path/to/log.txt
Motivation:
Taking an image of a device can be useful for various reasons, such as creating a backup or analyzing the data on the device without modifying it directly. By using ddrescue
to create an image, you can ensure that the process is resilient to read errors, making it suitable for damaged or faulty devices.
Explanation:
sudo
: This command is used to runddrescue
with elevated privileges. It might be necessary if you need to access certain devices that require administrative privileges./dev/sdb
: This is the source device from which we want to create an image. Replace/dev/sdb
with the appropriate device name on your system.path/to/image.dd
: This specifies the path and filename of the image file that will be created. Adjust the path and filename to your preference.path/to/log.txt
: This specifies the path and filename of the log file that will be created. The log file keeps track of the progress and any encountered errors during the process.
Example output:
GNU ddrescue 1.25
Press Ctrl-C to interrupt
ipos: 1024 KiB, non-trimmed: 0 B, current rate: 2048 B/s
opos: 1024 KiB, non-scraped: 0 B, average rate: 1239 B/s
non-tried: 0 B, errsize: 1024 KiB, run time: 33.70 s
rescued: 1024 KiB, bad sectors: 0, run timeout: 120.00 s
Use case 2: Clone Disk A to Disk B, creating a log file
Code:
sudo ddrescue --force --no-scrape /dev/sdX /dev/sdY path/to/log.txt
Motivation:
Cloning a disk can be useful when you want to duplicate the contents of one disk to another, such as when upgrading to a larger hard drive or replacing a faulty disk. With ddrescue
, you can clone the disk while avoiding known damaged areas and generating a log file for reference.
Explanation:
--force
: This option forcesddrescue
to overwrite the output disk, even if it contains important data. Use this option carefully, as it can result in data loss.--no-scrape
: This option tellsddrescue
not to attempt to rescue data from areas with read errors. By excluding these areas, you can avoid potential hangs or slowdowns during the cloning process./dev/sdX
: This is the source disk that you want to clone. Replace/dev/sdX
with the appropriate disk name on your system./dev/sdY
: This is the destination disk where the cloned contents will be written. Replace/dev/sdY
with the appropriate disk name on your system.path/to/log.txt
: This specifies the path and filename of the log file that will be created. The log file records the progress and any errors encountered during the cloning process.
Example output:
GNU ddrescue 1.25
Press Ctrl-C to interrupt
ipos: 1024 KiB, non-trimmed: 0 B, current rate: 2048 B/s
opos: 1024 KiB, non-scraped: 0 B, average rate: 1239 B/s
non-tried: 0 B, errsize: 1024 KiB, run time: 33.70 s
rescued: 1024 KiB, bad sectors: 0, run timeout: 120.00 s
Conclusion:
The ddrescue
command is a powerful tool for data recovery and disk cloning. By understanding its various options and use cases, you can efficiently recover data from damaged devices or clone disks while minimizing potential issues. Always use caution and double-check your device names and paths before executing the command, as incorrect usage may result in data loss.