Saturday, December 10, 2011

Linux recover boot loader or filesystem corruption using Rescue Mode

Here are the steps to recover corrupted linux filesystem (with or without LVM) or boot loader:

1) Boot system using Linux OS (should be the same version which is installed or needs to recover) CD/USB

2) When prompted, type ''linux rescue''

3) This will ask You for some questions like need to enable network or not and mount system or not

In case of installation/repair or grub boot loader

4) Try to mount file system and use following command to install grub
grub-install /dev/sda (should be a first partition where MBR resides)
run exit to reboot into new installed and recovered grub boot loader

In case of filesystem repair (skip step 4)

5) Do not mount partition

6) run following command over shell
e2fsck -p /dev/sda{1,2,3....} Partition which required to recover
fsck -p /dev/sda{1,2,3} Partition which required to recover

If all goes well reboot your system :)

In case of LVM filesystem repair (skip step 4 & 6)

7) In case of rescue mode, LVMs are not in active state we require to activate them manually

8) To check and activate LVMs run following commands:

lvm pvscan (Scan for PVs available and show them)
lvm vgscan (Scan for VGs available and show them)
lvm vgchange VGName -a y (This will activate all VGs LVM volumes)
lvm lvscan (Scan LVMs available)

9) Now use Step 6 (change partition with LVMs partition number which is shown by ''lvm lvscan'')

Thats it!!! Plz correct if wrong somewhere :)