GRUB: Restore GRUB

From Sidvind
Jump to: navigation, search

Description[edit]

Booting with a Windows XP installations cd means that the bootsector gets overwritten and thus grub won't boot any longer. This article describes how to reinstall grub into the bootsector. Quick steps:

  1. Boot with a livecd. Make sure to login as root. In this example I use the Gentoo 2005.1 livecd (universal installation cd).
  2. Mount appropriate partition
# mkdir /mnt/foo
# mount /dev/hda2 /mnt/foo

If you have a sepecial bootpartition you should also mount that one now.

# mount /dev/hda1 /mnt/foo/boot
  1. chroot into the partition
# mount -t proc none /mnt/foo/proc 
# chroot /mnt/foo /bin/bash
  1. run grub
# grub --no-floppy

Use --no-floppy to skip probing for floppydrives. Alternative you could run grub-install here and skip the next step.

  1. Install grub on the bootsector.
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

root points to the drive and partition that contains the boot-directory and setup points to the drive that grub should be installed into.

  1. exit out of the chrooted envirioment and reboot
# exit
# reboot

Summary[edit]

Boot with a livecd, login as root

# mkdir /mnt/foo
# mount /dev/hda2 /mnt/foo
# mount /dev/hda1 /mnt/foo/boot
# mount -t proc none /mnt/foo/proc
# chroot /mnt/foo /bin/bash
# grub-install
grub> root (hd0,0)
grub> setup (hd0)
grub> quit
# exit
# reboot

How to find out which drive grub should use[edit]

Having problems with linux and grub reporting the drives in a different order?

Grub maintains a list of what a linux drive would be in grub. Look at /boot/grub/device.map once you booted the system. In case you need to know when you booted using the livecd, just look at the same directory but on the mounted partition.

  1. less /boot/grub/device.map (hd0) /dev/hda

As you can see the file first tells us the drive as grub reports it and then how linux would. Here the drives are listed in a correct order but using IDE-controller card etc can make the orders a bit confusing.

Where is my boot partition?

How do I know which partition holds my bootfiles? Grub has a simple command to find it. grub> find /boot/grub/stage1 (hd0,0)

If it won't return anything you might have a separate boot partition, so try this instead. grub> find /grub/stage1 (hd0,1)

Grub just looks at the partition and checks if it can find the file you asked for. It won't look recursive so we need to specify the full path. In case you have a separate boot partition we need to specify the full path but with /boot as base.