Restoring the GNU Grub

This is a post I had written in an old blog that I abandoned a long time ago. I re-publish it here to help everyone who might have a problem trying to restore grub.

Have you ever found yourself locked out of a Windows installation and had to reinstall them? If so, you have probably noticed that Windows restores the NTLDR (the NT bootloader) to the MBR and Grub disappears. In order to regain access to your GNU/Linux distribution you have to re-install grub and that can be confusing since nearly 1 out of 2 guides out there WILL NOT work (at least not the way they should)…

This happened to me just yesterday and the (manual) steps I describe below worked fine. Enough with the talking, let’s start.

There are two easy ways to reinstall/restore Grub: either automatically or manually.

The automatic way: Super Grub Disk is a LiveCD-based solution for restoring grub via a user-friendly interface. After a couple of minutes you will be asked to reboot and grub will be restored, simply and easily. This solution worked for many people I know but not for me, so I used the manual way which I describe just below.

The manual way:

  1. Get yourself a small LiveCD, I personally used Slax standard edition 5.1.8.1 but any LiveCD should do just fine.
  2. Boot using the LiveCD and mount the partition containing your distribution (if it hasn’t been already mounted by the LiveCD distro)
  3. Open a terminal window, gain root access, and type: “chroot /mnt/hd??” OR “chroot /media/hd??” where the first “?” stands for the hard disk letter and the second “?” stands for the partition number. Note that some distributions use “/media” for mounting drives, so check both “/mnt” and “/media” before attempting to manually mount the partition. If you don’t know which is the distribution partition (e.g. If you have multiple distros installed) then just navigate to the directories you mounted on the previous step until you determine which is the right one.
  4. Type “grub“, a message saying “Probing devices to guess BIOS drives” should appear, just wait for a couple of minutes and soon you will see the grub prompt (it looks like “grub> _”)
  5. Type “find /boot/grub/stage1“. The result will be like “(hd0,5)” or perhaps “(hd0)”. Keep this in mind because it is a key-text for the next steps.
  6. Type “root (hd?,?)“, replace the question marks with what the output of the command above was.
  7. Now we are ready to install grub, select one of the following options depending on the place you want to install grub:
    • If you want to install grub on the MBR (recommended for most installations) type “setup (hd?)” where “?” is the result BEFORE the comma that command in step 5 returned
    • If you know what you are doing and want to install it on a separate partition, type “setup (hd?,?)” where the first “?” stands for the pre-comma output of the command of step 5 and the second “?” stands for the partition number.
  8. Type “quit” to exit the grub prompt
  9. Reboot the computer and remove the LiveCD, grub should now appear

LINKS:
GNU GRUB | Wikipedia Article – GNU GRUB | Wikipedia Article – NTLDR | Wikipedia Article – Master Boot Record (MBR) | Super Grub Disk | Slax |

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: