If you’ve accidentally deleted photos, documents, or messages from your phone’s internal storage, the data isn’t necessarily gone forever. Android’s file system keeps the raw data blocks until they are overwritten. By using the open‑source TestDisk suite inside the Termux terminal, you can scan those blocks and retrieve many of the lost files – all without rooting your device.
Why this works: TestDisk works at the block‑device level, bypassing the Android media‑store index that marks files as deleted. Because the operation is read‑only, it won’t damage existing data as long as you follow the safety steps.
pkg update && pkg upgrade -y
termux-setup-storage
You’ll see a system dialog – tap Allow.
After termux-setup-storage finishes, a new folder /storage/emulated/0 becomes accessible inside Termux as /sdcard.
testdisk package from the default Termux repository:
pkg install testdisk -y
testdisk --version
You should see a version number like 7.2.
PhotoRec, which ships with TestDisk, is specialized for recovering media files (photos, videos, audio). We’ll use it later for a quick media‑only recovery.
Android presents internal storage as a set of block devices under /dev/block. The exact name varies by manufacturer and Android version, but most modern devices expose a single logical partition called userdata.
userdata:
ls -l /dev/block/bootdevice/by-name/
by-name directory does not exist (common on older devices), fall back to:
df -h
The line that shows /data will have a device path in the first column, e.g. /dev/block/mmcblk0p28. That is the block device you’ll feed to TestDisk.
/dev/block/mmcblk0p28) – you’ll need it in the next step.
If you cannot see any block device, make sure the android.permission.READ_EXTERNAL_STORAGE permission is granted (Termux asks for it automatically after termux-setup-storage).
--readonly flag prevents any write operation):
testdisk /dev/block/mmcblk0p28 --readonly
Replace /dev/block/mmcblk0p28 with the path you noted earlier.
Enter.
Intel/PC (GPT or MBR). If you see EFI GPT or Intel, accept the default.
Enter. TestDisk will scan for existing partitions.
userdata partition, you’ll usually see the same partition listed again. Choose Proceed.
c. TestDisk will ask for a destination folder. Type a path on the /sdcard side, for example:
/sdcard/Recovered
If the folder does not exist, TestDisk will create it.
a to copy an entire directory.
q repeatedly to quit TestDisk.
All copied files now reside in /sdcard/Recovered, which you can view with any file manager.
If you lost many photos, videos, or audio files, navigating the TestDisk file list can be tedious. PhotoRec scans the raw block device and extracts files based on signatures, ignoring the file system entirely.
photorec /dev/block/mmcblk0p28
/sdcard, e.g. /sdcard/PhotoRec.
recup_dir.1/f123456789.jpg), but the extensions are correct, making it easy to sort.
Because PhotoRec does not rely on the file system, it can recover files even when the partition table is corrupted.
After copying, open a few files with the appropriate apps (Gallery for images, VLC for videos, etc.) to confirm they are intact. If a file fails to open, it may have been partially overwritten; you can try recovering it again with a different destination folder to avoid further overwriting.
/data, TestDisk may not be able to read the raw blocks. In that case, you’ll need to decrypt the device first (which usually requires root).su on a non‑rooted device – Termux cannot gain root, and forcing it can lead to unexpected crashes.Even though Termux runs without root, it can read block devices that are world‑readable. Some manufacturers restrict this access. Workaround:
adb installed.adb shell and then su – if the device is rooted, you can copy the block device to a temporary file on /sdcard:
dd if=/dev/block/mmcblk0p28 of=/sdcard/userdata.img bs=4M
Possible reasons:
cache instead of userdata). Double‑check the device path from Step 3.Termux limits RAM usage. Increase the virtual memory limit by editing ~/.termux/termux.properties and adding extra-keys = ... – but the simplest fix is to limit the scan to a specific directory type via the File Opt menu, or run PhotoRec on a smaller partition (e.g., only /sdcard if you have external storage).
Using TestDisk and PhotoRec inside Termux gives you a powerful, no‑root method to scan the raw internal storage of an Android phone and pull out deleted files. By following the read‑only workflow, keeping the device idle, and copying recovered data to a separate partition, you minimize the risk of overwriting the very data you’re trying to rescue. While the method works best on unencrypted devices, it remains a valuable tool for many Android users who need a quick, offline recovery solution.









