How to recover files from a deleted or even overwritten partition

This part is some junk story, so you may skip

First of all, this is something that happened to me and, it is just a post about how I recovered myself from the mess. You are gonna slap me if I tell you how idiotic I was to loose all my data anyway. I was updating my Linux Mint 14 laptop with Linux Mint 15 RC, which has been released yesterday by a fresh reinstall. As usual I backed up all my files in the /home/napster folder, which is nothing but my home folder, to another spare PC here and since all of my critical documents are on Dropbox and Google Drive, that part was pretty safe. Before starting gone-deadly installation, my TOSHIBA-250GB HDD looked something like the following.

image

The partition labelled Data was the central place where I kept all my stuff like movies, music, photos and e-books and everything as such. And this drive was 200GB in size, and it was around 99% occupied. As you see this is a pretty deadly combination that, if you accidentally lose the data, there is not much space left to stand up and do the recovery from within the disc. Anyway, this is what I did in the apocalyptic re-installation. First I booted the machine with a Linux Mint 15 RC CD-ROM and while the installation process, I have chosen Replace Linux Mint 14 with Linux Mint 15. This was somewhat a very bad thing to do, although I didn’t expect all my partitions will be lost. After the installation, I have immediately noticed that all my partitions and data are lost, forever. This is somewhat the HDD looked like after the re-installation.

image

I was stupid enough to use the new installation for a few more minutes and install a few applications like Chrome Browser or the VLC player. Then I realized that the situation is real worse. With each apps being used, and with each app being newly installed, I’m technically overwriting one file or the other in my old partitions. I have stopped immediately, turned off the PC and looked around for solutions. I was pretty panicked and didn’t know what to do. I have headed to some IRC chat rooms and most of them were pretty sure that, I’m never going to get those data back.

I paused for a while and the next thing to do was to audit the damages. I have thoroughly tried to recall what files did I have on the machine before loosing the partitions. I have listed all those I could recall and analyzed which of them are potentially high priority files and which of them I could afford to loose. That opened little bit of a room to settle down for a while. Because most of the files where not that critical and to be honest, almost with any of them, I could live in the absence of them. So by the evening I decided not to approach any professional companies to do this recovery process, and assigned myself to give it a try.

Boring Story is over, You may read from here on.

For the sake of safety, I have gathered a 500GB external HDD. I thought I could use it in case if I need to profile the entire hard disk to an image. The most important tool to use was testdisk. This is an elegantly written open source software, which is the only tool I used in the entire process of the recovery. I have found a lot of threads discussing data loss due to the same incorrect Linux installation attempts. But none of them lead me to a proper recovery solution. Most threads where flooded by commercial data recovery companies and their sucky ads. So, I have found testdisk on the Ubuntu’s data recovery guide. But it was not at all documented there. I have setup a virtual machine quickly to get myself familiar with the interface of the testdisk tool. It is infact a 100% command line tool, with menu like interface much similar to what is provided by parted or such tools. I don’t know why I choose testdisk since the other two tools (one was gparted - I knew it was of no use) were documented there properly. Anyway I headed to the testdisk wiki and learned how to do the Deep Search process for the lost partitions and how to write the partition table back to the disk itself. The following were the major steps in the process.

  1. Boot the machine from a Live CD. I used Linux Mint 15 RC CD-ROM itself, since it was already available, as you would guess. Please note that the entire system is in the RAM when booting live, so the recovery process depends on the available RAM you do have. If possible, extend the RAM before initiating the recovery, or move the HDD to another PC with faster/larger RAM, although I’m not sure the later one is a good idea.
  2. Install the testdisk application. Please note that the installation goes to the RAM as well. So its better not to run any other apps from this Live CD for the sake of speed. Now, run the tool

    sudo testdisk

  3. Select the correct HDD first. If you have multiple hard disks on your PC, you can identify the correct one with the name or the size of the HDD.
  4. Select the Quick Search and proceed, and this will list you the new partitions, I mean the current available ones. In my case, the one with Linux Mint 15 RC and its 2GB swap.
  5. Select the root partition from the result and proceed to the Deep Search. This process is going to take a while, in my case it was around 1.5 hours.
  6. After the Deep Search, you will be getting a list of all deleted partitions that could possibly be recovered to some level whatsoever. It is not at all guaranteed to recover any files with any level of certainty, I mean, it depends on your luck as well. Anyway, from this list of partitions, correctly select the one you need to recover. Strangely, in my case I got two partitions with the same label Data. I’m not sure why 2 of such entries appeared.
  7. I selected one of them and pressed Enter to proceed. Now, the partition is displayed with all details about the drive. I could navigate through the file system by using the  and  arrow keys. You may find very old and previously deleted files on the drive in red color, which could not be recovered. Once the drive is properly identified, proceed to the next step.
  8. Change the partition type from D to P or L. D represents deleted, P represents Primary and L represents Logical partitions. If it was a primary drive, you may not be able to change the type to L at all. Once this step is done, press enter to proceed.
  9. Now, testdisk will ask you if you want to write back the partition table or not. Choose Write and confirm if asked again.
  10. Reboot the PC to complete the process.
  11. Once rebooted, the partitions will be restored and the files in it may found to have incorrect permissions or even some files or folders cannot be accessed at all. Check chmod command to see how you could fix this problem.


