≡ Menu

Linux: Save and Recover Data From Crashed Disks With ddrescue Command Like a Pro

GNU ddrescue is a program that copies data from one file or block device (hard disk, cd/dvd-rom, etc) to another, it is a tool to help you to save data from crashed partition i.e. it is a data recovery tool. It tries to read and if it fails it will go on with the next sectors, where tools like dd will fail. If the copying process is interrupted by the user it is possible to continue at any position later. It can copy backwards.

This program is useful to rescue data in case of I/O errors, because it does not necessarily abort or truncate the output. This is why you need to use this program and not the dd command. I have recovered much data from many disks (CD/hard disk/software raid) over the years using GNU ddrescue on Linux. I highly recommend this tool to Linux sysadmins.

Install ddrescue on a Debian/Ubuntu Linux

Type the following apt-get command to install ddrescue:
# apt-get install gddrescue
Sample outputs:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  gddrescue
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 49.6 kB of archives.
After this operation, 152 kB of additional disk space will be used.
Get:1 http://mirrors.service.networklayer.com/ubuntu/ precise/universe gddrescue amd64 1.14-1 [49.6 kB]
Fetched 49.6 kB in 0s (1,952 kB/s)
Selecting previously unselected package gddrescue.
(Reading database ... 114969 files and directories currently installed.)
Unpacking gddrescue (from .../gddrescue_1.14-1_amd64.deb) ...
Processing triggers for install-info ...
Processing triggers for man-db ...
Setting up gddrescue (1.14-1) ...

Install ddrescue on a RHEL/Fedora/CentOS Linux

First turn on EPEL repo on a RHEL/CentOS/Fedora Linux. Type the following yum command:
# yum install ddrescue
Sample outputs:

Loaded plugins: product-id, rhnplugin, security, subscription-manager,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ddrescue.x86_64 0:1.16-1.el6 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package            Arch             Version               Repository      Size
================================================================================
Installing:
 ddrescue           x86_64           1.16-1.el6            epel            81 k
 
Transaction Summary
================================================================================
Install       1 Package(s)
 
Total download size: 81 k
Installed size: 189 k
Is this ok [y/N]: y
Downloading Packages:
ddrescue-1.16-1.el6.x86_64.rpm                           |  81 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : ddrescue-1.16-1.el6.x86_64                                   1/1
  Verifying  : ddrescue-1.16-1.el6.x86_64                                   1/1
 
Installed:
  ddrescue.x86_64 0:1.16-1.el6
 
Complete!
 

You can directly download ddrescue from the official GNU project web site and compile it on Linux or Unix-like systems.

A note about using ddrescue safely

  1. You need to use a logfile to resume a rescue.
  2. Never ever run ddrescue on a read/write mounted partition.
  3. Do not try to repair a file system on a drive with I/O errors.
  4. Be careful about destination partition/device, any data stored there will be overwritten.

How do I use ddrescue command?

In this example rescue a /dev/sda to /dev/sdb

 
     ## No need to partition /dev/sdb beforehand, but if the partition table on /dev/sda ##
     ## is damaged, you will need to recreate it somehow on /dev/sdb. ##
     ddrescue -f -n /dev/sda /dev/sdb logfile
     ddrescue -d -f -r3 /dev/sda /dev/sdb logfile
     ## get list of partitions on a /dev/sdb ##
     fdisk /dev/sdb
 
     ## check for errors ##
     fsck -v -f /dev/sdb1
     fsck -v -f /dev/sdb2
 

Understanding ddrescue command options

  • -f : Overwrite output device or partition.
  • -n : Do not try to split or retry failed blocks.
  • -d : Use direct disc access for input file.
  • -r3 : Exit after given three (3) retries (use -1 as infinity retries).
  • -b2048 : Sector size of input device [default is set to 512].

Example: Rescue a partition in /dev/sda3 to /dev/sdb3 in Linux

 
 ## You need to create the sdb2 partition with fdisk first. sdb2 should be of appropriate type and size ##
     ddrescue -f -n /dev/sda2 /dev/sdb2 logfile
     ddrescue -d -f -r3 /dev/sda2 /dev/sdb2 logfile
     e2fsck -v -f /dev/sdb2
     mount -o ro /dev/sdb2 /mnt
