I recently had to reinstall MS Windows on my dual-boot box (Yes, I still require Billy Boy’s OS for a couple of applications for which I did not yet find a linux equivalent) which resulted in my MBR (Master Boot Record) being over by Windows. As such the Grub was gone and the box was booting directly into WinOS.
I googled for the solution and found quite a few different methods if restoring the Grub. Most of them was very complicated process. I found one which was the simplest. Here it the process…
This will restore grub if you already had grub installed but lost it to a windows install or some other occurence that erased/changed your MBR so that grub no longer appears at start up or it returns an error.
This how written for Ubuntu but should work for other linux distros also.
The only thing to take note of, when you see “sudo” is that the following command should be entered as root.
———-
Boot into the Ubuntu LiveCD. This can be the live installer cd or the older live session Ubuntu cds.
When you get to the desktop open a terminal and enter…
sudo grub
This will get you a “grub>” prompt (i.e. the grub shell). At grub> enter these commands…
find /boot/grub/stage1
This will return a location. If you have more than one, select the installation that you want to provide the grub files.
Next, THIS IS IMPORTANT, whatever was returned for the find command use it in the next line (you are still at grub> when you enter the next 3 commands)
root (hd?,?)
Again use the value from the find command i.e. if find returned (hd0,1) then you would enter root (hd0,1)
Next enter the command to install grub to the mbr
setup (hd0)
Finally exit the grub shell
quit
That is it. Grub will be installed to the MBR. When you reboot, you will have the grub menu at startup.
———-
Now the explanation.
Sudo grub gets you the grub shell. Find /boot/grub/stage1 has grub locate the file stage1. What this does is tell us where grub’s files are. Only a small part of grub is located on the MBR, the rest of grub is in your boot folder. Grub needs those files to run the setup. So you find the files and then you tell grub where to locate the files it will need for setup. So root (hd?,?) tells grub it’s files are on that partition. Finally setup (hd0) tells grub to setup on hd0. When you give grub the parameter hd0 with no following value for a partition, grub will use the MBR. hd0 is the grub label for the first drive’s MBR. Quit will exit you from the grub shell.