Install required dependencies:
sudo apt-get update && sudo apt-get install -y \
build-essential \
libext2fs-dev \
libewf-dev \
libncurses5-dev libncursesw5-dev \
ntfs-3g-dev \
libjpeg-dev \
uuid-dev \
zlib1g-dev \
qtbase5-dev \
qttools5-dev-tools \
pkg-config \
dh-autoreconf \
gettext \
gitgit clone https://github.com/cgsecurity/testdisk.git
cd testdiskmkdir config
autoreconf --install -W all -I config
./configure
make(Optional: to build a static binary)
make staticsudo make installAfter a successful build, the following tools will be created:
testdisk– partition recovery toolphotorec– file recovery toolfidentify– file type identifierqphotorec– graphical interface for PhotoRec
sudo testdisk # Start interactive recovery
testdisk /log # Enable logging
testdisk /list # List connected diskssudo photorec # Start interactive file recovery
photorec /log # Enable logging
photorec /d recovery_dir /cmd device # Command-line recoveryfidentify yourfile.raw # Detect file types in disk images or raw filesqphotorec # Start GUI version of PhotoRecsudo fdisk -lFind your USB device (e.g., /dev/sdb).
sudo fdisk /dev/sdX # Replace sdX with your USB deviceInside fdisk:
- Press
n→ create a new partition - Press
w→ write and exit - (Optional) Copy a test file to the USB
- Run
fdiskagain:- Press
d→ delete the partition - Press
w→ write and exit
- Press
sudo testdiskFollow the interactive steps to scan and restore the deleted partition.
sudo photorecChoose your USB device, file system type, and recovery destination directory.
Before starting recovery, you can set setting to how PhotoRec revcver your device:
Customize scanning behavior:
-
Paranoid: Yes / No
If enabled, PhotoRec checks for block consistency to reduce false positives (slower but safer). -
Keep corrupted files: Yes / No
If enabled, even damaged files will be saved. Otherwise, they are skipped. -
Expert mode: Yes / No
Unlocks advanced options like custom block sizes or forced file system detection. -
Low memory: Yes / No
Enables a memory-saving mode for systems with limited RAM (may reduce performance).
Use the arrow keys to navigate and press Enter to toggle values.
PhotoRec can recover many types of files. This menu lets you choose which ones to include in the scan.
[X]= Selected (will be recovered)[ ]= Not selected (will be skipped)
Space→ Toggle selected formats→ Deselect allb→ Save selectionEnter→ Next pageq→ Back to main menu
You can download the official documentation for TestDisk and PhotoRec here:
On page 45, there’s a section titled "CREATING CUSTOM SIGNATURE FOR PHOTOREC" — but I try it, it not work as expected.
At the end of page 47, there’s a guide for developing main source code: