Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Linux Free Data Recovery: Tools That Work

· 7 min read · Home Tech

In this article
  1. Why Linux Is a Good Choice for Data Recovery
  2. How TestDisk and PhotoRec Work
  3. Imaging with ddrescue: The First Step for Failing Drives
  4. Choosing the Right Tool for Your Situation
  5. Common Mistakes and How to Avoid Them
  6. Costs and Limitations of Free Tools
  7. Frequently Asked Questions

Yes, Linux offers several genuinely free data recovery tools that can restore deleted files, recover partitions, and even salvage data from failing drives. You can get started with command-line utilities like testdisk and photorec, or use a graphical tool like ddrescue for imaging. These tools are open-source, widely available in every major distribution’s repositories, and are the same ones used by many professional recovery services.

Why Linux Is a Good Choice for Data Recovery

Linux is often preferred for data recovery because it gives you direct, low-level access to storage devices without the “helpful” abstractions that other operating systems impose. When you plug in a drive, Linux does not automatically mount it, write to it, or run disk-checking utilities that could overwrite the very data you are trying to save. This “no auto-mount” behavior is critical: every write to a damaged filesystem reduces the chance of recovering the files that remain.

Additionally, the core recovery tools are mature and battle-tested. TestDisk has been developed since 1998 and can rebuild partition tables, while PhotoRec scans raw blocks for file signatures, ignoring the filesystem entirely. Both are maintained by Christophe Grenier and are free under the GNU General Public License.

How TestDisk and PhotoRec Work

TestDisk and PhotoRec are separate programs that solve different problems, though they are often installed together.

  • TestDisk focuses on the partition table. If you accidentally deleted a partition, or a partition table became corrupted, TestDisk can scan the drive for the original partition boundaries and rewrite them. It supports MBR, GPT, and many filesystem types including ext4, NTFS, FAT, and HFS+.
  • PhotoRec ignores the filesystem entirely. It reads the raw blocks of a drive or image and looks for header/footer signatures of known file types (JPEG, PNG, ZIP, PDF, and hundreds more). It then reconstructs files from those signatures. This works even if the filesystem is severely damaged or formatted, but it loses the original filenames and folder structure—recovered files are named like f1234567.jpg.

Both tools are run from the command line, but they have interactive, menu-driven interfaces that are surprisingly easy to navigate. You select the device, the partition, the file system type (or let PhotoRec auto-detect), and choose where to save the recovered files.

Imaging with ddrescue: The First Step for Failing Drives

If your drive is making clicking noises, is slow, or has bad sectors, you should not run recovery tools directly on it. Every read attempt can stress the drive further. The standard practice is to create a bit-for-bit image first using ddrescue (note: not dd, but the GNU ddrescue package).

ddrescue works by copying data from the source to an image file, but it does so intelligently: it reads good areas first, then goes back for bad sectors, and it logs its progress in a mapfile. If the drive fails mid-copy, you can run the same command again and it will resume from where it left off, skipping what is already saved.

sudo ddrescue /dev/sdb /media/backup/disk.img /media/backup/disk.mapfile

After you have a complete image, you can run TestDisk or PhotoRec on the image file instead of the physical drive. This keeps the original drive untouched and lets you retry recovery attempts as many times as you like.

Choosing the Right Tool for Your Situation

The right tool depends on what went wrong and what you want back.

  • Accidentally deleted files on a healthy drive? Use extundelete for ext3/ext4 filesystems, or ext4magic for ext4. For NTFS, try ntfsundelete. These tools work with the filesystem’s journal and metadata to recover files that still have their inode entries intact.
  • Formatted a partition or lost the partition table? TestDisk is your first choice. It can often rebuild the partition table exactly as it was, making all files visible again without any file-level recovery.
  • Filesystem is corrupted or unreadable? PhotoRec is the fallback. It does not care about the filesystem at all, so it can pull files from a drive that no longer mounts.
  • Drive is failing physically? Use ddrescue first to image the drive, then run the recovery tools on the image.

For most home users, the combination of TestDisk and PhotoRec covers 90% of scenarios. They are included in the testdisk package on Debian/Ubuntu, and in the testdisk package on Fedora and Arch as well.

Common Mistakes and How to Avoid Them

Even with the right tools, people often sabotage their own recovery. The most common mistake is installing the recovery software on the same drive you are trying to recover. That writes new data, which can overwrite the deleted files. Instead, boot from a live USB stick and install the tools there, or use a separate drive for the software.

Another mistake is running fsck (filesystem check) on a damaged filesystem. While fsck can fix structural issues, it often moves or deletes files that it considers “unrecoverable” to make the filesystem consistent again. That can destroy the very data you wanted to save. Always image the drive first, and run fsck only on the image if you must.

A third mistake is saving recovered files to the same drive. Always save to a different physical drive, or to a network location. If you save to the same drive, the recovery process itself can overwrite other deleted files.

Costs and Limitations of Free Tools

The tools themselves are free, but there are hidden costs. You need a second storage device with enough space to hold the image of the failing drive—if your drive is 1 TB, you need 1 TB of free space elsewhere. You also need time: ddrescue on a large drive with many bad sectors can run for days. And you need patience to learn the command-line interface, though the interactive menus help.

Limitations are real. PhotoRec does not preserve filenames or folder structure. Extundelete only works on ext3/ext4 and only if the filesystem journal still contains the needed metadata—if you deleted a file and then used the computer for a while, the inode may already be reused. No free tool can guarantee 100% recovery, especially after a drive has been formatted or heavily used.

For a professional recovery service, you might pay hundreds or thousands of dollars, but they have cleanroom facilities and specialized hardware for physically damaged drives. Free software cannot fix a drive with a crashed read/write head, but it can often extract data from a drive that is logically damaged or has bad sectors.

Frequently Asked Questions

Can I recover data from a formatted drive using Linux?

Yes, but it depends on the format. If you formatted a partition with a new filesystem, the old data is usually still there until overwritten. PhotoRec can scan the raw blocks and recover files by their signatures, regardless of the new filesystem. TestDisk might also help if the partition table was the only thing changed, but if the filesystem was rewritten, you will need PhotoRec.

Is it safe to install TestDisk on my main system?

Yes, installing the software is safe. The danger is running it on the drive you are trying to recover. Always boot from a live USB or use a separate recovery drive, and never save recovered files to the same drive.

What is the difference between TestDisk and PhotoRec?

TestDisk repairs partition tables and boot sectors, making entire partitions accessible again. PhotoRec scans raw data for file signatures and recovers individual files, ignoring the filesystem. Use TestDisk first to fix the partition, and if that does not work, use PhotoRec for file-level recovery.

Can I recover files from an SSD with Linux tools?

Yes, but SSDs have a complication: the TRIM command can permanently erase deleted data. If TRIM is enabled and the drive has been used after deletion, recovery is unlikely. If the drive is failing or the filesystem is corrupted, the same tools (ddrescue, TestDisk, PhotoRec) work on SSDs just as they do on hard drives.

How long does a recovery take?

It varies wildly. Recovering a few accidentally deleted files with extundelete can take minutes. Scanning a 1 TB drive with PhotoRec can take several hours, and ddrescue on a failing drive with bad sectors can take days. The speed depends on the drive size, the number of bad sectors, and the speed of your hardware.

Do I need to be a command-line expert to use these tools?

No. TestDisk and PhotoRec have interactive, menu-driven interfaces that guide you step by step. You do need to know the device name (like /dev/sdb) and be comfortable with sudo, but you do not need to write scripts. Many tutorials and forums can walk you through the exact keystrokes.