## Rread rescued files from /mnt ##
     cd /mnt
     ls -l
## Copy files using rsync ## 
     rsync -avr . vivek@server1.cyberciti.biz:/data/resuced/wks01
 

Example: Rescue/recover a DVD-ROM in /dev/dvdom on a Linux

The syntax is:

 
     ddrescue -n -b2048 /dev/dvdrom dvd-image logfile
     ddrescue -d -b2048 /dev/dvdrom dvd-image logfile
 

Please note that if there are no errors (errsize is zero), dvd-image now contains a complete image of the DVD-ROM and you can write it to a blank DVD-ROM on a Linux based system:
# growisofs -Z /dev/dvdrom=/path/to/dvd-image

Example: Resume failed rescue

In this example, while rescuing the whole drive /dev/sda to /dev/sdb, /dev/sda freezes up at position XYZFOOBAR (troubled sector # 7575757542):

 
 ## /dev/sda freezes here ##
 ddrescue -f /dev/hda /dev/hdb logfile
 ## So restart /dev/sda or reboot the server ##
 reboot
 ## Restart copy at a safe distance from the troubled sector # 7575757542 ##
 ddrescue -f -i 7575757542 /dev/sda /dev/sdb logfile
 ## Copy backwards down to the troubled sector # 7575757542 ##
 ddrescue -f -R /dev/sda /dev/sdb logfile
 

A note about dd_rescue command and syntax

On Debian / Ubuntu and a few other distro you end up installing other utility called dd_rescue. dd_rescue is a program that copies data from one file or block device to another, it is a tool to help you to save data from crashed partition.

Examples: dd_rescue

To make exact copy of /dev/sda (damaged) to /dev/sdb (make sure sdb is empty) you need to type following command:
# ddrescue /dev/sda /dev/sdb
Naturally, next step is to run fsck on /dev/sdb partition to recover/save data. Remember do not touch originally damaged /dev/sda. If this procedure fails you can send your disk to professional data recovery service. For example if /home (user data) is on /dev/sda2, you need to run a command on /dev/sdb2:
# fsck /dev/sdb2

Once fsck run, mount /dev/sdb2 somewhere and see if you can access the data:
# mount /dev/sdb2 /mnt/data
Finally, take backup using tar or any other command of your own choice. ddrescue command supports tons of options, read man page for more information:
# man dd_rescue
OR see gnu/ddrescue command man page:
# man ddrescue

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

Comments on this entry are closed.

  • Anonymous May 23, 2006, 12:04 am

    Very helpul thanks!

  • htc May 18, 2006, 9:02 pm

    Thanks, excellent article.

    I have a couple of doubts, though. I haven’t able to install it using apt-get command :( Any hint?

    • Sir_Mr_Bman October 7, 2014, 12:13 pm

      Try this command instead:

      $ apt-get update && apt-get install ddrescue

      That should do it.

  • nixCraft May 19, 2006, 1:13 pm

    @htc,

    Hmm…

    Try to update apt database and again run same command:

    apt-get update
    apt-get install ddrescue

    HTH.

  • John June 1, 2006, 8:23 am

    Simple and effective :D good pice of work,IMPO

  • chadrick June 13, 2006, 6:00 pm

    My personal experience is dd is slow and dd will never display any progress (which makes me more nervous about my data … LOL). I love ddrescue – one perfect tool for data recovery.

  • alt August 21, 2006, 10:05 pm

    I have on hd with NTFS file system which has important data to backed up and I have one more computer which has Readhat linux installed on it. How I can use dd_rescue to retrive data out from that hd having NTFS file system.

  • Dad September 14, 2006, 1:47 pm

    Does anyone have a link to a ddrescue man page that is something more than that the program itself puts on screen when the user enters parameters incorrectly? It would be nice to know more about ddrescue than just what the options list is!

  • nixCraft September 14, 2006, 2:43 pm
  • Scottux October 2, 2006, 11:25 pm

    Is there any other tool to recover files? I have a hard drive with bad sectors. It is an NTFS filesystem and has some importnat data on it. I have tried dd and now ddrescue, to no avail. I was trying to use autopsy/sleuthkit – but it requires an image. I am pulling my hair out trying to recover the files from this thing. I don’t care about the drive, just the data. All RAID from now on.

  • Udit January 20, 2007, 9:34 am

    You guys might want to look at dd_rhelp also
    http://www.kalysto.org/utilities/dd_rhelp/index.en.html

    I haven’t used it but it seems to shorten the amount of time dd_rescue takes.

  • nixCraft January 22, 2007, 3:16 pm

    Udit,

    Thanks for sharing link :)

  • cuvtixo October 2, 2007, 1:55 am

    The Linux tool called GNU ddrescue written by Antonio Diaz Diaz should not be confused with dd_rescue written by Kurt Garloff
    They are two different utilities.

  • Anonymous December 23, 2007, 6:35 pm

    Actually, the command on Ubuntu should be
    apt-get install gddrescue.

    Not ddrescue. You have to have the g there.

  • nixCraft December 23, 2007, 6:44 pm

    On my Ubuntu 7.10, I can install the tool ddrescue
    sudo apt-get install ddrescue

    And it got installed:
    [sudo] password for vivek:
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
    ddrescue
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 17.6kB of archives.
    After unpacking 77.8kB of additional disk space will be used.
    Get:1 http://in.archive.ubuntu.com gutsy/universe ddrescue 1.13-3 [17.6kB]
    Fetched 17.6kB in 2s (8220B/s)
    Selecting previously deselected package ddrescue.
    (Reading database ... 123654 files and directories currently installed.)
    Unpacking ddrescue (from .../ddrescue_1.13-3_i386.deb) ...
    Setting up ddrescue (1.13-3) ...

  • fd February 12, 2008, 10:39 am

    you write: “dd_rescue (also known as ddrescue)”. they are not at all the same software.

    ddrescue and dd_rescue are completely different programs which share no development between them. the two projects are not related in any way except that they both attempt to enhance the standard dd tool and coincidentally chose similar names for their new programs.

    ddrescue is the one to get.

  • noodle January 14, 2009, 10:40 am

    actually gddrescue is the one you want, its updated more frequently and incorporates the functions of the original dd_rescue and dd_rhelp.

  • webmaster screenshotscores July 14, 2009, 1:08 pm

    nice one, very helpful!

  • Rich August 16, 2009, 1:23 pm

    for clarity,
    * the PACKAGE “gddrescue” provides the COMMAND ddrescue
    * the PACKAGE “ddrescue” provides the COMMAND dd_rescue

    GNU ddrescue is the first one, and seems IMHO better/more flexible than dd_rescue.

  • wav August 13, 2010, 11:34 am

    Damn, i can’t get it to work!!

    when I use the given command to start copying the img file, i get told that the destination is not a directory!

    I created a directory called backup.img but still get the stupid error

    so do you all are so very happy that it works

  • brain October 6, 2010, 2:38 am

    well said wav…

    Look forward to a resolution posting.

    Thanks in advance to all.

    B

  • nodonttakethose January 18, 2011, 9:02 am

    Correction:
    ddrescue dose not equal dd_rescue!!! The apt database is confusing in this regard.
    “ddrescue” (gddrescue in apt) is a GNU app that is _far_ superior to dd_rescue (ddrescue in apt). Check synaptic. Check man page and info for GNU ddrescue at the linked site below. As I said it’s far superior to dd_rescue (faster, more sensible output).

    http://www.gnu.org/software/ddrescue/manual/ddrescue_manual.html#Fill-Mode

  • nathan December 6, 2011, 1:26 pm

    hai there. befpre i run these commands, do need to download any software? if yes, how to do it?? im a newbie:-)

    • Derpatron October 8, 2014, 10:51 am

      Had you bothered to read the article you wouldn’t have to ask this question, it’s all explained there.

  • gardenman April 5, 2012, 1:28 am

    just start the terminal and type sudo apt-get install gddrescue and hit enter

  • ybanafa October 12, 2014, 6:50 pm

    Thanks
    how can I boot /dev/sdb1 & /dev/sdb2 in new HD ( the old dead /dev/sda1 &2) ?
    Note : RouterOS Lic.Level 6
    –YB

  • davekimble February 11, 2015, 12:37 am

    I am trying to rescue an audio CD.
    $ ddrescue –n –b2048 /dev/cdrom cd.iso ddrescue.log
    ddrescue: Too many files.
    $
    no output files produced.
    Is the file system corrupt or what?