How To Fix Bootloader Problems Due To GRUB
Dual boot means you have two operating systems (most likely Windows and a Linux distro) on your computer. You get some kind of menu to choose which operating system to boot when you start your computer and depending upon your choice, the appropriate system boots up. More often than not, if you are dual-booting with Windows and Linux, chances are that the menu you see at boot time is the GRUB boot menu.
By default, GRUB is installed by many distributions and is available as an option with others. It automatically detects the other operating systems present on your computer and adds them as an entry in the menu along with the Linux distribution you are currently installing. All this happens without any additional steps during the Linux installation process if you install Linux after Windows is already present on the disk.
If you go the other route, that is — install Windows after Linux, or if you play with partitions on your hard drive too much; you can end up messing up GRUB. In that case, depending upon what you just did, you might only be able to boot into Windows or GRUB might fail to display any menu at all. In either case, before you panic and rush to forums or tech support, there is a simple fix that will most likely alleviate your woes. Its to restore GRUB, and you can do it in a snap. Let’s see how.
First off, as is often the case when a new version to a popular software is released, both versions continue to be in use for some time before the newly version is adopted. The same with GRUB. Sadly, the procedure is a little different for both versions and we shall tackle both of them here.
First off, you need a Live CD handy. Your Linux distro CD should work just fine if it installed GRUB on your computer in the first place. You can also use Knoppix or SystemRescueCD. We will be using Ubuntu Live CD. Keep in mind that the CD uses same version of GRUB. This can be insured by using the disc that you used to install Linux.
Boot off from the Live CD and give it some time before you can view the desktop. Next up – fire up terminal and get ready for some command line action. Before we proceed keep in mind that hd0 refers to the first hard disk on your computer, second will be hd1 and so on. Similarly (hd0,2) means second partition on the first hard disk.
- Type sudo grub, this will give you a the GRUB prompt. Now you can enter GRUB specific commands.
- Type find /boot/grub/stage1. This should return the location of GRUB files on your hard disk.
- Next up, use the location returned above and issue the command root(hdX, Y). For example, if the previous command returned (hd0, 1), you should issue root(hd0, 1)
- Next issue the command setup(hd0) or hdX as the case may be. PLEASE NOTE: This will overwrite the MBR, which is fine if you were using GRUB in the first place or you install Windows after Linux. If you had some other bootloader or custom configuration, you should watch out.
- Type quit to exit GRUB and then reboot the computer.
- Enter sudo mount /dev/XdYZ/ /mnt where X can be either ‘h’ or ‘s’ and Y represents the hard disk number and Z represents the partition. eg mount /dev/sda3 /mnt, in which case /dev/sda3 is your Linux system partition. You can use sudo fdisk -l, to list all partitions if you are not sure about the system partition. NOTE: If you have a separate boot partition, you will need to mount it explicitly at /mnt/boot
- Then issue the command sudo grub-install –root-directory=/mnt /dev/sdX X being the hard disk where you want to restore GRUB.
- Next, unmount the partition via sudo umount /mnt and then reboot your computer.
After running these steps, you should be able to restore GRUB within 5 minutes. If things go well and if GRUB was the reason for your troubles, you just fixed them. If these didn’t fix your problem, you might want to have a closer look at your hard disk’s health and partitions. You can use GParted or the Ubuntu Live CD or any other Live USB/CD that suits you.
Have you ever run into booting troubles? How did you fix it? Shoot off any tips in the comments, that might be helpful to fellow readers!