The wise technician knows the art of retrieval; in the battlefield of data, victory lies not in avoiding loss, but in mastering the path to recovery.
~Moon Tzu
Table of Contents
Introduction to Data Recovery Basics
Data loss happens to the best of us—it’s an unfortunate reality in our digital lives. Maybe it was a misplaced keystroke, an accidental formatting, or even a hard drive deciding it needed a nap. The causes range from human error to technical hiccups, and even good old-fashioned software bugs. But whatever the reason, knowing how to recover lost data is a lifesaver.
Linux stands out as a top choice for data recovery because it plays nicely with USBs, disks, and partitions without making changes unless you ask it to. Unlike certain other systems (ahem Windows), it doesn’t sneakily write to your drives. Instead, it’s a controlled, stable environment, making it perfect for safe, hands-on recovery.
Key tools for data recovery in Linux include TestDisk
and PhotoRec
, which allow you to inspect, recover, and restore files without putting your data at further risk. We’ll use a Linux bootable USB drive with these tools to get us started on the path to recovery.
This process is so easy that even my Grandma can do it !
Accidental Data Deletion Scenarios
Losing data can feel like that moment you realize you’ve sent a text to the wrong person—it happens fast, it’s frustrating, and you wish you could hit undo. Let’s go over some common “Oops!” moments that lead to data loss, so you’re aware of what to watch out for and, hopefully, avoid the heartache.
Formatting Wrong Drive: Formatting mistakes can erase important data. Always confirm the drive/partition name before formatting.
Interrupting USB Transfer: Unplugging a USB mid-transfer can corrupt data. Wait for the “Safe to Remove” prompt!
Partition Errors: Mistakes while resizing/deleting partitions can wipe data. Backup before making any changes.
OS Reinstall Without Backup: Reinstalling OS without backup can erase files. Backup everything beforehand.
In short: always back up your data!
Creating a Bootable Linux USB for Recovery
Since I’ve already written a step-by-step guide on creating a bootable USB, feel free to refer to that for detailed instructions. For this tutorial, I’m using an Ubuntu 20 ISO as my preferred Linux OS for booting into recovery mode. You can follow the exact same steps with any tool like Balena Etcher or Rufus to create your USB.
Once you have your Linux bootable USB ready, all you need to do is plug it in and boot up your system. Be sure to press the appropriate boot key (usually F12, F2, F9,F10 or Esc depending on your system) to select the USB as your boot device. From there, you’ll enter your Linux OS and be ready to start the recovery process.
Let’s move on to the fun stuff—getting that data back!
Installing TestDisk and Preparing for Recovery
To recover lost files, TestDisk is a go-to tool for its reliability and effectiveness. Here’s how to get it set up on Linux, plus some tips on safely handling the affected drive.
The Importance of Not Writing to the Affected Drive
Before we dive in, remember: do not write or save anything on the drive where your lost data was stored. Writing new data can overwrite the deleted files, making recovery much harder or even impossible. For best results, work from a separate bootable USB and install recovery tools there.
Methods to Install TestDisk on Linux
- Installing via
apt
(Debian/Ubuntu-based systems)- Open the terminal. and Run:
sudo apt update
sudo apt install testdisk
- This is the easiest method for Ubuntu and Debian users, as it pulls the latest available version from the system’s repositories.
- Installing via
yum
ordnf
(Fedora/RHEL-based systems)- For Fedora, CentOS, or RHEL users, use:
sudo yum install testdisk
or:
sudo dnf install testdisk
This method installs TestDisk directly from the distribution’s repository, ensuring compatibility.
Direct Download from the Official Website
- Visit TestDisk’s official download page.Download the latest version for Linux as a .tar.bz2 file.Extract it and navigate into the directory:
tar -xvjf testdisk-7.3-WIP.linux26-x86_64.tar.bz2
cd testdisk-7.3-WIP
- Run TestDisk with:
sudo ./testdisk_static
The above image shows my test setup . I will use these softwares to recover 4 images . My test pendrive is an old Kingston 2GB pendrive .
Recovering Data with TestDisk
Once you’ve got TestDisk installed, it’s time to roll up your sleeves and dive into recovery mode. TestDisk might look a bit like a retro video game (no fancy graphics here!), but it’s powerful and gets the job done.
Step-by-Step Guide to Scanning Drives
- Launch TestDisk
Open up a terminal and launch TestDisk by entering:
sudo testdisk
- You’ll see a menu asking if you want to create a new log file. This is handy if you need to track your recovery process, but it’s optional.
- Select the Drive to Scan
TestDisk will display a list of all connected drives. Use the arrow keys to select the drive where you lost your data, then press Enter to proceed.
- Choose the Partition Table Type
TestDisk tries to detect the partition type automatically, so most users can just select [Intel] or [EFI GPT] if prompted. Just press Enter if you’re unsure. - Analyze for Lost Partitions
Choose [Analyze] and hit Enter. TestDisk will scan for lost partitions or deleted files. The first scan may be quick, but TestDisk will prompt you to do a deeper search if necessary. For more complex recoveries, go with the deep search!
Navigating TestDisk’s Recovery Options
Once you’ve scanned, TestDisk will present you with some options:
- List Files: To view recoverable files, choose [List] to see what’s there.
- Recover Files: Use the arrow keys to select specific files or folders, then press C to copy. You’ll be prompted to select a destination folder (more on that below).
- Write: If you’re recovering an entire partition, you can select [Write] to restore it. This is more advanced, so only do this if you’re sure about what you’re restoring.
Safely Recovering Data to an External Device
When you’re recovering files, always save them to a different drive or external device. This helps prevent overwriting other data on the affected drive.
- Select a Destination: After selecting files to recover, navigate to a safe drive or external device for storage.
- Confirm the Location: Double-check you’re saving to the right place and not accidentally back on the same drive you’re recovering from!
- Hit Recover: TestDisk will do its thing, and the files should start recovering to your chosen location.
Using PhotoRec for File Recovery
If TestDisk can’t locate your files or if you’re dealing with corrupted files, PhotoRec (included with TestDisk) is a great secondary option. Unlike TestDisk, which works at the partition level, PhotoRec is designed for file recovery on damaged or formatted partitions. Using this software is pretty straightforward , you can navigate through the menu using arrow keys and Enter key to select an item .
Here’s a quick guide to using PhotoRec:
- Launch PhotoRec:
Open PhotoRec by typingsudo photorec
in the terminal. - Choose the Drive:
Select the drive you want to recover files from. PhotoRec supports most storage media, including hard drives, SSDs, and USB drives. - Select Partition and File Types:
Once the drive is selected, choose the partition. You’ll also be prompted to choose the type of files to recover (e.g., images, documents, etc.), which can help speed up the process if you know what you’re looking for. When PhotoRec asks for the filesystem of your drive , remember this:
- “[ Other ] FAT/NTFS/HFS+/ReiserFS/…” for windows based systems .
- “[ ext2/ext3 ] ext2/ext3/ext4 filesystem” if your main system was Linux.
- Specify the Save Location:
Important: Always save recovered files to a different drive to avoid overwriting data on the affected drive. Press C when your save destination is correct .
- Start Recovery:
Once everything is set, start the recovery process. PhotoRec will scan and recover any detected files to the specified location.
PhotoRec might not retain file names and structure, but it’s highly effective for recovering specific file types and bypassing partition issues.
Preventive Measures for Future Data Safety
To minimize future data loss, consider these preventive tips:
Keep a Bootable USB on Hand: Prepare a bootable Linux USB with recovery tools like TestDisk and PhotoRec for emergency data recovery.
Regular Backups: Schedule backups for important files and system data, ideally using a combination of local and cloud storage.
Use External Drives and Cloud Storage: Store critical files on external hard drives or cloud platforms for added redundancy.
[…] World’s Easiest Data Recovery Guide for USB Drives, HDDs, and SSDs : Recover your lost memorie… […]