linux poison RSS
linux poison Email

How to restore GRUB with an Ubuntu Live CD

Sometimes, if an Ubuntu installation goes wrong, or a Windows bootloader overwrites MBR and doesn't recognise the Linux installation, we have to restore our GRUB bootloader

we boot the Live CD, we choose the first option and in a few minutes we have arrived at the Live CD Desktop.

So, we go :  Applications --> Accessories --> Terminal

Then, we have to remember which is our Ubuntu installation partition.

In our example, it is the second one (/dev/sda2), formatted as ext3, in the first HDD of a SATA controller. We suppose that it is the second one, since, in case we have Windows that demand to be in the first partition (/dev/sda1), this one is occupied.

Now, you have to be really careful. You have to enter the right partition, instead of sda2 (unless it is the same) In the terminal :

  cd /
  sudo -s -H
  mount -t ext3 /dev/sda2 /mnt
  mount -t proc proc /mnt/proc
  mount -t sysfs sys /mnt/sys
  mount -o bind /dev /mnt/dev
  chroot /mnt  /bin/bash

And now, you are actually "running" Ubuntu within the Hard Drive but through Live CD's terminal.

Now we restore GRUB like that:

1) Restoration to MBR

  grub-install /dev/sda

2) Restoration to partition (example: /dev/sda2)

  grub-install /dev/sda2

In the first case (that is the most usual) you have certainly installed GRUB on MBR after you receive, in the terminal, the message that there are no errors.

After you reboot, you have your favorite bootloader restored.


Anonymous said...

If you are merely trying to restore Grub to the master boot record (MBR), and not actually trying to regenerate all of Grub's system files in /boot/grub, it is much easier to do it from the Grub CLI with:

sudo grub
grub> find /boot/grub/stage1

The above command should return your Ubuntu partition in the form (hdX,Y), or if you all ready know the partition and can translate it to (hdX,Y), use that. Just remember that Grub's numbering starts with 0, not 1, so sda1 is (hd0,0), sda2 is (hd0,1), sda3 is (hd0,2), etc. Then proceed:

grub> root (hdX,Y)
grub> setup (hdX)

That will install Grub to the MBR of the same drive as the drive Ubuntu is on. If you have more than one drive and wish to install Grub to the MBR of the boot drive, use "setup (hd0)".

Post a Comment

Related Posts with Thumbnails