Browsed by
Month: June 2016

Recovering the partition table of a corrupted USB stick using TestDisk

Recovering the partition table of a corrupted USB stick using TestDisk

Recovering the partition table of a corrupted USB

Yesterday I came across an extremely useful utility called TestDisk. I managed to rescue my Dads micro-SD card when all hope looked lost. Somehow the micro-SD card partition table became corrupted after his phone got wet. I have never heard corruption-by-water before but I guess that’s a thing!

First signs of partition table corruption

The first problem we noticed after drying the phone out was that most of the apps on his android device were missing. After removing the memory card and re-inserting it again a message popped up saying that he needed to format the card before it could be used. Obviously this doesn’t sound good and first my thought jumped straight to water damage. However despite this I powered on to see if I could avoid formatting the device. After attaching it to my desktop a similar message appeared: You need to format the disk in drive G: before you can use it. 

windows partition table formatIn disk management I could see the device as a RAW filesystem so the first thing I did was open up DISKPART and see if that could manipulate the partition. With DISKPART I encountered a weird a problem in that there was only one partition (Partition 1) and it was marked as active (Denoted by a *) however all commands were failing with an error stating that a partition must be selected. This also meant that CHKDSK would not work either. Still refusing to give up I moved onto the tried-and-trusted GParted ISO VM, but this only gave me the option of creating a new partition table which in turn would require formatting the device.

TestDisk – My saviour

It was at this point I happened to stumble across a utility called TestDisk while trying to Google a solution for my corruption issue. Their website states that TestDisk is a free and open source data recovery software tool designed to recover lost partition and unerase deleted files. Recovering a lost partition sounded like exactly what I needed so I figured I would give it a go.. and it worked! TestDisk managed to rescue the partition table and restore partition 1 as the active partition. We plugged the memory card back into my Dad’s phone and voila all his apps were back to normal.

How to use TestDisk to recover a partition table

While I’m here I figure I may as well show you how to use TestDisk and the procedure I followed. The first prompt you receive after launching the TestDisk executable is whether or not you wish to create a log file of the completed actions. If you choose to create the text file, testdisk.log , it will contain TestDisk options, technical information and various
outputs; including any folder/file names TestDisk was used to find and list onscreen. I went with ‘No Log’:

TestDisk log partition table

Now we are good to go with finding the partition..

  1. First step is to choose your media device. Mine was listed as ‘Disk /dev/sdd’ at the time.  You can choose your appropriate device via your arrow keys on your keyboard.
  2. Next you choose your partition table type from the list. For this step I went with ‘EFI GPT’
  3. Lastly you choose the ‘Analyse’ option. At this point I was given a message stating that there were no partitions found, but after another scan it found the primary partition.
  4. Use to arrow keys to navigate to the partition and press the return key (Enter)
  5. Now you will be given the option to ‘Write’ the partition table

This managed to successfully recover the partition table without formatting the sdCard and therefore retaining all of the data. I am so happy I stumbled across TestDisk and I know I’m going to end up needing it again in the future.