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.
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.
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.
- 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.
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.
All the essential tools in this series:
|Essential System Tools|
|Alacritty||Innovative, hardware-accelerated terminal emulator|
|BleachBit||System cleaning software. Quick and easy way to service your computer|
|bottom||Graphical process/system monitor for the terminal|
|btop++||Monitor usage and stats for CPU, memory, disks, network and processes|
|catfish||Versatile file searching software|
|Clonezilla||Partition and disk cloning software|
|CPU-X||System profiler with both a GUI and text-based|
|Czkawka||Find duplicate files, big files, empty files, similar images, and much more|
|ddrescue||Data recovery tool, retrieving data from failing drives as safely as possible|
|dust||More intuitive version of du written in Rust|
|f3||Detect and fix counterfeit flash storage|
|Fail2ban||Ban hosts that cause multiple authentication errors|
|fdupes||Find or delete duplicate files|
|Firejail||Restrict the running environment of untrusted applications|
|Glances||Cross-platform system monitoring tool written in Python|
|GParted||Resize, copy, and move partitions without data|
|GreenWithEnvy||NVIDIA graphics card utility|
|gtop||System monitoring dashboard|
|gWakeOnLAN||Turn machines on through Wake On LAN|
|hyperfine||Command-line benchmarking tool|
|inxi||Command-line system information tool that's a time-saver for everyone|
|journalctl||Query and display messages from the journal|
|kmon||Manage Linux kernel modules with this text-based tool|
|Krusader||Advanced, twin-panel (commander-style) file manager|
|Neofetch||System information tool written in Bash|
|Nmap||Network security tool that builds a "map" of the network|
|nmon||Systems administrator, tuner, and benchmark tool|
|nnn||Portable terminal file manager that's amazingly frugal|
|pet||Simple command-line snippet manager|
|Pingnoo||Graphical representation for traceroute and ping output|
|ps_mem||Accurate reporting of software's memory consumption|
|SMC||Multi-featured system monitor written in Python|
|Timeshift||Reliable system restore tool|
|QDirStat||Qt-based directory statistics|
|QJournalctl||Graphical User Interface for systemd’s journalctl|
|TLP||Must-have tool for anyone running Linux on a notebook|
|Unison||Console and graphical file synchronization software|
|VeraCrypt||Strong disk encryption software|
|Ventoy||Create bootable USB drive for ISO, WIM, IMG, VHD(x), EFI files|
|WTF||Personal information dashboard for your terminal|