Friday 20 February 2009

Test disaster recovery (MBR curruption) of Redhat AS 4 on vmware workstation 5:

Test disaster recovery of Redhat AS 4 on vmware workstation 5:

Test Disaster Recovery Procedure:
1. Backing up MBR.
2. Currupting the MBR.
3. Booting off the Live CD.
4. Mouting root file system.
5. Restoring MBR from the backup in step 1.


Step 1: Backing up Master Boot Record (MBR)

What is MBR:
The MBR is a 512 byte segment on the very first sector of your hard drive composed of three parts: 1) the boot code which is 446 bytes long, 2) the partiton table which is 64 btyes long, and 3) the boot code signature which is 2 bytes long.

Using dd command we will be backing up the MBR which consists of 512 bytes.

What is DD:
Disk Definition (dd) came from IBM's Job Control Language and became a staple of the low-level UNIX and Linux commands. What dd does is copy bytes from an input source (if) to an output source (of). But dd can also copy raw data as well, which makes it perfect for copying boot sectors. The dd command can handle many tasks including: disk cloning (Note: Target disk must be of equal size or greater than the original disk)disk imaging,partition cloning, restoring from image file.

[root]# dd if=/dev/sda of=/backup_of_mbr bs=512 count=1
1+0 records in
1+0 records out
[root]#


For IDE devices: Its hda, for SCSI devices: its sda, check your scenario.

I have backedup MBR on the root. It's advisable to backup MBR to an external disk such as USB, CD or a differnt drive.


Step 2 : Currupting the MBR.

We will kill the MBR but leave the partition table intact by simply currupting the boot-code of 446 bytes of the total 512 bytes.

[root]# dd if=/dev/zero of=/dev/sda bs=446 count=1
1+0 records in
1+0 records out
[root]#

For IDE devices: Its hda, for SCSI devices: its sda, check your scenario.


Error on the reboot:

The master boot record (MBR) of this virtual machine's hard disk does not contain valid bootstrap code. It is likely that the MBR was corrupted by an incorrect guest operating system installation or some other reason. The virtual machine cannot continue and will now power off.

Step 3 : Booting off the Live CD or from an ISO image of the CD.

If you have a Live CD then simply insert the CD into the Drive and start the vmware machine. Note: make sure vmware has the control of the CD-ROM drive at this momment.

Or,

In case you have ISO image, then click on "VM" on the top menu bar of the vmware panel and select -"settings" | Click on CD-ROM under device | select "use ISO Image" | Browse to the ISO image of the Live CD.

Start the vmware machine.


Step 4: Mouting root file system.

a.You will be presented with redhat linux install options - In the command line Type : linux rescue [Enter]
b. Next sceen will ask you to "choose a language" , select "English" [Enter].
c. Select a keyboard type - choose "US" [Enter]
d. Do you want to start network interface on this system - Its up to you, i said NO b'cos i don't need a network, scope of this test is to Fix the currupted MBR.
e. You will now be presented with "Rescue" screen with following message :

The rescue environment will now attempt to find your linux installation and mount it under the directory /mnt/sysimage. You can then make any changes required to your system. If you want to proceed with this step choose 'continue'. You can also choose to mount your file system 'read-only' instead of read-write by choosing 'read-only'.

From the three options : Continue | Read-Only | Skip , Choose 'Continue', b'cos we want to mount the file system in read-write mode.


In the next screen "Rescue" , following message is displayed : Your system has been mounted under /mnt/sysimage . Press to get a shel. If you would like to make your system the root environment, run the command:

chroot /mnt/sysimage

Press [Enter]



Following message is displayed in the next screen :
Your system in mounted under the /mnt/sysimage directory. when finished please exit from the shel and your system will reboot.

-/bin/sh-3.00# [This is the shel you wil get, enter the following command]
-/bin/sh-3.00# chroot /mnt/sysimage


sh-3.00# [Now you are back in business, just type 'ls' to get the list of items and to see the backup file you created in step1].

sh-3.00# ls [Enter]
backup_of_mbr boot halt lib misc proc selinux tmp
backup dev home lost+found mnt root usr
bin etc initrd media opt sbin sys


You can see the backup file 'backup_of_mbr' up there...

Note: I hope you remember i saved the backup file 'backup_of_mbr' on the root itself that is - "/".

Step 5: Restoring MBR from the backup done in step1.

At the following shel type :

sh-3.00# if=backup_of_mbr of=/dev/sda bs=446 count=1
1+0 records in
1+0 records out
sh-3.00#



Finally, remove the "live cd" or "ISO image" and type "exit" at the shel command, and once again type 'exit' as shown below:

sh-3.00# exit [Enter]
-/bin/sh-3.00# exit [Enter]
logout..
rebooting the system....



That's it - You are back in business, your linux will boot off normally as if nothing happend. This was a very small excercise to demonstrate how to overcome currupt MBR issues as long as you have a proper backup of the same. Iam a beginner in linux hence there may be mistakes which i don't know untill someone points to me but i hope i will learn as i grow further.