Data recovery tool, save data from a crashed partition.
Syntax
ddrescue [options] infile outfile [mapfile]
Options:
infile Input files, devices, or partitions.
outfile Output files, devices, or partitions.
mapfile A regular file placed in an existing directory.
If mapfile does not exist, ddrescue creates it.
Be careful to not specify by mistake an old mapfile from an unrelated rescue.
Ddrescue will try to create a backup copy of the mapfile, with the name mapfile.bak,
every time it is going to overwrite a fsynced mapfile. See --mapfile-interval.
Always use a mapfile unless you know you won't need it.
Without a mapfile, ddrescue can't resume a rescue, only reinitiate it.
-a bytes
--min-read-rate=bytes
Minimum read rate of good non-tried areas, in bytes per second.
If the read rate falls below this value during the first two passes of the copying phase, ddrescue
skips ahead a variable amount depending on rate and error histories.
The blocks skipped are tried in additional passes (before trimming). --min-read-rate is ignored in
all passes but the first two.
If bytes is 0 (auto), the minimum read rate is recalculated every second as (average_rate / 10).
--ask
Ask for user confirmation before starting the copy. If the first letter of the answer is 'y', ddrescue starts
copying. Else it exits with status 1.
If they can be obtained, ddrescue shows the model and serial number of the input and output devices.
Ddrescue also shows the size in bytes of the corresponding file or device if it exists.
The format used is [model::serial_number] (size)
-A
--try-again
Mark all non-trimmed and non-scraped blocks inside the rescue domain as non-tried before beginning the rescue.
Try this if the drive stops responding and ddrescue immediately starts scraping failed blocks when restarted.
If --retrim is also specified, mark also the most promising bad sectors inside the rescue domain as non-tried.
See --retrim.
-b bytes
--sector-size=bytes
Sector (hardware block) size of input device in bytes (usually 512 for hard discs and 3.5" floppies,
1024 for 5.25" floppies, and 2048 for cdroms). Defaults to 512.
In rescue mode, any non-finished subsector that is found during the initial read of the mapfile is joined
to its corresponding sector (if it is also not finished), marking the whole sector with the less processed
state, so as to make sure that sub-sector data is not discarded from a successful read during the rescue.
(A subsector is a block smaller than sector size). Subsector joining is performed in all the mapfile, not
only in the rescue domain.
--bad-sector-data=file
Treat as a read error any sector containing the same data as file.
If file is larger than the sector size, the rest of file is discarded.
This option is useful when the drive, instead of signaling a read error, returns known garbage data
(different for each drive model). If you need to use this option, it means that the failing drive lacks
adequate integrity checking. Better avoid such drives.
-B
--binary-prefixes
Show units with binary prefixes (powers of 1024).
SI prefixes (powers of 1000) are used by default. (See table below).
-c sectors
--cluster-size=sectors
Number of sectors to copy at a time. Defaults to 64 KiB / sector_size.
Try smaller values for slow drives. The number of sectors per track (18 or 9) is a good value for floppies.
--command-mode
Read commands from the standard input and execute them, copying parts of the input file on demand.
Command-line arguments controling the display (like --data-preview) or the automatic algorithm
(like --max-errors or --reverse) have no effect in command mode.
See Command mode, for a complete description of the command mode.
--continue-on-errno=code[,code]...
Treat errno code code as non-fatal.
This option may be useful on systems that incorrectly return fatal errno codes for non-fatal errors.
If ddrescue exits because of a fatal read error, it prints in the final message the value of the variable 'errno',
which can then be used as argument to this option.
Multiple errno values may be specified with cumulative effect, either in the same argument, or by specifying
multiple instances of this option. The option --reopen-on-error may be needed when using this option.
--cpass=range
Select what pass(es) to run during the copying phase.
Valid pass values range from 1 to 4. To run only the given pass(es), specify also --no-trim, --no-sweep,
and --no-scrape. --cpass=0 skips the copying phase entirely.
Examples of range Passes run
1 1
1,2,3 1, 2, 3
2-4 2, 3, 4
-C
--complete-only
Limit rescue domain to the blocks listed in the mapfile.
Don't read new data beyond mapfile limits. This is useful when reading from devices of undefined size
(like raw devices), when the drive returns an incorrect size, or when reading from a partial copy.
-C can only be used after a first rescue attempt, possibly limited with the option --size, has produced a
complete mapfile. If -C is not specified, ddrescue extends the mapfile from position 0 to the size of outfile,
adding one non-tried block before the existing blocks and another one after them if needed.
-d
--idirect
Use direct disc access to read from infile, bypassing the kernel cache.
(Opens the file with the flag 'O_DIRECT'). Sector size must be correctly set for this to work.
Not all systems support this. See Direct disc access.
If your system does not support direct disc access, ddrescue warns you.
If the sector size is not correctly set, an unaligned read error may happen, in which case ddrescue exits
with error status 1.
--delay-slow=interval
Initial delay before ddrescue starts checking for slow reads.
Defaults to 30 seconds. interval is formatted as in the option --timeout below.
-D
--odirect
Use direct disc access to write to outfile, bypassing the kernel cache.
(Opens the file with the flag 'O_DIRECT'). Sector size must be correctly set for this to work.
Not all systems support this.
If your system does not support direct disc access, ddrescue warns you.
If the sector size is not correctly set, a write error is reported and no data is rescued.
Some OSs have a bug that prevents them from detecting write errors properly (or at all) on some devices
if direct disc access is not used for outfile.
-e [+]n
--max-bad-areas=[+]n
Maximum number of bad areas allowed before giving up. Defaults to infinity.
If n is preceded by '+' the number refers to new bad areas found in this run, not counting those already
present in the mapfile. See --max-read-errors.
-E bytes
--max-error-rate=bytes
Maximum rate of read errors allowed before giving up, in bytes per second.
Defaults to infinity. The rate being measured is that of actually failed reads, so ddrescue may exit because of
this rate being exceeded even if the total error size (size of bad-sector areas) does not change because the
areas being tried are being marked as non-trimmed or non-scraped, or are already marked as bad-sector.
-f
--force
Force overwrite of outfile.
Needed when outfile is not a regular file, but a device or partition.
This option is just a safeguard to prevent the inadvertent destruction of partitions, and is ignored for
regular files.
-F types
--fill-mode=types
Fill the blocks in outfile specified as any of types in mapfile, with data read from infile.
types contains one or more of the status characters defined in the chapter Mapfile structure (see Mapfile structure)
and an optional 'l' for sector location data.
See the chapter Fill mode (see Fill mode) for a complete description of the fill mode.
-G
--generate-mode
Generate an approximate mapfile from the infile and outfile of the original rescue run.
Note that you must keep the original offset between --input-position and --output-position of the original rescue
run. See the chapter Generate mode (see Generate mode) for a complete description of the generate mode.
-h
--help
Print an informative help message describing the options and exit.
-H file
--test-mode=file
Build a map of good/bad blocks using the mapfile file and use it to simulate read errors in infile.
The blocks marked as finished in file are read normally. All other block types are considered read errors without
even trying to read them from infile. The apparent size of infile is truncated to the extent of file.
This mode is an aid in improving the algorithm of ddrescue and is also useful to check that ddrescue
produces accurate results in presence of read errors.
Use a hyphen '-' as file to read the mapfile from standard input. See --pause-on-error.
-i bytes
--input-position=bytes
Starting position of the rescue domain in infile, in bytes.
Defaults to 0. This is not the point from which ddrescue starts copying. (For example, if you pass the
option --reverse to ddrescue, it starts copying from the end of the rescue domain).
In fill mode it refers to a position in the infile of the original rescue run.
See the chapter Fill mode (see Fill mode) for details.
-I
--check-input-size
Compare the size of infile with the size calculated from the list of blocks contained in the mapfile, and
exit with status 1 if they differ.
This is not enabled by default because the size of some devices can't be known in advance and because the
size derived from the mapfile may be incomplete, for example after doing a partial rescue.
-J
--check-on-error
After every read error, read again the last good sector found and check that it returns the same data.
Exit with status 2 if the read fails or returns inconsistent data.
Exit with status 1 if a read error happens before a good sector is found.
This option performs one extra read after each error, wearing the drive faster.
Use it only on drives that stop responding or return garbage data after finding errors.
You may need to power cycle the drive before restarting ddrescue.
-K [initial][,max]
--skip-size=[initial][,max]
Set limits to skip size during the copying phase.
At least one of initial or max must be specified. initial is the size to skip on the first read error or slow read,
in bytes. max is the maximum size to skip. The values given are rounded to the next multiple of sector size.
The skip size is doubled for each read error or slow read until it reaches max or, if max is omitted,
1% of the size of infile, and is reset to initial when good data are found.
Valid values range from 64 KiB to 1 EiB. initial defaults to infile_size / 32_768 with a minimum value of
64 KiB. An initial value of 0 disables skipping entirely.
If ddrescue is having difficulties skipping away from a large area with scattered errors, or if the device
has large bad areas at regular intervals, you may increase the initial skip size with this option.
Inversely, if ddrescue is skipping too much, leaving large non-tried areas behind each error (which will be read
later in the usually slower backwards direction), you may reduce the maximum skip size, or disable skipping.
--skip-size is independent from --cluster-size.
The size to skip is calculated from the end of the block that just failed.
--log-events=file
Log all significant events (start of each pass and end of run) in file.
If file already exists, the new events are appended at the end of file. For each event two lines are printed
containing a time stamp, the amount of data rescued, and a message describing the event.
The 'end of run' line also contains the current position and status. If ddrescue exits because of an error
or interruption, the cause is also logged in file.
--log-rates=file
Log rates and error sizes every second in file.
If file already exists, it is overwritten. Every time the screen is updated with new details, some of those
details (time, input position, current and average rates, number of bad areas, and total error size) are
written to file in a format usable by plotting utilities like gnuplot.
This allows a posterior analysis of the drive to see if it has any weak zones (areas where the transfer rate
drops well below the sustained average).
--log-reads=file
Log all read operations in file.
If file already exists, it is overwritten. Every read attempt and its result (position, size, copied size,
error size, and errno (if different from EIO)) is written to file.
(The position written is always the beginning of the block tried, even if reading backwards).
A line is also written at the beginning of each phase (copying, trimming, sweeping, scraping, and retrying).
Finally, a line with a time mark is written every second (unless the read takes more time).
Use this option with caution because file may become very large very quickly. Use lzip to compress file
if you need to store or transmit it.
-L
--loose-domain
Accept an incomplete synthetic (user fabricated) domain mapfile or test-mode mapfile, and fill the gaps in
the list of data blocks with non-tried blocks. The blocks in the mapfile may be unordered, may overlap other
blocks of the same status, and don't need to be contiguous.
This option allows making quick edits to a mapfile without all the size calculations involved in making all
data blocks contiguous again.
-m file
--domain-mapfile=file
Restrict the rescue domain to the blocks marked as finished in the mapfile file.
This is useful for merging partially recovered images of backups, or if the destination drive fails during the
rescue. Use a hyphen '-' as file to read the domain mapfile from standard input.
Specialized tools like ddrutility or partclone can produce a domain mapfile listing all the used blocks in
a partition, making the rescue more efficient. Trailing empty space in the partition is not copied to outfile.
If you need outfile to be the same size as the partition (to mount it, for example), you may
use --extend-outfile=0, --extend-outfile=partition_size, or --preallocate. --extend-outfile increases the size
without writing data to outfile, and may therefore be more efficient than --preallocate.
Partclone saves the size of the partition as the value of 'current_pos' in the domain mapfile.
--mapfile-interval=[save_interval][,sync_interval]
Change the interval at which ddrescue saves and fsyncs the mapfile.
At least one of save_interval or sync_interval must be specified. A save_interval of -1 chooses the
default automatic interval (from 30 seconds to 5 minutes depending on mapfile size).
A save_interval of 0 saves the mapfile after every read (use with caution).
sync_interval is the interval between fsync calls. Default sync_interval is 5 minutes. Minimum sync_interval is
5 seconds. sync_interval must be greater or equal than save_interval.
Intervals are formatted as in the option --timeout below.
In practice, fsyncs are a subset of saves. I.e., some of the times when the mapfile is saved,
it is also fsync'ed. Therefore, --mapfile-interval=30,45 is really --mapfile-interval=30,60.
The time needed to write the mapfile is excluded from the mapfile save and sync intervals.
(Some mapfiles may take several seconds to write).
--max-slow-reads=n
Maximum number of slow reads allowed before giving up.
Defaults to infinity. Exit with status 1 if more than n slow reads are encountered during the first
two passes of the copying phase. Only works if a minimum read rate has been set with --min-read-rate.
-M
--retrim
Mark the failed blocks inside the rescue domain adjacent to a non-tried or finished block as non-trimmed
before beginning the rescue. This might make perhaps possible to rescue some of them.
-n
--no-scrape
Skip the scraping phase. Avoids spending a lot of time trying to rescue the most difficult parts of the file.
-N
--no-sweep
Skip the sweeping phase. May be useful when the drive has a dead head.
--no-trim
Skip the trimming phase.
This option is not recommended because trimming has a high probability of finding good data.
-o bytes
--output-position=bytes
Starting position of the image of the rescue domain in outfile, in bytes.
Defaults to --input-position. The bytes below bytes aren't touched if they exist and truncation is not
requested. Else they are set to 0.
-O
--reopen-on-error
Close infile and then reopen it after every read error encountered.
If --min-read-rate is set, also close and reopen infile after every slow read encountered during the first
two passes of the copying phase. Use this option if you notice a permanent drop in transfer rate after
finding read errors or slow areas. But be warned that most probably the slowing-down is intentionally caused
by the kernel in an attempt to increase the probability of reading data from the device.
This option may also be needed to reset the error status of the input device when using the option
--continue-on-errno.
-p
--preallocate
Preallocate space on disc for outfile.
Only space for regular files can be preallocated. If preallocation succeeds, rescue will not fail due to
lack of free space on disk. If ddrescue can't determine the size to preallocate, you may need to specify it
with some combination of the options --input-position, --output-position, --size, and --domain-mapfile.
--pause-on-error=interval
Time to wait after each read error.
Also after each slow read if a minimum read rate has been set with --min-read-rate.
Defaults to 0. interval is formatted as in the option --timeout below.
If interval begins with 's', the pause is simulated and interval can be smaller than one second; the time displayed
is increased by interval but without performing any pause.
Pause simulation can be useful in combination with --test-mode for testing purposes.
--pause-on-pass=interval
Time to wait between passes.
Defaults to 0. interval is formatted as in the option --timeout below.
-P[lines]
--data-preview[=lines]
Show lines lines of the latest data read in '16-byte hex + ASCII' format.
Valid values for lines range from 1 to 32.
If lines is omitted, a default value of 3 is used.
-q
--quiet
Quiet operation. Suppress all messages.
-r n
--retry-passes=n
Exit after the given number of retry passes. Defaults to 0.
-1 means infinity. Every bad sector is tried only once in each pass.
The direction is reversed after each pass. To retry bad sectors detected on a previous run, you must
specify a nonzero number of retry passes.
A command like 'ddrescue -f -r-1 /dev/sdcard /dev/null mapfile' can be used to read repeatedly until
the device controller succeeds and remaps the bad sectors internally.
--reset-slow
Reset the slow reads counter every time the read rate reaches or surpasses --min-read-rate.
With this option, ddrescue only exits after the read rate has remained below --min-read-rate for at
least as many seconds as the argument given to --max-slow-reads. See --max-slow-reads.
-R
--reverse
Reverse the direction of all passes (copying, trimming, sweeping, scraping, and retrying).
Every pass that is normally run forwards is now run backwards, and vice versa. -R does not modify the
size of the blocks copied during each phase, just the order in which they are tried.
-s bytes
--size=bytes
Maximum size of the rescue domain in bytes.
It limits the amount of input data to be copied. -1 removes any previous size limit.
In rescue mode, --size=output uses the size of the output file or device (for example to overwrite it).
By default, ddrescue limits the amount of data to be copied to the size of the input file, but if
ddrescue can't determine the size of the input file, you may need to specify it with this option.
Note that this option does not specify the size of the resulting outfile.
For example, the following command creates an outfile 300 bytes long, but only writes data on
the last 200 bytes:
ddrescue -i 100 -s 200 infile outfile mapfile
-S
--sparse
Use sparse writes for outfile.
(The blocks of zeros are not actually allocated on disc). May save a lot of disc space in some cases.
Not all systems support this. Only regular files can be sparse.
Use this option only with an empty or zeroed outfile because if a block in outfile contains nonzero data,
it won't be overwritten by a corresponding block of zeros in infile, resulting in a corrupt copy.
--same-file
Allow infile and outfile to be the same file or device.
This may be used to test the writing ability of a drive. It may also be used to copy part of a file to
another location inside or beyond the end of the same file by setting different values for --input-position
and --output-position. If the data to be copied overlap with the destination, the right copying direction
must be chosen to avoid overwriting the overlapping part before it is copied.
-t
--truncate
Truncate outfile to zero size before writing to it.
Only works for regular files, not for drives or partitions.
-T interval
--timeout=interval
Maximum time since last successful read allowed before giving up.
Defaults to infinity. interval is an integer or rational number (like 1.5 or 1/2) optionally followed by
one of 's', 'm', 'h', or 'd', meaning seconds, minutes, hours, and days respectively.
If no unit is specified, it defaults to seconds. interval has a resolution of one second; fractions of a second
are not allowed. See --max-read-errors.
-u
--unidirectional
Run all passes in the same direction.
Forwards by default, or backwards if the option --reverse is also given.
-v
--verbose
Verbose mode.
Further -v's (up to 4) increase the verbosity level. Some large numbers in messages (like device sizes) are
printed in groups of 3 digits separated by underscore characters to make them more readable.
-V
--version
Print the version number of ddrescue on the standard output and exit.
This version number should be included in all bug reports.
-w
--ignore-write-errors
Make fill mode ignore write errors.
This is useful to avoid ddrescue exiting because of new bad sectors developing while wiping the good sectors
of a failing drive. Fill mode normally writes to outfile one cluster at a time. With this option, after the
first write error is found in an area, the rest of that area is filled sector by sector.
Note that in rescue mode a write error is fatal, which means that the rescue needs to be repeated or else
outfile needs to be copied to a third drive using mapfile as domain. See --domain-mapfile.
-W
--compare-before-write
Omit superfluous writes in rescue mode.
Before writing each block of data to outfile, compare the data already present there with the data about to
be written and, if they match, omit the write. Possible advantages are that on some devices reads are faster
than writes and it may reduce wear when writing to a solid state device.
-x bytes
--extend-outfile=bytes
Extend the size of outfile to make it at least bytes long.
If bytes is 0, extend the size of outfile to that of infile. If the size of outfile is already equal or longer
than bytes or the size of infile, then this option does nothing.
Use this option to guarantee a minimum size for outfile. Only regular files can be extended.
-X n
--max-read-errors=n
Maximum number of read errors allowed before giving up.
Defaults to infinity. Exit with status 1 if more than n read errors are encountered. --max-read-errors=0 is
similar but different to --timeout=0, which waits until the screen status is refreshed (at least 1 second).
If there is at least one successful read per second, --timeout=0 does not make ddrescue to exit.
--max-read-errors=0 is also similar but different to --max-bad-areas=+0, which exits when a new bad area is found.
If the read errors are adjacent to existing bad areas, no new bad areas are produced (just enlarged), and
--max-bad-areas=+0 does not make ddrescue exit.
-y
--synchronous
Use synchronous writes for outfile.
(Issue a fsync call after every write). May be useful when forcing the drive to remap its bad sectors.
Use it to make sure that all writes have been committed to disc when ddrescue finishes. Else the kernel may
cache all the writes and pretend that it has finished.
-Z bytes
--max-read-rate=bytes
Maximum read rate, in bytes per second.
If bytes is too small, the actual read rate is rounded up to the equivalent of a whole number of cluster
reads per second. Use this option to limit the bandwidth used by ddrescue, for example when recovering
over a network.
-- Terminates all options; any following arguments are treated as non-option arguments, even if they begin
with a hyphen.
One or more options without arguments, followed by at most one option that takes an argument, may follow a hyphen in a single token. Thus, -abc is equivalent to -a -b -c.
Numbers can be followed by a multiplier: b = blocks, k = kB = 10^3 = 1000, Ki = KiB = 2^10 = 1024, M = 10^6, Mi = 2^20, G = 10^9, Gi = 2^30, etc...
Numbers given as arguments to options (positions, sizes, rates, etc) may be expressed as decimal, hexadecimal, or octal values (using the same syntax as integer constants in C++), may contain underscore separators between groups of 3 or more digits (2 or more digits for hexadecimal), and may be followed by a multiplier and an optional 'B' for "byte". (1_234_567kB, 4Kis, 0x1234_5678, 07_777_777). The 's' multiplier may be appended to any of the other multipliers. For example, 'ks' means kilosectors (1000 * sector_size), and 'Kis' means kibisectors (1024 * sector_size).
| Power-of-ten suffixes | Multiplier | Power-of-two suffixes: | Multiplier | ||||
|---|---|---|---|---|---|---|---|
| B | bytes (not blocks) | 1 | |||||
| K[B] | kilobytes | 1000 | 1 x 10^3 | Ki[B] | kibibytes | 1024 | 1 x 2^10 |
| M[B] | megabytes | 1000000 | 1 x 10^6 | Mi[B] | mebibytes | 1048576 | 1 x 2^20 |
| G[B] | gigabytes | 1000000000 | 1 x 10^9 | Gi[B] | gibibytes | 1073741824 | 1 x 2^30 |
| T[B] | terabytes | 1000000000000 | 1 x 10^12 | Ti[B] | tebibytes | 1099511627776 | 1 x 2^40 |
| P[B] | petabytes | 1000000000000000 | 1 x 10^15 | Pi[B] | pebibytes | 1125899906842624 | 1 x 2^50 |
| E[B] | exabytes | 1000000000000000000 | 1 x 10^18 | Ei[B] | exbibytes | 1152921504606846976 | 1 x 2^60 |
| Z[B] | zettabyte | 10^21 | Zi[B] | zebibyte | 2^70 | ||
| Y[B] | yottabyte | 10^24 | Yi[B] | yobibyte | 2^80 | ||
| R[B] | ronnabyte | 10^27 | Ri[B] | robibyte | 2^90 | ||
| Q[B] | quettabyte | 10^30 | Qi[B] | quebibyte | 2^100 |
Debian / Ubuntu Linux:
# apt-get install ddrescueRedHat /Fedora /CentOS Linux:
# yum -y install ddrescue
GNU ddrescue is a data recovery tool. It copies data from one file or block device (hard disc, cdrom, etc) to another, trying hard to rescue data in case of read errors.
The basic operation of ddrescue is fully automatic. That is, you don’t have to wait for an error, stop the program, read the log, run it in reverse mode, etc.
If you use the mapfile feature of ddrescue, the data are rescued efficiently, (only the blocks needed are read). Also you may interrupt the rescue at any time and resume it later at the same point. The mapfile is an essential part of ddrescue's effectiveness. Use it unless you know what you are doing.
Ddrescue does not write zeros to the output when it finds bad sectors in the input, and does not truncate the output file if not asked to. So, every time you run it on the same output file, it tries to fill in the gaps without wiping out the data already rescued.
Automatic merging of backups: If you have two or more damaged copies of a file, cdrom, etc, and run ddrescue on all of them, one at a time, with the same output file, you will probably obtain a complete and error-free file. This is so because the probability of having the same area damaged in all copies is low (if the errors are randomly located). Using the mapfile, only the blocks needed are read from the second and successive copies.
Ddrescue recommends lzip for compression of backups because the lzip format is designed for long-term archiving and provides data recovery capabilities which nicely complement those of ddrescue. (Ddrescue reads as many sectors as it can, while lziprecover uses other data to repair the sectors that ddrescue was not able to read). Lziprecover's FEC algorithm can repair any kind of file, but its ability to repair lzip files is greater than for other kinds of files. Lziprecover can use the statistical properties of lzip data to repair a lzip file rescued with ddrescue, even if the fec file is so damaged that it has lost both CRC arrays. Lziprecover fec files can be used as recovery record for tar.lz archives. If the cause of file corruption is a damaged medium, the combination ddrescue + lziprecover is the recommended option for recovering data from damaged files. See lziprecover example1, lziprecover example2, lziprecover example3, and lziprecover example4, for examples.
Because ddrescue needs to read and write at random places, it only works on seekable (random access) input and output files. Therefore, the only way of creating a compressed image with ddrescue is to create a normal (uncompressed) image first, and then compress that image.
If your system supports it, ddrescue can use direct disc access to read the input file, bypassing the kernel cache.
One of the strengths of ddrescue is that it is interface-agnostic, and so can be used for any kind of device supported by your kernel (ATA, SATA, SCSI, old MFM drives, floppy discs, or even flash media cards like SD).
Ddrescue also features a 'fill mode' able to selectively overwrite parts of the output file, which has a number of interesting uses like wiping data, marking bad areas, or even, in some cases, "repair" damaged sectors.
Block Any amount of data. A block is described by its starting position and its size. The starting position (or beginning position) is the lowest position in the block. The end of the block is its starting position plus its size. Cluster Group of consecutive sectors read or written in one go. Device Piece of hardware containing data. Hard disc drives, cdrom drives, USB pendrives, are devices. /dev/hda, /dev/sdb, are device names (file names associated to devices). File Files are named units of data which are stored by the operating system for you to retrieve later by name. Devices and partitions are accessed by means of their associated file names. Partition Every part in which a device is divided. A partition normally contains a file system. /dev/hda1, /dev/sdb3, are partition names (file names associated to partitions). Recoverable formats As ddrescue uses standard library functions to read data from the device being rescued, only mountable device formats can be rescued with ddrescue. CD-ROMs and DVDs can be rescued, "compact disc digital audio" CDs can't, "video CDs"[1] maybe. [1] http://en.wikipedia.org/wiki/Video_CD Rescue domain Block or set of blocks to be acted upon (rescued, listed, etc). You may define it with the options --input-position, --size, and --domain-mapfile. The rescue domain defaults to the whole input file or mapfile.
If ddrescue can't determine the size of the input file, the rescue domain defaults to the maximum size of a block (at least 2^63 - 1 bytes, or 8 EiB minus 1 byte). Ddrescue never tries to read any data outside the rescue domain except when unaligned direct disc access is requested (see Direct disc access). If it does, please, report it as a bug.
The data shown by ddrescue (amount of data rescued, number of bad areas, etc) may vary or even become zero if you limit the rescue domain. Don't worry, they have not disappeared; they are simply out of the rescue domain specified.
Sector Hardware block. Smallest accessible amount of data on a block device.
Ddrescue is like any other power tool. You need to understand what it does, and you need to understand some things about the machines it does those things to, in order to use it safely.
Never try to rescue a r/w mounted partition. The resulting copy may be useless. It is best that the device or partition to be rescued is not mounted at all, not even read-only.
Never try to repair a file system on a drive with I/O errors; you will probably lose even more data.
If you use a device or a partition as destination, any data stored there will be overwritten.
Some systems may change device names on reboot (for example, udev enabled systems). If you reboot such a system, pass the option --ask to ddrescue and check that the device names match the model and serial number of the input and output devices before allowing ddrescue to proceed. You may also check the devices with commands like 'hdparm -I /dev/sda' or 'smartctl -i /dev/sda'.
If you interrupt the rescue and then reboot, any partially copied partitions should be hidden before allowing them to be touched by any operating system that tries to mount and "fix" the partitions it sees.
When using a (graphical) frontend, be careful to not insert or remove any devices to avoid changes in the mapping of devices to device names between the moment the devices are selected in the frontend and the call to ddrescue. Be careful even if the frontend passes --ask to ddrescue, because outfile may be changed between user confirmation and actual opening.
It is recommended to run ddrescue on a POSIX system, but if you run it on Cygwin be prepared to find mysterious 'Permission denied' error messages caused by Windows returning misleading error codes and then Cygwin mapping some of those error codes to EACCES, making it impossible for ddrescue to know what failed, or even whether the error is fatal or not. See --continue-on-errno.
The output of ddrescue looks like this: GNU ddrescue 1.30 Press Ctrl-C to interrupt Initial status (read from mapfile) rescued: 1665 MB, tried: 0 B, bad-sector: 0 B, bad areas: 0 Current status ipos: 2874 MB, non-trimmed: 0 B, current rate: 21479 kB/s opos: 2874 MB, non-scraped: 0 B, average rate: 21023 kB/s non-tried: 13603 MB, bad-sector: 0 B, error rate: 0 B/s rescued: 2401 MB, bad areas: 0, run time: 35s pct rescued: 15.00%, read errors: 0, remaining time: 10m slow reads: 5, time since last successful read: 0s Copying non-tried blocks... Pass 1 (forwards)Ddrescue scrolls forward after each pass. This keeps on the screen the final status of the previous pass, making it easier to estimate the amount of work done by the current pass.
The meaning of each field is as follows:
ipos Input position. The position in the input file where data are being currently read from. opos Output position. The position in the output file where data are being currently written to. non-tried Size of the part of the rescue domain pending to be tried. This is the sum of the sizes of all the non-tried blocks. rescued Size of the part of the rescue domain already successfully recovered. This is the sum of the sizes of all the finished blocks. pct rescued Percentage of the rescue domain that has been successfully recovered. slow reads Number of times that the read rate fell below --min-read-rate during the first two passes of the copying phase. tried Size of the part of the rescue domain already tried but not yet rescued. This is the sum of the sizes of all the non-trimmed, non-scraped, and bad-sector blocks. non-trimmed Size of the part of the rescue domain pending to be trimmed. This is the sum of the sizes of all the non-trimmed blocks. non-scraped Size of the part of the rescue domain pending to be scraped. This is the sum of the sizes of all the non-scraped blocks. bad-sector Total error size. This is the size of the part of the rescue domain formed by known bad sectors. The total error size is the sum of the sizes of all the bad-sector blocks. It increases during the trimming, sweeping, and scraping phases, and may decrease during the retrying phase. A sector is not marked as bad-sector and considered part of a bad area until it has been tried individually instead of as part of a large block read. Note that as ddrescue retries the bad-sector blocks, the good data found may divide them into smaller blocks, decreasing the total error size but increasing the number of bad areas. bad areas Number of separate bad-sector blocks inside the rescue domain. Non-trimmed and non-scraped blocks are not considered bad areas. See --max-bad-areas. read errors Number of failed read attempts. See --max-error-rate. current rate The read rate measured during the last second. average rate The average read rate measured during the current run. error rate The read error rate measured during the last second. run time Time elapsed since the beginning of the current run. remaining time Estimated remaining time to rescue all the data in the rescue domain. The remaining time is calculated using the average rate of the last 60 seconds and does not take into account that some parts of the rescue domain may be excluded from the rescue (for example with --no-sweep), or that some areas may be unrecoverable. Therefore it may be imprecise, may vary widely during the rescue, and may show a nonzero value at the end of the rescue. In particular it may go down to a few seconds at the end of the first pass, just to grow to hours or days in the following passes. Such is the nature of ddrescue; the good parts are usually recovered fast, while the rest may take a long time. time since last successful read Time elapsed since the last successful read attempt.
NOTE: In versions of ddrescue prior to 1.20 the mapfile was called 'logfile'. The format is the same; only the name has changed.
The mapfile is a text file easy to read and edit. It is formed by three parts, the heading comments, the status line, and the list of data blocks. The character '#' at begin of line or after whitespace starts a comment that extends to the end of the line.
The heading comments contain the version of ddrescue or ddrescuelog that created the mapfile, the command line used, and the time when the program started. If the mapfile was created by ddrescue it also contains the current time when the mapfile was saved and a copy of the status message from the screen describing the operation being performed (copying, trimming, finished, etc). They are intended as information for the user.
The first non-comment line is the status line. It contains a non-negative integer, a status character, and a positive decimal integer. The first integer is the position being tried in the input file. (The beginning of the block being tried in a forward pass or the end of the block in a backward pass). The status character is one of these:
Character Meaning ? copying non-tried blocks * trimming non-trimmed blocks % sweeping non-tried blocks / scraping non-scraped blocks - retrying bad sectors F filling the blocks specified G generating approximate mapfile + finished Finally, the last integer is the number of the current pass in the current phase. The status line allows ddrescue to resume the copying phase instead of restarting it from pass 1. It also allows the retrying phase to resume in the same direction it was interrupted.
The blocks in the list of data blocks must be contiguous and non-overlapping.
Every line in the list of data blocks describes a block of data. It contains 2 non-negative integers and a status character. The first integer is the starting position of the block in the input file, the second integer is the size (in bytes) of the block. The status character is one of these:
Character Meaning ? non-tried block * failed block non-trimmed / failed block non-scraped - failed block bad-sector(s) + finished block And here is an example mapfile:
# Mapfile. Created by GNU ddrescue version 1.30 # Command line: ddrescue -d -c18 /dev/fd0 fdimage mapfile # Start time: 2015-07-21 09:37:44 # Current time: 2015-07-21 09:38:19 # Copying non-tried blocks... Pass 1 (forwards) # current_pos current_status current_pass 0x00120000 ? 1 # pos size status 0x00000000 0x00117000 + 0x00117000 0x00000200 - 0x00117200 0x00001000 / 0x00118200 0x00007E00 * 0x00120000 0x00048000 ?If you edit the file, you may use decimal, hexadecimal, or octal values, using the same syntax as integer constants in C++, except for current_pass, which must be a decimal integer.
The mapfile is an essential part of ddrescue's effectiveness. Without a mapfile, ddrescue can't resume a rescue, only reinitiate it. Given that a difficult rescue may take days to complete, it would be a serious drawback if the mapfile were lost because of a solvable problem like a lack of space on the device the mapfile is written to.
In case of trouble writing the mapfile, ddrescue prints a message like this:
Error writing mapfile 'mapfile': No space left on device Fix the problem and press ENTER to retry, or E+ENTER for an emergency save and exit, or Q+ENTER to abort.You may try to fix the problem, for example deleting some files to make room for the mapfile, and press <Return> to retry.
If the problem can't be fixed, you may press <e> followed by <Return> to try an emergency save and exit. Ddrescue tries to write the mapfile to the file ddrescue.map in the current directory or, if this fails, to $HOME/ddrescue.map. If the mapfile is written successfully, ddrescue exits with status 1. Else it prints the above message again.
Or you may press <q> followed by <Return> to quit and exit with status 1. In this case the content of the mapfile is lost.
Ddrescue may be better than dd for copying recordable CD-ROMs because the two lead out sectors at the end of some of them may cause a read error that prevents the whole last record from being copied by dd, potentially losing data. Also dd may create an image larger than the original if the 'sync' conversion and a block size larger than the sector size are specified.
In the special case of reading CD-ROMs (but not DVDs), the specialized tool dvdisaster may be a better option than ddrescue for recovering data because dvdisaster can read and analyze raw CD sectors, which ddrescue can't.
Recordable CD and DVD media keep their data only for a finite time (typically for some years). After that time, data loss develops slowly with read errors growing from the outer region towards the inside. It is a good idea to make two (or more) copies of every important CD-ROM/DVD you burn so that you can later recover them with ddrescue.
If you have only one copy of a CD-ROM or DVD that fails when being copied, and if you have access to multiple optical media drives, you have a better chance of recovering the bad sectors since one drive may fail to read a particular sector, but another drive might be able to squeeze the data out of it, depending on the laser frequency and the sensitivity of the laser-sensor that reads the reflected laser light.
If ddrescue is interrupted by a signal, it updates mapfile and then terminates by raising the signal received.
ddrescue written by Antonio Diaz Diaz, download from the GNU website.
Installs as /usr/bin/ddrescue
Rescue a CD-ROM in /dev/cdrom:
ddrescue -n -b2048 /dev/cdrom cdimage mapfile ddrescue -d -r1 -b2048 /dev/cdrom cdimage mapfile (if bad-sector size is zero, cdimage now contains a complete image of the CD-ROM and you can write it to a blank CD-ROM)
Rescue a CD-ROM in /dev/cdrom from two copies:
ddrescue -n -b2048 /dev/cdrom cdimage mapfile ddrescue -d -b2048 /dev/cdrom cdimage mapfile (insert second copy in the CD drive) ddrescue -d -r1 -b2048 /dev/cdrom cdimage mapfile (if bad-sector size is zero, cdimage now contains a complete image of the CD-ROM and you can write it to a blank CD-ROM)
Rescue a CD-ROM in /dev/cdrom using two CD drives from two different computers, writing the image into an USB drive mounted on /mnt/mem:
ddrescue -n -b2048 /dev/cdrom /mnt/mem/cdimage /mnt/mem/mapfile ddrescue -d -r1 -b2048 /dev/cdrom /mnt/mem/cdimage /mnt/mem/mapfile (umount the USB drive and move both USB drive and CD-ROM to second computer) ddrescue -d -r1 -b2048 /dev/cdrom /mnt/mem/cdimage /mnt/mem/mapfile (if bad-sector size is zero, /mnt/mem/cdimage now contains a complete image of the CD-ROM and you can write it to a blank CD-ROM)
Merge the partially recovered images of 3 identical DVDs using their mapfiles as domain mapfiles:
ddrescue -m mapfile1 dvdimage1 dvdimage mapfile ddrescue -m mapfile2 dvdimage2 dvdimage mapfile ddrescue -m mapfile3 dvdimage3 dvdimage mapfile (if bad-sector size is zero, dvdimage now contains a complete image of the DVD and you can write it to a blank DVD)
Recover a lzip compressed backup from two copies on CD-ROM with error-checked merging of copies:
ddrescue -d -r1 -b2048 /dev/cdrom cdimage1 mapfile1 mount -t iso9660 -o loop,ro cdimage1 /mnt/cdimage cp /mnt/cdimage/backup.tar.lz rescued1.tar.lz umount /mnt/cdimage (insert second copy in the CD drive) ddrescue -d -r1 -b2048 /dev/cdrom cdimage2 mapfile2 mount -t iso9660 -o loop,ro cdimage2 /mnt/cdimage cp /mnt/cdimage/backup.tar.lz rescued2.tar.lz umount /mnt/cdimage lziprecover -v -m -o backup.tar.lz rescued1.tar.lz rescued2.tar.lz Input files merged successfully. lziprecover -tv backup.tar.lz backup.tar.lz: ok
To copy /dev/sda (damaged \device\harddisk0) to another drive /dev/sdb (empty \device\harddisk1)
ddrescue /dev/sda /dev/sdb
To recover the partition data run fsck, for example if /home (user data) is on /dev/sda2, run fsck on partition /dev/sdb2:
fsck /dev/sdb2
This avoids touching the damaged /dev/sda, if the procedure fails you can send the original disk to a professional data recovery service.
Lastly mount the partition somewhere and see if you can access the data:
mount /dev/sdb2 /mnt/data
“Rescue me, Oh take me in your arms, Rescue me” ~ Aretha Franklin
GNU ddrescue Manual.
info ddrescue - full ddrescue manual.
ddrescuelog - Tool for ddrescue logfiles.
dd_rescue - written by Kurt Garloff for Debian.
ddrescue example macOS - macosxhints.
dd - Data Duplicator - Convert and copy a file.