Go to the first, previous, next, last section, table of contents.


Installation

First, you need to have GRUB itself properly installed on your system, (see section How to obtain and build GRUB) either from the source tarball, or as a package for your OS.

To use GRUB, you need to install it on your drive. There are two ways of doing that - either using the utility @command{grub-install} (see section Invoking grub-install) on a UNIX-like OS, or by using the native Stage 2. These are quite similar, however, the utility might probe a wrong BIOS drive, so better be careful.

Also, if you install GRUB on a UNIX-like OS, please make sure that you have an emergency boot disk ready, so that you can rescue your computer if, by any chance, your hard drive becomes unusable (unbootable).

GRUB comes with boot images, which are normally installed in the directory `/usr/share/grub/i386-pc'. You need to copy the files `stage1', `stage2', and `*stage1_5' to the directory `/boot/grub'. Here the directory where GRUB images are installed and the directory where GRUB will use to find them are called image directory and boot directory, respectively.

Creating a GRUB boot floppy

To create a GRUB boot floppy, you need to take the files `stage1' and `stage2' from the image directory, and write them to the first and the second block of the floppy disk, respectively.

Caution: This procedure will destroy any data currently stored on the floppy.

On a UNIX-like operating system, that is done with the following commands:

# cd /usr/share/grub/i386-pc
# dd if=stage1 of=/dev/fd0 bs=512 count=1
1+0 records in
1+0 records out
# dd if=stage2 of=/dev/fd0 bs=512 seek=1
153+1 records in
153+1 records out
#

The device file name may be different. Consult the manual for your OS.

Installing GRUB natively

Caution: Installing GRUB's stage1 in this manner will erase the normal boot-sector used by an OS.

GRUB can currently boot GNU Mach, Linux, FreeBSD, NetBSD, and OpenBSD directly, so using it on a boot sector should be okay. But generally, it would be a good idea to back up the first sector of the partition on which you are installing GRUB's stage1. This isn't as important if you are installing GRUB on the first sector of a hard disk, since it's easy to reinitialize it (e.g. by running `FDISK /MBR' from DOS).

If you decide to install GRUB in the native environment, which is definitely desirable, you'll need to create the GRUB boot disk, and reboot your computer with it. Otherwise, see section Installing GRUB using grub-install, for more details.

Once started, GRUB will show the command-line interface (see section The flexible command-line interface). First, set the GRUB's root device(4).} to the boot directory, like this:

grub> root (hd0,0)

If you are not sure which partition actually holds these files, use the command @command{find} (see section find), like this:

grub> find /boot/grub/stage1

This will search for the file name `/boot/grub/stage1' and show the devices which contain the file.

Once you've set the root device correctly, run the command @command{setup} (see section setup):

grub> setup (hd0)

This command will install GRUB on the MBR in the first drive. If you want to install GRUB into the boot sector of a partition instead of the MBR, specify a partition into which you want to install GRUB:

grub> setup (hd0,0)

If you install GRUB into a partition or a drive other than the first one, you must chain-load GRUB from another boot loader. Refer to the manual for the boot loader to know how to chain-load GRUB.

Now you can boot GRUB without a GRUB floppy. See the chapter section Booting to find out how to boot your operating systems from GRUB.

Installing GRUB using grub-install

Caution: This procedure is definitely deprecated, because there are several posibilities that your computer can be unbootable. For example, most operating systems don't tell GRUB how to map BIOS drives to OS devices correctly, GRUB merely guesses the mapping. This will succeed in most cases, but not always. So GRUB provides you with a user-defined map file called device map, which you must fix, if it is wrong. See section The map between BIOS drives and OS devices, for more details.

Unfortunately, if you do want to install GRUB under a UNIX-like OS (such as GNU), invoke the program @command{grub-install} (see section Invoking grub-install) as the superuser (root).

The usage is basically very easy. You only need to specify one argument to the program, namely, where to install GRUB. The argument can be either of a device file or a GRUB's drive/partition. So, this will install GRUB into the MBR of the first IDE disk under Linux:

# grub-install /dev/hda

Likewise, under Hurd, this has the same effect:

# grub-install /dev/hd0

If it is the first BIOS drive, this is the same as well:

# grub-install '(hd0)'

But all the above examples assume that you use GRUB images under the root directory. If you want GRUB to use images under a directory other than the root directory, you need to specify the option @option{--root-directory}. The typical usage is that you create a GRUB boot floppy with a filesystem. Here is an example:

# mke2fs /dev/fd0
# mount -t ext2 /dev/fd0 /mnt
# grub-install --root-directory=/mnt '(fd0)'
# umount /mnt

Another example is in case that you have a separate boot partition which is mounted at `/boot'. Since GRUB is a boot loader, it doesn't know anything about mountpoints at all. Thus, you need to run @command{grub-install} like this:

# grub-install --root-directory=/boot /dev/hda

By the way, as noted above, it is quite difficult to guess BIOS drives correctly under a UNIX-like OS. Thus, @command{grub-install} will prompt you to check if it could really guess the correct mappings, after the installation. The format is defined in section The map between BIOS drives and OS devices. Please be careful enough. If the output is wrong, it is unlikely that your computer can boot with no problem.

Note that @command{grub-install} is actually just a shell script and the real task is done by the grub shell @command{grub} (see section Invoking the grub shell). Therefore, you may run @command{grub} directly to install GRUB, without using @command{grub-install}. Don't do that, however, unless you are very familiar with the internals of GRUB. Installing a boot loader on a running OS may be extremely dangerous.


Go to the first, previous, next, last section, table of contents.