Ok, so that’s the story, I have executed all the steps above, and successfully recovered almost all the files without being corrupted. I faced some boot related issues after the recovery, but I’m not sure yet if it is caused by the recovery process or not. Also, the most important files were recovered and so, a bad day became a good day afterall for me! :)

23.05.13

Tide goes in, Tide goes out - You can’t explain that!

Reading Time : Less than 5 Minutes

A popular video floating around on the internet back in 2011 was a talk show between David Silverman (the president of the American Atheists) and Bill O’Reilly. The video, in fact made a number of O’Reilly posters and a very popular Internet meme. I’m not really able to figure out what the talk was all about, but it is pretty interesting. You can checkout the video below.

Silverman was shocked when O’Reilly thrown the tides statement into the argument. It was no different from “Bread Goes in, Toast comes out - You can’t explain that!”. It was a trivial statement with no use whatsoever. But apparently, Silverman’s expression upon the incident was pretty awesome. He got shocked and which turned out to a very popular meme. Now you know where did it come from. :)

image

And if you have a few moments, checkout the O’Reilly posters here.

6.03.13

Some Handy Functions for Android Developers!

Reading Time : Less than 10 Minutes

In this post, I thought I would share a few utility functions for Android Developers. These are indeed used by me in different projects. My plan is to keep updating this post as new utility functions are found across. Please note that, not all the code is mine, but I borrowed from different people around the globe. So credits goes to them as well. So far the list of functions includes the following.

  • Check if the phone is connected to the Internet
  • Get EXIF rotation information of an Image
  • Get a view object from a layout id
  • Convert pixels to dp (dip)
  • Create a file object with correct media type, and handle name conflicts.
  • Get the width of the screen in pixels
  • Get a scaled bitmap from another

NB : The description about the function is followed by code snippets for each.

Connectivity
Lets begin with the connectivity check function. The function uses the Connectivity Manager class to check whether the phone is connected or not. Please do keep in mind that it does not really checks out about Internet connectivity, but it just checks if the phone connected to a WiFi or your mobile data network. For finding if the Internet connection is working or not, you really have to make a network request from the phone.

https://gist.github.com/5079918

EXIF
You can read more about EXIF information of images from the wiki. In some situations it is handy to check out that an image is rotated either clockwise or anti-clockwise. I don’t exactly remember the degrees of rotation, but you definitely can read about it from the Internet. The following function returns the actual rotation degrees of an image being passed. You can apply different methods to rotate an incorrectly oriented image back to the original position.

https://gist.github.com/5079961

View Inflation
The next function is very simple, but it saves a lot of time fiddling around views inflation when dealing with adapter views such as lists or grids. It is not a function as such, but a time saver in fact.

https://gist.github.com/5079977

Pixels to DPs
Yet another handy function which is particularly useful for people who deals with UI for pixel perfection. The name explains it all. You can read more about graphic units in Android here.

https://gist.github.com/5080001

Media Files
Creating files is very useful when you are dealing with Camera on the device. Most camera intents accepts a file object which will be used to write the taken picture or video to. The following function returns a file object with proper names and file type.

https://gist.github.com/5080012

Screen Width
The following function is useful for UI designers as well. This function returns the width of the screen in pixels. You can modify it to find the height as well.

https://gist.github.com/5080018

Bitmap Scaling
Another very useful function is the one for scaling bitmaps. We usually get big sized bitmaps, and we need to scale them down to match the memory of the device. There wont be a single developer who never had an OOM error due to high sized bitmaps. So here we go.

https://gist.github.com/5080039

Hope that all the functions works fine on different API levels. Always check the date of this blog-post before copy pasting the code. There might be a more efficient version of each of these functions.

//See you in the afterlife…
//Subin Sebastian

3.03.13




Hi There, This is my personal blog. You might see some really personal stuff and more or less technical articles here. I used to fuse all my things together at one place. So, don't take it too seriously. I could not really manage more than one blog or profile at a time. You might think its a little odd to do it in that way. All of the posts here are made on the intention that it would be helpful for you at some point. I have tried to keep it as simple as possible without losing the quality. Thanks for reading.

View Archive

Ask me anything

Submit