Grub install

When you install some operating systems such as Windows or Mac OS X, they will overwrite your master boot record. If you have Linux installed you will be unable to access it, until you restore Grub on the MBR.

The easiest way is to find your Ubuntu or other Linux rescue/live/installation CD and boot it. Pop open a terminal and first find which partition is your root using fdisk.

sudo fdisk -l

below is a sample output from my system we can use for this scenario.

Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        4717    37889271    7  HPFS/NTFS
/dev/hda2            4718        4865     1188810    e  W95 FAT16 (LBA)

Device Boot Start End Blocks Id System
Disk /dev/hdc: 13.0 GB, 13020069888 bytes
255 heads, 63 sectors/track, 1582 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/hdc1   *           1        1514    12161173+  83  Linux
/dev/hdc2            1515        1582      546210    5  Extended
/dev/hdc5            1515        1582      546178+  82  Linux swap / Solaris

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       14593   117218241   83  Linux

Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3885    31206231    c  W95 FAT32 (LBA)
/dev/sdb2            3886       14593    86012010    7  HPFS/NTFS

Here we see that /dev/hdc1 is our Linux partition, so we will want to mount it in order to read the Grub configuration.

sudo mkdir /mnt/mydisk
sudo mount /dev/hdc1 /mnt/mydisk

If your don’t get any errors now your root partition should be mounted under /mnt. You can check for the grub configuration by listing the contents of the directory /mnt/boot/grub.

to edit grub follow this

When you get to the desktop open a terminal and enter. (I am going to give you the commands and then I will explain them later)

sudo grub

This will get you a “grub>” prompt (i.e. the grub shell). At grub>. enter these commands

find /boot/grub/stage1

This will return a location. If you have more than one, select the installation that you want to provide the grub files. This will be the one that was listed earlier in my case hdc1. Next, THIS IS IMPORTANT, whatever was returned for the find command use it in the next line (you are still at grub>. when you enter the next 3 commands)

root (hd?,?)

Again use the value from the find command i.e. if find returned (hd0,1) then you would enter root (hd0,1)

Next enter the command to install grub to the mbr

setup (hd0)

Finally exit the grub shell

quit

That is it. Grub will be installed to the mbr. When you reboot, you will have the grub menu at startup.

Other info

some advice to avoid confusion , grubs drive numbering convention doesn't see sda drives as such (sata and usb drives) so you will have a file called device.map that will map the various drives on your system and allocate a grub friendly string for it to use.

heres an example of a device.map file

(hd0) /dev/hda
(hd1) /dev/hdb
(hd2) /dev/hdc
(hd3) /dev/sda
(hd4) /dev/sdb

Full List Of GRUB Errors

External Link to GRUB manual

 
restore_grub_on_linux.txt · Last modified: 2008/07/08 17:15 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki