TestDisk is a powerful open-source tool used to recover lost partitions, repair partition tables, and restore boot sectors on Linux systems.
๐ฆ Install TestDisk
Ubuntu / Debian
sudo apt update
sudo apt install testdisk
Fedora
sudo dnf install testdisk
Arch Linux
sudo pacman -S testdisk
โถ๏ธ Launch TestDisk
Run with root privileges:
sudo testdisk
๐งญ Basic Navigation Controls
- Arrow keys โ Move
- Enter โ Select
- Q โ Quit / Go back
๐ง Step-by-Step: Recover Lost Partitions
1. Create a Log File
- Select Create โ Press Enter
2. Select Your Drive
- Choose your disk (e.g.,
/dev/sda) - Press Enter
3. Select Partition Table Type
- Usually auto-detected:
- Intel/PC (MBR)
- EFI GPT (modern systems)
4. Analyze the Disk
- Select Analyze
- Press Enter
- Choose Quick Search
5. View Found Partitions
- Highlight a partition
- Press P to preview files
โ If files look correct โ proceed
6. Write the Partition Table
- Press Enter โ Select Write
- Confirm with Y
โ ๏ธ Reboot after writing changes:
sudo reboot
๐ ๏ธ Recover Deleted Files (Advanced)
TestDisk includes PhotoRec for file recovery:
sudo photorec
- Select drive
- Choose file types
- Pick recovery location
โ Recovers files even from damaged partitions
โ ๏ธ Important Tips
- Always run as root (sudo)
- Avoid writing to the affected drive before recovery
- Use a separate drive for recovered files
- GPT systems are common on newer PCs
๐ง When to Use TestDisk
- Lost or deleted partitions
- Corrupted partition tables
- System wonโt boot
- Missing drives after OS install
๐ Alternative Tools
- GParted (GUI partition tool)
- ddrescue (advanced disk recovery)