Run grub-install from a live CD

From ArchBang

Jump to: navigation, search

How to install/reinstall GRUB in case you mess up installing on multiple boot or delete your GRUB failing to install GRUB2 or whatever.

Start up your favorite live CD. If you are unaware of the the location of /boot, use the GRUB shell find command to locate the GRUB files. When you get to the desktop, open a terminal and enter the GRUB shell as root by:

 # grub

The following example is for systems without a separate /boot partition, wherein /boot is merely a directory under /.This will get you a "grub>" prompt. At grub> enter these commands:

 # grub> find /boot/grub/stage1

The following example is for systems with a separate /boot partition:

 # grub> find /grub/stage1

GRUB will find the file, and output the location of the stage1 file. For example:

 # grub> find /grub/stage1
 (hd0,0)

Grub numbers the hard drives and partitions starting with 0. So hd0,0 would be the first partition on the first hard drive.

Next enter the command to install grub to the master boot record (MBR):

 # grub> setup (hd0)

If you need to install grub to a partition instead of the MBR, then enter that partition. For example, to install on the second partition of the first hard drive enter:

 # grub> setup (hd0,1)

If you get an error like "Error 12: Invalid device requested". Then enter:

 # grub> root (hd0,0)

Using the location of the boot directory as found by the find command above. Then run the setup command again.

Finally exit the grub shell:

 # quit

If you can't get grub to find the stage1 file or even recognize your drive then we'll use a Gentoo tip:

You have to mount your root partition using the livecd:

 # mkdir /mnt/root
 # mount -t ext3 /dev/sda6 /mnt/root

Then you have to mount the proc subsystem and udev inside /mnt/root also:

 # mount -t proc none /mnt/root/proc
 # mount -o bind /dev /mnt/root/dev

Doing this allows grub to discover your drives. Next you have to chroot:

 # chroot /mnt/root /bin/bash

Now that you're chrooted into your drive as root everything should work.

 # grub
 # grub> find /boot/grub/stage1

For example maybe yours is on (hd0,5) Code:

 # grub> root (hd0,5)

It successfully scanned the partition and recognized the filesystem-type

 # grub> setup (hd0)

and then

 # quit


Back to Table of Contents

Personal tools