Fix Broken Bootloader (GRUB)

I have a triple boot setup (Xubuntu, LMDE, and crunchbang) on my primary work laptop and have ran into several occasions when an update (always LMDE) breaks GRUB. This article explains how to fix a broken GRUB on a system with several operating systems, all using separate partitions for root (/), boot, home, etc.
There are several ways to fix a broken grub, I opt for the simple/effective approach of booting into one of the existing Operating Systems and using grub-install (note: this does require an existing/working OS). This approach requires a bootloader disk/application such as SGD or SystemRescueCD. The steps are as follows (I'll use SGD for the example):

Terms / Notices

  • OS - Operating System: such as Ubuntu, Debian, or Windows XP
  • BM - Boot Master: this is the Operating System which is set as the boot master, meaning it is set to boot, for example, if I have Xubuntu, LMDE, and crunchbang and LMDE's grub is set to boot this means LMDE is the BM

Boot Up via SGD

  • Insert SGD CD and boot (make sure boot from cd is enabled or enable it in your bios)
  • As SGD starts, I select the "Automagic Boot" option
    Note: the automagic boot attempts to find any/all OS on your computer and builds a temporary GRUB menu. This allows you to select one of your existing OSes to boot
  • Next, you need to determine which OS you want to be your BM, and boot that OS. In my case, LMDE was my BM; however, I want to change the BM to be crunchbang as I've had numerous issues with LMDE breaking grub, so I select crunchbang from the GRUB menu
    Note: often, the OS is not apparent from the GRUB menu as it simply says Linux Kernel 2.38..., Linux Kernel 2.36... If this is the case you can try each entry one by one until you find the correct OS

Re-Install GRUB
You should now be back into your OS (the OS you intend to use as your BM) so all you need to do is re-install GRUB. The following steps provide the details for doing so.

  • Open a terminal and issue the following command:
    $ grub-install /dev/sda (replacing /dev/sda with your appropriate hard drive/device path)
  • Next update grub to ensure all images/kernels are found and added to your grub menu with the following command:
    $ update-grub

The final step is to ensure your correct partition is set to boot. We use fdisk to toggle (on/off) the boot flag for a partition but before starting fdisk, issue the following command to determine your boot partition and note the device path (e.g. /dev/sda8):

  • Issue the following command to determine your boot partition:
    $ df -hT | grep /boot
  • If you receive no results then issue the following and note the device path for the '/' root (e.g. /dev/sda1):
    $ df -hT

Now we are ready to start fdisk to determine/set your boot partition:

  • Start fdisk passing it the same device from above (where you installed grub) with the following command:
    $ fdisk /dev/sda (use the same device as used in the grub-install from above)
  • Next, press 'p' and hit enter to print your current partition table
  • If there is only one '*' and it is next to the device path of your boot partition then you are all set and can exit grub (q)

If there is more than one '*' or it is not in the boot column for your /boot partition then...

  • First toggle (off) the current boot partition by pressing 'a' and then entering the device path to toggle
  • Next, toggle (on) the boot flag for the partition you want to boot by pressing 'a' and then entering the device path to toggle
  • You should now have your boot partition set to boot, press 'w' to write the partition table changes and exit fdisk

You should be complete, take the SGD disk out of your CDRom drive, set your bios back to not boot from the CDRom and boot up! If for some reason you got the wrong partitions simply boot from SGD again and try again!
Hope this article is of use to others, if you have questions feel free to add comments!