Last Friday I promised a good friend that I will provide him with a LiveCD that contains a bunch of anti-virus software that will be able to scan his heavily infected windows machine. It continues to annoy me how Microsoft can continue to get away with utter and complete incompetency in shipping totally flawed operating system software. I downloaded PLoP live CD and went about setting up a bootable USB drive. Unfortunately, in that process, I accidentally messed up the master boot record of my functioning Fedora 11 machine. So, this post is really to remind me what to do to recover from these mistakes in the future.
a) Boot from a live CD – F11 would suffice
b) If the drive that needs rescuing is the internal drive (usually /dev/sda) and if the boot partition is /dev/sda1 (usually), then do the following:
i) Open up a Terminal
ii) Become root with the command (F11 root has not password):
$ su –
iii) run the grup command:
iv) within the grub prompt do the following:
grub> root (hd0,0)
grup> setup (hd0)
Note that the line “root (hd0,0)” refers to the 1st drive on your system and the first partition. GRUB starting from 0. So hd0 is the first drive and 0 is the first partition.
Now, if you don’t know which one is the boot partition of your drive, then you will have to run fdisk /dev/sda. For example,
[root@qbic ~]# fdisk /dev/sda The number of cylinders for this disk is set to 4998. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sda: 41.1 GB, 41110142976 bytes 255 heads, 63 sectors/track, 4998 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x6f1824f1 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 208813+ 83 Linux /dev/sda2 27 1501 11847937+ 83 Linux /dev/sda3 1757 4998 26041365 8e Linux LVM /dev/sda4 1502 1756 2048287+ 5 Extended /dev/sda5 1502 1756 2048256 82 Linux swap / Solaris Partition table entries are not in disk order Command (m for help):
The output above is generated after invoking fdisk /dev/sda and hitting the p key. Naturally, you need to be root to do this. So, if the boot partition was say /dev/sda2, then the grub command above would have been root (hd0,1).