When you are working on an already installed linux distribution, the grub package will be bydefault installed on the system.
I will be showing you, the example’s of working with grub-legacy. Because any grub version number thats in the form 0.9x is grub-legacy now.(Please note the fact that grub-legacy is no longer under active developement.)
For this example, i will be working on a Red hat enterprise linux 5.
[root@localhost ~]# rpm -qa | grep grub
grub-0.97-13.5
[root@localhost ~]#
the above shown package, will also provide you with a command called grub-install.
[root@localhost ~]# whereis grub-install
grub-install: /sbin/grub-install /usr/share/man/man8/grub-install.8.gz
[root@localhost ~]# rpm -qf /sbin/grub-install
grub-0.97-13.5
As you can clearly see from the above command results that the grub-install command comes from the package grub-0.97-13.5
[root@localhost ~]# grub-install /dev/sda
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0) /dev/sda
[root@localhost ~]#
In the above command, it will install grub in the MBR of the hard disk /dev/sda.
the above command result tells you an important fact to understand. It tells that, there is a device map file, and is asking us to check and confirm whether the file is correct or not.
Device map file is used by grub to identify the OS device names in a precise way. GRUB uses this file to map the device names of BIOS to operating system device names.This was devised, because there was inconstancies with, Linux operating system’s device naming convention.
This file is configurable as per your requirement.
In the above example output of the /boot/grub/device.map tells that (hd0) in grub means /dev/sda in the operating system.
Whenever you install GRUB, on any of your partition, it gets installed and images are put under the directory “boot” in that partition.
If you want to install grub, under a directory other than the default “boot”, you need to specify the boot directory with a command line argument to grub-install command.
Imagine that you want to install grub, on one of your external hard disk, and is currently mounted under /mydisk. lets see how to do it.
[root@localhost ~]# grub-install --root-directory=/mydisk/grub/ /dev/sdb