System Administration

Essential System Tools: ddrescue – Data recovery software

Last Updated on May 28, 2022

This is the tenth in our series of articles highlighting essential system tools. These are small, indispensable utilities, useful for system administrators as well as regular users of Linux based systems. The series examines both graphical and text based open source utilities. For this article, we’ll look at ddrescue. Anyone who cares about preserving their data should invest a bit of time in learning about this utility. For details of all tools in this series, please check the table in the summary section.

Linux is an excellent operating system to recover data with a wide variety of open source tools designed to clone and recover data from failing drives. When rescuing data from a dying hard drive, time is of the essence. A drive may degrade with each attempt to access it. The longer it takes to copy your data, the more data is at risk. ddrescue is one of our favorite data recovery tools. It’s maintained by the GNU project.

ddrescue copies data from one file or block device to another, trying to rescue the good parts first in case of read errors, scheduling reads inside bad (or slow) areas for later. This process maximizes the amount of data that can be finally recovered from a failing device. ddrescue uses a sophisticated algorithm to copy data from failing drives causing them as little additional damage as possible.

Installation

ddrescue is mature software with packages available for all popular Linux distribution.

The full source code is available in the event you want to compile the source code.

In operation

ddrescue is a command-line tool. There’s no fancy graphical frippery here. If you prefer using graphical tools, there are a couple of frontends available: DDRescue-GUI and ddrescueview.

The format for running ddrescue is:

ddrescue [OPTIONS] INFILE OUTFILE [MAPFILE]

An example command:

# ddrescue -d -r3 /dev/sdb test.img example.mapfile

Both INFILE and OUTFILE can be files, devices or partitions. In the example above the INFILE is /dev/sdb, an entire drive. The -r 3 option instructs the software to carry out 3 passes of the data.

The final parameter is MAPFILE, a text file that must reside in an existing directory. It’s important to use a MAPFILE as this enables the software to resume a rescue. If MAPFILE doesn’t exist, the software will create it. The file is formed by three parts, the heading comments, the status line, and the list of data blocks. The character ‘#’ at the beginning of a line or after whitespace starts a comment that extends to the end of the line.

When running ddrescue, it’s imperative the device is not mounted.

Features include:

  • Fast and reliable in operation. That’s rather essential with a disk recovery tool!
  • 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.
  • The mapfile lets you combine results of different attempts of saving your drive. This maximizes the amount of data that can be recovered. Every time you run it on the same output file, it tries to fill in the gaps without wiping out the data already rescued.
  • “Fill mode” able to selectively overwrite parts of the output file. This can be used to mark bad areas, or wipe data.
  • Can use direct disc access to read the input file, bypassing the kernel cache.
  • Extract data from a device even when the Linux kernel refuses to read the partition table.
  • Operates at the block level, rather than the filesystem level, so it doesn’t matter what filesystem is on the device. This tool is therefore not limited to recovering data stored on Linux devices, it can also recover data on Windows and Mac OS X storage devices.

Summary

What we like about ddrescue is that it can be used for any mechanical device supported by your kernel such as SATA – even old devices like ATA, SCSI, MFM, floppy discs are supported. CDs/DVDs are also supported. We’ve saved quite a few mechanical hard drives with this tool over the years.

Note, ddrescue is designed for mechanical devices. It’s not recommended to use the software with SSDs as it doesn’t deal with failing blocks properly as the Flash Translation layer changes the topography.

While dd can save drives too, it reads data sequentially, which can wear out the drive without rescuing any of the data if the errors are at the beginning of the drive.

Website: www.gnu.org/software/ddrescue/
Support: Manual
Developer: Antonio Diaz Diaz
License: GNU General Public License version 3

ddrescue is written in C++. Learn C++ with our recommended free books and free tutorials.


All the essential tools in this series:

Essential System Tools
AlacrittyInnovative, hardware-accelerated terminal emulator
BleachBitSystem cleaning software. Quick and easy way to service your computer
bottomGraphical process/system monitor for the terminal
btop++Monitor usage and stats for CPU, memory, disks, network and processes
catfishVersatile file searching software
ClonezillaPartition and disk cloning software
CPU-XSystem profiler with both a GUI and text-based
CzkawkaFind duplicate files, big files, empty files, similar images, and much more
ddrescueData recovery tool, retrieving data from failing drives as safely as possible
dustMore intuitive version of du written in Rust
f3Detect and fix counterfeit flash storage
Fail2banBan hosts that cause multiple authentication errors
fdupesFind or delete duplicate files
FirejailRestrict the running environment of untrusted applications
GlancesCross-platform system monitoring tool written in Python
GPartedResize, copy, and move partitions without data
GreenWithEnvyNVIDIA graphics card utility
gtopSystem monitoring dashboard
gWakeOnLANTurn machines on through Wake On LAN
hyperfineCommand-line benchmarking tool
HyFetchSystem information tool written in Python
inxiCommand-line system information tool that's a time-saver for everyone
journalctlQuery and display messages from the journal
kmonManage Linux kernel modules with this text-based tool
KrusaderAdvanced, twin-panel (commander-style) file manager
NmapNetwork security tool that builds a "map" of the network
nmonSystems administrator, tuner, and benchmark tool
nnnPortable terminal file manager that's amazingly frugal
petSimple command-line snippet manager
PingnooGraphical representation for traceroute and ping output
ps_memAccurate reporting of software's memory consumption
SMCMulti-featured system monitor written in Python
TimeshiftReliable system restore tool
QDirStatQt-based directory statistics
QJournalctlGraphical User Interface for systemd’s journalctl
TLPMust-have tool for anyone running Linux on a notebook
UnisonConsole and graphical file synchronization software
VeraCryptStrong disk encryption software
VentoyCreate bootable USB drive for ISO, WIM, IMG, VHD(x), EFI files
WTFPersonal information dashboard for your terminal
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Please read our Comment FAQ before posting a comment.

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Goofy User
Goofy User
1 year ago

sure, looks like all this software leads to a version that has to be purchased.

Nigel Bolton
Nigel Bolton
1 year ago
Reply to  Goofy User

Goofy, please don’t troll. It isn’t funny.