Recover Deleted Files from Android Internal Storage with TestDisk in Termux

14 min read Step‑by‑step guide to recover deleted files from an Android device’s internal storage using the free TestDisk tool inside Termux, without rooting. October 11, 2026 08:00 How to Recover Deleted Files from Android Internal Storage Using TestDisk in Termux (No Root)

What you’ll accomplish

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.

Before you start

  • Charge your phone to at least 80 %. The process can take several minutes, and a power drop could interrupt the scan.
  • Free at least 200 MB of internal storage. Recovered files need a destination folder that isn’t on the same partition you are scanning.
  • Enable Developer Options & USB debugging. Settings > About phone > tap Build number seven times, then Settings > System > Developer options > toggle USB debugging on.
  • Install Termux from F-Droid or the Google Play Store. The F-Droid version receives regular security updates.
  • Back up anything you can’t afford to lose. While the method is read‑only, it’s good practice to keep a recent backup of important files.

Step 1 – Install and update Termux

  1. Open the Termux app.
  2. Run the following commands to update the package index and upgrade existing packages:
    pkg update && pkg upgrade -y
  3. Grant Termux access to your internal storage (required for copying recovered files later):
    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.

Step 2 – Install TestDisk (and the companion PhotoRec)

  1. Install the testdisk package from the default Termux repository:
    pkg install testdisk -y
  2. Verify the installation:
    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.

Step 3 – Identify the internal storage block device

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.

  1. Run the following command to list block devices and look for a line containing userdata:
    ls -l /dev/block/bootdevice/by-name/
  2. If the 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.
  3. Record the full path (e.g. /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).

Step 4 – Run TestDisk in read‑only mode

  1. Launch TestDisk with root‑like privileges (Termux runs as a regular user, but the --readonly flag prevents any write operation):
    testdisk /dev/block/mmcblk0p28 --readonly
    Replace /dev/block/mmcblk0p28 with the path you noted earlier.
  2. When the text UI appears, use the arrow keys to select Create (this creates a new log file) and press Enter.
  3. Choose the partition table type. In most cases TestDisk auto‑detects Intel/PC (GPT or MBR). If you see EFI GPT or Intel, accept the default.
  4. Select Analyse and press Enter. TestDisk will scan for existing partitions.
  5. After the quick scan finishes, you’ll see a list of partitions. Press Enter on Quick Search to let TestDisk look for deleted partitions.
  6. If the deleted files you need were on the primary userdata partition, you’ll usually see the same partition listed again. Choose Proceed.
  7. Now you are in the file‑listing view. Use the arrow keys to navigate directories. Deleted files are shown in red.
  8. To copy a file, press 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.
  9. Repeat the copy step for each file you need, or press a to copy an entire directory.
  10. When you are done, press q repeatedly to quit TestDisk.

All copied files now reside in /sdcard/Recovered, which you can view with any file manager.

Step 5 – Using PhotoRec for bulk media recovery

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.

  1. Start PhotoRec in read‑only mode:
    photorec /dev/block/mmcblk0p28
  2. Select the File Opt menu to enable only the file types you care about (e.g., JPG, PNG, MP4, MP3). This speeds up the scan.
  3. Choose Search. PhotoRec will ask where to store recovered files – again pick a folder on /sdcard, e.g. /sdcard/PhotoRec.
  4. Allow the scan to run. Depending on storage size, it may take 10‑30 minutes.
  5. When finished, open the destination folder. Files will be named generically (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.

Step 6 – Verify recovered data

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.

Safety warnings and best practices

  • Do not write to the same partition you are scanning. Even copying a single recovered file can overwrite other deleted data.
  • Keep the device idle during the scan. Close background apps that might write to internal storage (e.g., messaging apps, camera).
  • If you have a custom ROM that encrypts /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).
  • Never run TestDisk as su on a non‑rooted device – Termux cannot gain root, and forcing it can lead to unexpected crashes.

Troubleshooting common issues

TestDisk reports “Permission denied”

Even though Termux runs without root, it can read block devices that are world‑readable. Some manufacturers restrict this access. Workaround:

  1. Connect the phone to a PC with adb installed.
  2. Run 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
  3. Pull the image to the PC and run TestDisk on the computer. This is a fallback for devices that block direct access.

No files appear in red (deleted) after the scan

Possible reasons:

  • The file system has already overwritten the blocks. Try PhotoRec, which can still find signatures.
  • You scanned the wrong partition (e.g., cache instead of userdata). Double‑check the device path from Step 3.

PhotoRec stops with “Cannot allocate memory”

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).

After you’ve recovered your files

  • Move the recovered files to a safe location (cloud backup, PC, or external SD card).
  • Consider enabling Google Photos backup or another cloud sync service to avoid future loss.
  • If you frequently delete files, enable a “recycle bin” app (e.g., Dumpster) that keeps a temporary copy for 30 days.

Summary

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.

User Comments (0)

Add Comment
We'll never share your email with anyone else.