Using Testdisk to recover lost files from deleted partitions

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:

  1. First go through the following links in detail: and step by step wiki
  2. DO NOT USE the HDD once you realize the partitions were removed or corrupted.
  3. Have another external storage device like HDD or USB stick which can store the data you want to recover.
  4. Have a Live Ubuntu USB Image. [You will need to boot using this and not use the HDD of your computer. ]
  5. Have an internet connection. [Or else you need to have an executable of testdisk with you]
  6. Boot into the live ubuntu and open software and updates, and make sure the “Universe” repository is checked. [3]
  7. Run the following commands “sudo apt-get update” and “sudo apt-get install testdisk”
  8. Once testdisk is installed you need to run it as administrator “sudo testdisk”
  9. Follow the steps in
  10. Quick search might not yeild best results especially if your Ubuntu was installed over your windows partitions.
  11. Try Deeper Search [Be warned this will take a lot of time depending on your HDD size, mine took around 1.5 Hrs]
  12. Once finished it should probably list your original partitions usually with first column of results as HDFS – NTFS.
  13. 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.



Drush for Drupal: Command Line for Drupal

I am not new to Content Management Systems and have been developing websites for quite some long time now. I have used CMSs like Joomla, Drupal and WordPress (yeah its not just for blogging). Add to that a few others like Silverstripe etc. Well I enjoy developing websites using CMS as it eases a lot of your work. No more trouble about entering data directly into database or writing HTML code. Easy to install plug-ins, themes and what not. But this case which I am going to mention is really interesting and fascinating. So please read on =)

I tried using Drupal two years back when I was just looking at the various CMSs available. I like the flexibility it had over any other CMS but then the interface was really difficult to navigate (or so my lazy mind felt).  There were not many good free themes  available and also the modules were also less as compared to Joomla and WordPress. Since then I have been building websites majorly on Joomla with WordPress as well for small or quick projects. But then I kept reading Drupal is really cool and you can add a whole new level of functionally to it once you get a good hand at it. Those comments bothered me. At times I wanted to do some stuff in Joomla and then realized that its just too inefficient or rather lengthy process to do those.

A few weeks back I started on a new website. I thought of giving it a shot in Drupal this time. So installed it and started working. One feature which didn’t work for me was the Plugin Manager. Its actually a pretty good plugin which gives you a great control over installing, updating both modules and themes for Drupal. So I was looking for a really rapid development using this. But alas no computer is perfect and no hosting is perfect as well. I am using Godaddy Grid Hosting and after a lot of search I found out that they do not support ftp_connect() php function which spoiled the party for me. (Please if anyone knows how to run Plugin Manager on Godaddy Grid hosting please share it with me). So I was back to looking for something which will help me with rapid Drupal Website Development. After a few searches I stumbled across this Drupal project called Drush. Drush basically stands for “Drupal Shell” and its a command line utility to install modules, themes, updating and do much more. All in all its gives you the control of your drupal installation  through a command line interface. (Which developer won’t love it =D). I downloaded it but really had a hard time trying to figure out how to make it work.

Well as they say “Google when in trouble” so I did just that. I was getting the error

Content-type: text/html

drush.php is designed to run via the command line.

They had a few tutorials on fixing it. The best amongst them which worked 90 percent for me was this one by Joshua Riddle again as I figured out it was basically a Godaddy problem which was not allowing Drush to run properly. Basically Drush requires itself to be run by php-cli which by default is not accessible in command line by the hosting. So in order to make it work I was required to add an alias to the drush command I intended to use with the exact path of the php executable. The line which was required was:

alias  drush=’/usr/local/php5/bin/php ~/html/drush/drush.php’

So this used to solve the problem whenever I entered the above in the shell. But there is a need for automation so that things get taken care of for always. So I added this line to .bashrc file of my directory. But it didn’t work out somehow (Again it would be great if someone can explain that as well). So I “Googled” and lo I got the answer again. The solution was presented on this Wiki How article “Install Drupal with Drush 2”. The point which solved the matter for me was

echo “alias drush=’/usr/local/php5/bin/php ~/drush/drush.php'” >> ~/.bash_profile
source .bash_profile

This done now I can log into my hosting and control installing any module, theme directly from the command line. And first of all its fast and secondly its really easy. Say for example you want to install the Dynamic Display Block Module module in your drupal site so all you are required to do is change your current working directory to your drupal install folder. After that fire this simple command in your command line

drush dl ddblock
drush en ddblock

Done and your module is downloaded and enabled. As simple as that. Not only this you can download and install modules in bulk all you need to write a command similar to this:

drush dl cck zen es

Which will Download latest versions of CCK, Zen and Spanish translations for your Drupal version. For a detailed lists of commands you can always type

drush help or simply drush

Details about the Drush module can be found on Overall its a must use for anyone who wants to develop Drupal websites very quickly. Its insanely powerful and increases your working pace 10 folds.

There are some small quirks related to installing it but once done its like a cake walk for any Drupal Developer. I am new to it but have already started to see the positive implications of this project. Thanks to the Drush team for giving us such a great tool.

Feel free to post your issues related to the module or anything related to the hosting problems. Also if anyone can figure out how the .bashrc and the Plugin Manager issue can be solved I would be very thankful.