Using Testdisk to recover lost files from deleted partitions
June 4, 2015
Posted by on
I installed ubuntu on my home desktop recently. While doing so I choose the “Replace Windows …” option which like title suggests, should have just replaced the windows partition with a ubuntu partition and should have kept everything intact (or so I thought). However, in reality the option is misleading and is actually used to format the whole drive and use all of it for linux. It is like doing a fresh single boot install of ubuntu on your machine. I would highly advise against using this option even though it is the second suggested option (issue with user experience).
In my 500 GB HDD I had 4 partitions:
- C:\ – Windows, ~50 GB
- D:\ – Personal files, ~200 GB
- E:\ – Personal files, ~195 GB
- F:\ – Backup files ~ Rest
I wanted to just replace Windows and instead have Ubuntu on my C:\ drive. Also, I wanted to keep all my data in the other partitions. However, using the “Replace Windows…” option was disastarous and I ended up with one large linux partition of size ~490GB. I spent the rest of the day, trying to recover parts of my original data.
This is when I found out about testdisk, a utility for recovering files and lost partitions from a device. The utility is suggested in many threads related to solving the exact same problem I was having [1,2,3]. After digging through the step by step wiki as well as going through many other links [4,5,6] I recovered many important files from my partitions. This video guide was also very helpful.
Some important things to note while doing the recovery are:
- First go through the following links in detail: http://selfsolve.net/software/testdisk.html and step by step wiki
- DO NOT USE the HDD once you realize the partitions were removed or corrupted.
- Have another external storage device like HDD or USB stick which can store the data you want to recover.
- Have a Live Ubuntu USB Image. [You will need to boot using this and not use the HDD of your computer. ]
- Have an internet connection. [Or else you need to have an executable of testdisk with you]
- Boot into the live ubuntu and open software and updates, and make sure the “Universe” repository is checked. 
- Run the following commands “sudo apt-get update” and “sudo apt-get install testdisk”
- Once testdisk is installed you need to run it as administrator “sudo testdisk”
- Follow the steps in
- Quick search might not yeild best results especially if your Ubuntu was installed over your windows partitions.
- Try Deeper Search [Be warned this will take a lot of time depending on your HDD size, mine took around 1.5 Hrs]
- Once finished it should probably list your original partitions usually with first column of results as HDFS – NTFS.
- You can go inside each partition and look at the files using option “P”. You can also mark paritions for deletion or as Logical Drive using the Left/Right arrow keys.
I used the list files option and copied all important files from my partitions to my external HDD. This will take some time depending on the data you need. I recovered ~5000 photos and few 100 documents and ~5000 other files. The process was easy and the external HDD had the correct files stored.
My attempt to recover full partitions, failed with Invalid partition sectors error. However, I was happy with the capabilities of the tool and its user friendly approach. I believe, it would have been possible to recover my partitions as well but I made some mistake on my side.
Overall, testdisk is a great utility and is recommended for recoveing files which you accidently deleted or lost during partition deletion. It is recommended by the Ubuntu data recovery page as well.