Recovering from Broken Grub
On Friday, i was trying to down-grade Grub to grub-legacy. So installed grub-legacy, i knew i was playing with bootloader. When i restart my OS, as expected grub was not able to find out the OS. Problem became more worsen when i came to know, i didn’t installed stage1, stage1.5 and stage2 scripts means i didn’t ran commands(grub-mkconfig).
Dos grub didn’t had grub-install,
So i googled didn’t found any solution. I read from different blog, websites and tried this.
- Use any live os and run grub-install
First Mount the partition where OS is installed. You can find the partition by running. #$ blkid /dev/sda1: UUID="ee51f4e9-1ef8-4b65-8ef4-299600e8cbf4" TYPE="ext4" PTTYPE="dos" PARTUUID="c679c6ed-01" /dev/sda2: UUID="cb97ec88-4282-459a-852f-f619138d46d9" TYPE="ext4" PARTUUID="c679c6ed-02" then run sudo mount /dev/sda1 /mnt (Make sure partition in write mode) mount -o remount, rw /dev/sda2 (Here sdb3 where OS is installed) grub-install --target=/mnt --recheck /dev/sda2
Now Scripts are installed reboot the machine.(Most probably you will get a grub black screen)
Now you have to do 3 things
a. Find the partitions.
ls
it will show you how many partitions are here, here you may get like
(hd0) (hd0,5) (hd0,1) (hd1) (hd1,1) (hd1,2) (fd0) (hd0,msdos1) (hd0, msdos2)
Then run
ls /(hd0,0)
and observe the output, if you are getting Linux root(where folders like etc, boot are present) then this is your root.
b. Set the root
root (hd0,0)
Here (hd0,0) Explained Here.
- The brackets are a must; all devices listed in GRUB menu must be enclosed in brackets.
- hd stands for hard disk; alternatively, fd stands for floppy disk, cd stands for CD-ROM etc.
- The first number (integer for geeks) refers to the physical hard drive number; in this case, the first drive, as they are counted from zero up. For example, hd2 refers to the third physical hard drive.
- The second number refers to the partition number of the selected hard drive; again, partitions are counted from zero up. In this case, 1 stands for the second partition.
From here, it is evident that GRUB (menu) does not discriminate between IDE or SCSI drives or primary or logical partitions. The task of deciding which hard drive or partition may boot is left to BIOS and Stage 1. As you see, the notation is very simple.
Primary partitions are marked from 0 to 3 (hd?,0), (hd?,1), (hd?,2), (hd?,3). Logical partitions in the extended partition are counted from 4 up, regardless of the actual number of primary partitions on the hard disk, e.g. (hd1,7).
For me I guessed, i tried like setting up the root, like above mentioned then. used grub’s ls command if ls /boot+tab shows any thing that partition where you have to install actually re-install your Grub.
c. Load the kernel
kernel /boot/vmlinux-linux ro root=/dev/sda2
d. Load the Linux img
initrd /boot/vmlinux-linux-lts.img
Then Run
boot
You will be able to boot the desired OS. [1]