Recovering a broken GRUB2 setup

Along with all the strange changes grub2 introduced (like not having an editable menu.lst file any more), it also provides a grub2-install command which works without having to do 25 other things manually (to be honest, I was never quite able to run grub-install from grub 1 successfully). Here’s how you recover your broken bootloader using a live disk:

1. Boot the live disk

It doesn’t matter which one, and it does not need some fancy UI or whatever. An initrd shell is enough, you only need two commands: chroot and mount. If you have a graphical user interface, open up a shell and become root; many live disks use something like “root” for the root password, and many others don’t ask you for a password when using sudo, so you can try either “su” or “sudo bash” to get a root shell.

2. Change the root directory

Now you need to switch over to your installed linux system (the one you can’t boot because your grub is broken, remember?). To do that, you first need to find and mount that system’s root partition. For me, this went something like

mkdir newroot
mount /dev/hda1 newroot

If you don’t know which number your root partition has, you can try something like “fdisk -l” to list all partitions, then guess; or you can just trial-and-error mount every partiton and look at its contents.
Once you got this, change the file system root:

chroot newroot

chroot should then start a new shell in your new file system, so you should see your familiar shell prompt, and the “pwd” command should tell you something like “/”.

3. Re-install grub2

Now just go ahead and run

grub2-install /dev/hda

(without a number after /dev/hda to install it into the master boot record of that disk). Depending on your hard drive setup and the live disk used, this could also be something like /dev/sda, /dev/sdb or similar.

4. Reboot

Now just reboot your system, you’re done! Make sure your bios boots from the hard drive you just installed grub2 to, in case you have more than one (like me). Once back in your old system, you can change the default entry using

grub2-set-default 2

(this would automatically boot the 3rd entry in the list).

Categories: Everything

Leave a Reply

Your email address will not be published. Required fields are marked *