Faster Recovery from a Disk with Bad Sectors with ddrescue

7 minute read

If you’re dealing with a disk that has bad sectors and you want to recover data from it as quickly as possible using ddrescue, there are a few strategies you can employ to speed up the recovery process. ddrescue and dd are both powerful tools for disk imaging and data recovery, but they have different approaches and features that make ddrescue more suitable for scenarios where there are bad sectors on the disk. Here are some reasons why ddrescue is often considered better than dd for data recovery:

  1. Error handling: When dd encounters a read error on a disk, it immediately terminates the process, making it difficult to recover data from bad sectors. On the other hand, ddrescue is specifically designed for data recovery and employs sophisticated algorithms to handle read errors intelligently. It attempts to read the maximum amount of data from the disk, and if it encounters an error, it skips that region and continues with the rest of the disk. It also maintains a log file to keep track of the problematic areas and can retry reading from those regions later.

  2. Resumable recovery: ddrescue has a built-in resumable recovery feature. It creates a logfile that stores the information about the already recovered areas and the areas with errors. This allows you to pause and resume the recovery process at any time, without starting from the beginning. The logfile feature is particularly useful when dealing with disks that have extensive bad sectors or when the recovery process is time-consuming.

  3. Flexible recovery strategies: ddrescue offers various recovery strategies that you can employ depending on the nature of the disk and the errors encountered. You can prioritize recovering non-error areas first, or you can focus on areas with errors, trying different settings or approaches to improve the chances of successful recovery. These strategies make ddrescue more adaptable to different scenarios and increase the likelihood of recovering as much data as possible.

  4. Detailed status information: ddrescue provides more detailed status information during the recovery process compared to dd. It displays the current progress, the number of errors encountered, and the estimated time remaining. This information helps you monitor the recovery process and assess its progress.

While ddrescue has distinct advantages for data recovery from disks with bad sectors, it’s worth noting that dd is still a useful and versatile tool for disk imaging and copying. If you’re dealing with a disk without any read errors or if you simply need to create a bitwise copy, dd can be a suitable choice.

Let’s go through a basic example of using ddrescue to recover data from a disk with bad sectors. Here’s a step-by-step guide:

  1. Install ddrescue: If ddrescue is not already installed on your system, you can install it using the package manager specific to your operating system. For example, on Ubuntu, you can run sudo apt-get install gddrescue to install it.

  2. Identify the source and destination: Determine the disk or partition you want to recover data from (source) and the location where you want to save the recovered data (destination). Make sure you have enough free space on the destination disk.

  3. Create a logfile: Before starting the recovery process, it’s recommended to create a logfile. This will allow you to pause and resume the recovery if needed. You can create a logfile using the following command:
    ddrescue --generate-logfile=<logfile> <source> <destination>/dummyfile
    

    Replace <logfile> with the desired path and filename for the logfile, <source> with the path to the disk or partition you want to recover data from, and <destination> with the path to the directory where you want to save the logfile.

  4. Run ddrescue: Once the logfile is created, you can start the recovery process using the following command:
    ddrescue -f -n -r3 <source> <destination> <logfile>
    

    Replace <source> with the path to the disk or partition you want to recover data from, <destination> with the path to the directory where you want to save the recovered data, and <logfile> with the path to the logfile you created in the previous step.

    In this command, -f forces ddrescue to run even if the destination file already exists, -n skips scraping and avoids unnecessary retries, and -r3 specifies that ddrescue should retry failed blocks up to 3 times.

  5. Monitor the progress: ddrescue will start the recovery process and display progress information, including the current status, the number of errors encountered, and the estimated time remaining. You can monitor the progress and let the process run until completion.

  6. Resume or restart the recovery: If the recovery process is interrupted or you need to pause and resume it later, you can use the same command used in step 4. ddrescue will read the logfile and resume the recovery process from where it left off.

  7. Finalize the recovery: Once the recovery process is complete, you can verify the recovered data and check if any files are corrupted. You can also create a backup of the recovered data on a separate disk to ensure its safety.

Remember, this is just a basic example to get you started with ddrescue. You can explore additional options and strategies, such as changing block sizes or using different recovery modes, to adapt to specific situations. Be sure to refer to the ddrescue documentation and adjust the command parameters according to your needs.

Here’s an example of the output you might see when running ddrescue:

ddrescue: Starting ddrescue version 1.25
[ipos: 0 B, non-trimmed: 0 B, total: 1024 MB]    # Initial status information

Copying non-tried blocks... Pass 1 (forwards)
rescued: 8000 MB, errsize: 256 kB, current rate: 1000 kB/s  # Progress update

Splitting failed blocks... Retry 1 (after splitting)
rescued: 8000 MB, errsize: 128 kB, current rate: 800 kB/s   # Progress update

Splitting failed blocks... Retry 2 (after splitting)
rescued: 8000 MB, errsize: 64 kB, current rate: 600 kB/s    # Progress update

Finished                                      # Recovery process completed
ddrescue: Summary - Errors: 0 B, Error rate: 0.00%, Average rate: 800 kB/s

In this example, the initial status shows that ddrescue has started, and the source disk has a total size of 1024 MB. As the recovery process progresses, it displays information about the amount of data rescued, the size of the remaining errors (errsize), and the current recovery rate. It also indicates the pass number or retry number if splitting of failed blocks is enabled.

The output concludes with a summary that shows the total amount of errors (Errors), the error rate (Error rate), and the average recovery rate (Average rate).

Please note that the actual output may vary depending on the specific version of ddrescue you’re using and the parameters you’ve provided.

There are a few strategies you can employ to speed up the recovery process. Here are some tips:

  1. Use the --direct option: By default, ddrescue uses buffered I/O, which can slow down the recovery process. You can use the --direct option to enable direct I/O, which bypasses the buffer cache and can improve performance. However, keep in mind that this may increase the load on your system, so monitor its resources accordingly.

  2. Start with a larger block size: ddrescue allows you to specify the block size with the --block-size option. Using a larger block size can improve performance, especially when dealing with large bad sectors. However, if you encounter errors, you might need to reduce the block size to ensure better error handling.

  3. Use the logfile feature: ddrescue has a built-in feature called “logfile” that helps you resume the recovery process if it gets interrupted. It keeps track of the already recovered data and the areas with errors. By using the logfile, you can pause and resume the recovery process without starting from scratch each time.

  4. Prioritize non-error areas: When using ddrescue, you can specify the areas you want to prioritize by providing a mapfile. You can start by recovering the non-error areas first to retrieve as much data as possible. Then, you can go back and focus on the areas with bad sectors using different settings or approaches.

  5. Avoid unnecessary retries: By default, ddrescue will make multiple attempts to read from a bad sector. This can significantly slow down the recovery process. You can use the -n or --no-scrape option to disable scraping and avoid unnecessary retries. However, keep in mind that you may miss some recoverable data by doing this.

  6. Try reverse mode: If you’re having difficulty recovering data in the forward direction, you can try using the reverse mode in ddrescue. The reverse mode starts from the end of the disk and works backward. This can be helpful in cases where certain areas of the disk are more accessible from the end.

Remember, dealing with bad sectors can be a time-consuming process, and it’s crucial to have patience. Additionally, it’s always a good idea to make a bitwise copy of the disk using dd or similar tools before attempting any recovery operations to ensure you have a backup of the original data.