Restoring GRUB on Ubuntu

Possibly the only useful article on the previous incarnation of this blog was this on, detailing how to pull GRUB back up under Ubuntu. This was written with reference to Ubuntu 4, which I was hooked on like a turbot.

There are many standard ways of reinstalling GRUB – most involve using a Linux rescue floppy (which noone creates) or a Linux Live CD, like Knoppix. Once you have yourself a prompt, you should be able to do this:

# grub
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

… and that’s it. However, you’ll find that you grub will spit back at you “Filesystem type unknown, using whole disk” and you won’t be able to do anything else.

The best way of doing this in a normal distribution is to run:

# grub-install /dev/hda

… but that craps out in Ubuntu, giving you these lines:

/sbin/grub-install: line 429: /dev/null: Permission denied
/sbin/grub-install: line 431: /dev/null: Permission denied

Hungsquirrel puts us on the straight and narrow with this convolved but brilliant solution, slightly modified by me:

  • Boot up your Ubuntu install CD
  • Wait until your install CD has detected your drives – it will be just about to partition your system
  • Switch to console 2 by ctrl+alt+F2
  • Hit enter to activate the console
  • # mkdir mounted
  • # mount /dev/ide/host0/bus0/target0/lun0/part5 mounted
  • # chroot mounted /bin/bash
  • # grub-install /dev/hda

Remember to substitute the /dev/ide/host0/bus0/target0/lun0/part5 for whatever the location of your root drive is. For example, if your booting from hd1,3 (physical drive 1, partition 3) then use /dev/ide/host0/bus0/target1/lun0/part3. Most people will be booting from physical drive 0 somewhere. If you’re not sure where you’re booting from, the quickest way is to note it from the pre-partitioning setup screen in Ubuntu install.

When this reinstalls Grub, since it reads the menu.lst file directly from your root drive, your Grub menu will come back up exactly as you left it.

Credits:
Hungsquirrel post


Comments

Leave a Reply

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