Monday 2 July 2012

system crash recovery

I had mistakenly used the killer command dd on dev/sda.Which caused my grub to obliterate and the partition table as well completely disappeared ,hence i was unable to boot my system ,i had windows as well as ubuntu running on separate partition;fearing the worst i searched for ways to recover data on web.
I hence state here the complete method to recover data from your system in case you face the same problem.
To begin with you have to use a live CD or live USB ,the live indicates that the OS can be booted from them.This also ensures that you do not overwrite any data on your hard disk as you are using a bootable usb or cd.
Plugin the Live USB or insert the Live CD and restart your system ,you may have to press f12 or any equivalent key to provide booting priority.
We shall be using the Ubuntu OS .Once the OS boots up ,open a terminal and type:

$ sudo su 
 This makes you a super user.
then type:

$ sudo apt-get install testdisk

The testdisk checks for partitions on the harddisk and the detected partition can then be saved and once rebooted with the Live CD/USB the partitions are then visible and can be mounted which then can allow the user to access the data from the harddisk,itself.

upon downloading the testdisk ,start it by the command
$ testdisk

This starts the programme ,you can choose to create a new log file.
As the next step choose from the list your hard disk,observe the size of the media presented and determine your harddisk from its size.
After choosing your harddisk proceed ,you then have to select the partition table type,the software will choose the most probable partition table type,however you can be extra careful and determine the same from other sources.

Then select analyze which will start scanning your harddisk for any information on partition, After some time when it is done with scanning it provides a list of partition,you can recollect the partition of your system ,if it matches select write,which causes the partition to be saved.If however the provided partition does not match then select deeper search ,which forces the software to search for the partition information .

Once it is done reboot your system and then observe that your drives have been mounted and you can access the data!!

If the deleted data needs to be recovered then use photorec
download it by 
$ sudo apt-get install photorec
and use it by

$ photorec

You then have to provide the appropriate file type you are searching for and viola it finds all the deleted files of the indicated type for you in the chosen destination folder.

  Also there may be possibility of recovering the grub or bootloader it self,but for the provided steps please use extreme caution before using them.

If you have windows and linux partitions on the same machine,and if the bootloader or grub has been missing then you may recover by using the following steps .
use $ fdisk -l
To check the partition on your system,identify the dev/sdx which corresponds to the linux partition x may be 1,2,3, and so on.
Once you have identified ,you have to mount it onto the live cd/usb by using
$ sudo mount /dev/sdx /mnt

lets mount the boot as well

$ sudo mount /dev/sdx /mnt/boot

and then we can use bind to make a mirror image of the linux partition on the live cd/usb by using 
$ sudo mount --bind /dev /mnt/dev


now you can access all your data on the linux partition as the /mnt will replicate the root of your linux.


we will now switch root to /mnt
$ sudo chroot /mnt


we will install grub here by
$ sudo grub-install /dev/sda


Reboot the system and viola !! the purple screen greets us with our favorite OS's.