Yes, you can recover an ext4 partition in most cases, provided you stop using the drive immediately and use the right tools. This guide explains the common causes of ext4 partition loss, the recovery options available, and the step-by-step process to get your data back.
Why ext4 Partitions Get Lost
The ext4 filesystem is the default for most Linux distributions, known for its robustness and journaling. However, partitions can still become inaccessible due to:
- Accidental deletion – deleting the partition with fdisk or GParted instead of just unmounting it.
- Filesystem corruption – from improper shutdowns, power outages, or hardware issues.
- Bad sectors – physical damage to the disk that makes the partition table unreadable.
- Partition table overwritten – installing a new OS or using a disk utility that rewrites the MBR or GPT.
- Failed resize or move – interrupted operations that leave the partition in an inconsistent state.
Understanding the cause matters because it determines whether you need to repair the filesystem or use data recovery software.
First Steps: Stop Using the Drive
The most critical rule in any data recovery scenario is to stop writing to the affected drive. Every new file, even a log entry, can overwrite the very data you are trying to recover. If the partition is still mounted, unmount it immediately:
- Open a terminal and run
umount /dev/sdX1(replace sdX1 with your partition). - If the drive is your system drive and you cannot unmount it, boot from a live USB stick.
- Do not run filesystem checks like
fsckuntil you have a backup of the current state, as fsck can make things worse if the partition table is damaged.
If the partition is missing entirely, do not create a new partition in its place. The old partition table entry may be recoverable, and creating a new one can overwrite it.
Recovery Methods: From Simple to Advanced
Depending on the situation, you can try one of these approaches:
1. Check the Partition Table
Sometimes the partition is not lost, just hidden. Use fdisk -l or gdisk -l to list all partitions. If you see the partition but it is not mounting, the problem may be a corrupted superblock or filesystem, not a lost partition.
2. Restore the Partition Table with TestDisk
TestDisk is a free, open-source tool that can scan for lost partitions and rewrite the partition table. It is often the first choice because it can recover the entire partition structure, making all files accessible again without individual file recovery.
- Boot from a live Linux USB and install testdisk (
sudo apt install testdisk). - Run
testdiskand select the disk, then choose the partition table type (usually Intel for MBR or EFI GPT). - Select Analyse and then Quick Search. If it finds the lost partition, highlight it and press Enter to confirm.
- Write the new partition table using the Write option.
TestDisk works best when the partition was deleted or the table was overwritten, but the underlying data is intact.
3. Use PhotoRec for Individual Files
If the partition table is beyond repair or the filesystem is severely corrupted, PhotoRec (also from the TestDisk suite) can recover files by their signatures, ignoring the filesystem structure. It is slower and recovers files with generic names, but it works even on formatted or partially overwritten drives.
Repairing a Corrupted ext4 Filesystem
If the partition is visible but won’t mount, the filesystem itself may be damaged. The standard tool is fsck.ext4 (or e2fsck).
- Unmount the partition.
- Run
sudo fsck.ext4 -f /dev/sdX1. The-fforces a check even if the filesystem appears clean. - If the superblock is corrupted, you may see an error. You can use a backup superblock:
sudo fsck.ext4 -b 32768 /dev/sdX1(the backup superblock location varies; check withdumpe2fs -hif possible). - Answer
yto fix any errors found.
Important: fsck can cause further data loss if the filesystem is badly damaged. Always create a disk image first if you are unsure.
Creating a Disk Image Before Recovery
Before attempting any recovery, it is wise to make a bit-for-bit copy of the drive. This protects the original from further damage and lets you work on the copy without risk.
- Use
ddto create an image:sudo dd if=/dev/sdX of=/path/to/image.img bs=4M status=progress. - Or use
ddrescuefor drives with bad sectors, as it handles read errors better. - Run recovery tools on the image file instead of the physical drive.
This step is especially important if the drive makes clicking noises or is otherwise failing physically.
Choosing the Right Tool: TestDisk vs PhotoRec vs Commercial
There is no single best tool; it depends on your situation.
- TestDisk – best for recovering a lost partition table. It is fast and restores the original structure.
- PhotoRec – best when the filesystem is gone or unreadable. It recovers files by content, but loses filenames and folder structure.
- Commercial tools (like R-Studio, EaseUS, or Disk Drill) – often have a graphical interface and can recover files with original names from ext4 partitions. They are not free, but may be worth it for critical data.
If you have a backup of the partition table (e.g., from sfdisk -d), you can restore it directly with sfdisk. This is the simplest method if you had the foresight to save it.
Common Mistakes and Misconceptions
- Running fsck on a mounted partition – this can cause more corruption. Always unmount first.
- Installing recovery software on the same drive – this overwrites data. Use a live USB or a different drive.
- Thinking that a formatted partition is gone forever – formatting only writes new filesystem metadata; the old data often remains until overwritten.
- Ignoring SMART health – if the drive is failing, recovery becomes a race against time. Check SMART status with
smartctlbefore starting.
Another misconception is that journaling guarantees recovery. The ext4 journal helps with consistency, not with data recovery after partition loss.
Frequently Asked Questions
Can I recover an ext4 partition after reinstalling Linux?
Yes, if the reinstall only overwrote the partition table and not the entire disk. Use TestDisk to scan for the old partition. If the installer formatted the partition, the data may still be recoverable with PhotoRec, but filenames will be lost.
How long does ext4 recovery take?
It depends on the disk size and the method. A partition table restore with TestDisk can take minutes. A full file recovery with PhotoRec on a 1TB drive can take hours or even days.
Is it safe to use fsck on a corrupted ext4 partition?
fsck is safe if the partition is unmounted and you have a backup or image. It can repair the filesystem, but if it encounters severe damage, it may move files to lost+found, which is better than losing them entirely.
What is the difference between TestDisk and PhotoRec?
TestDisk recovers the partition structure, making the whole partition mountable again. PhotoRec recovers individual files by scanning raw data, ignoring the filesystem. TestDisk is preferred when the partition table is the problem; PhotoRec is a last resort when the filesystem is destroyed.
Can I recover an ext4 partition from a failing hard drive?
Yes, but you should first clone the drive with ddrescue to a healthy disk. Working directly on a failing drive risks further damage. After cloning, run recovery tools on the copy.
Will I get my original filenames back?
If you recover the partition table with TestDisk, yes. If you use PhotoRec, no – it assigns generic names like f1234567.ext. Commercial tools often preserve names if the filesystem metadata is still readable.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Increase Internal Memory Xiaomi Phones: How-To
- Nvidia Display Settings Are Not Available: Fixes
- Gmod Keeps Crashing? Fixes That Actually Work
- Cloudflare cf CLI: How Coding Agents Discover & Run Commands
- Protect AI from Model Extraction & Distillation
- Net Code Analysis Workflow: A Reliable Setup Guide