How to Recover Data from Corrupt/Formatted USB Flash using Photorec

Hi all, today we'll be helping you guys to recover data from your formatted or virus corrupt USB Flash(Pen drive) , Hard Disk, Memory Sticks, etc in Linux. In this tutorial we'll be using PhotoRec, a package of TestDisk.

TestDisk is a free and Open Source Software which was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally deleting a Partition Table).

If you accidentally deleted your data or you formatted your USB flash or your friend running Virus full Windows corrupted it then, PhotoRec is an awesome tool for you to choose for Data Recovery.

TestDisk can

  • Fix partition table, recover deleted partition
  • Recover FAT32 boot sector from its backup
  • Rebuild FAT12/FAT16/FAT32 boot sector
  • Fix FAT tables
  • Rebuild NTFS boot sector
  • Recover NTFS boot sector from its backup
  • Fix MFT using MFT mirror
  • Locate ext2/ext3/ext4 Backup SuperBlock
  • Undelete files from FAT, exFAT, NTFS and ext2 filesystem
  • Copy files from deleted FAT, exFAT, NTFS and ext2/ext3/ext4 partitions.

Here are the steps that you'll need to follow to use photorec to recover data from the memory device:

1. Installing PhotoRec

First we'll need to update our repository index using the command below, I am running Ubuntu 14.04 LTS (Trusty) so I will go for sudo apt-get update. It differs by distro used:

sudo apt-get update

Then, We'll gonna install testdisk which includes the package PhotoRec in it.

sudo apt-get install testdisk

Note: PhotoRec is included in testdisk, so you'll no need to install photorec separately. 

2. Recovering Data

Ok, now we'll go towards or real and important stuff ie Recovering our deleted data or formatted USB stick. For that we'll gonna run photorec. Photorec allows you to recover every type of data from the device.

sudo photorec

The above command will show you the list of the memory devices detected by your computer as shown in the figure below:

choose media

Then, we'll gonna select the partition which we have the data and we'll wanna select it. If we know the  format of data we need to recover, you select File Opt option in the menu. You can do that by pressing right button.

choose partition

You can select the format by pressing spacebar and then, press b to save the changes.

format selection

Then, previous menu will come, then select Search to search for the lost data.

recovery dir

Then, We'll gonna select the location where to save. Note: Please do not select directory of the memory device for the destination.

Select .. to go back, Enter to get into the directory and press C when you are done to choose that as destination.

destination recovery

After you select the directory, the program will start fetching the data you want to get recovered. After it is done, you'll be able to browse your files in the place where you have selected the destination to save.

recoverying process

Yes, now we are done. We have successfully recovered the required data from our memory stick using Photorec. You can visit the website of PhotoRec if you need more information regarding these or can comment below.

5 Comments... add one

  1. Dear Arun,

    I have followed the steps you described to recover my data from the pen drive although dmesg and fdisk -l gave me a lot of errors. Testdisk could not find the type of partition and the result of the data recovery was

    Disk /dev/sdc - 31 GB / 29 GiB (RO) - Kingston DataTraveler 3.0
    Partition Start End Size in sectors
    P Unknown 0 0 1 30008 39 32 61457664
    0 files saved in /home/ngizani/recup_dir directory.
    Recovery completed.

    Is it true that I have lost everything? Is there any other way of recovering the data, photos, etc??

    Thank you


Leave a Comment