grubinstall

grubinstall installs a GRUB boot loader on a fixed disk. It's simpler and easier to understand than the methods that come with the GRUB package.

Examples


    grubinstall -stage1=/usr/lib/grub/i386pc/stage1 \
                -stage2=/usr/lib/grub/i386pc/stage2 \
                -config=(0x80,0)/boot/grub.conf \
                /dev/hda


Overview

grubinstall -stage1=filename -stage2=filename [-config=grub_filename] boot_device_file

General

grubinstall installs GRUB on a boot disk, so you're ready to boot that device.

grubinstall uses a particular method of installing that is simple, easy to understand, and hard to get wrong. In contrast, the GRUB package comes with tools to install in various ways, and those tools are hard to understand (partly because they are poorly documented) and the common methods are equally hard to grasp and easy to mess up.

More comparison of grubinstall and other methods of installing GRUB are here.

grubinstall installs like this:

To use grubinstall, you must ensure the first 256K of your boot disk is free for use by a boot loader. I.e. don't allocate any partition in it, or allocate a partition but don't use it for anything.

We call the first 256K of your boot disk the boot area.

grubinstall works only on a boot disk with DOS partitioning or no partitioning; in particular, it avoids the last 66 bytes of the first 512-byte sector of the disk because that's where a DOS format partition table and disk format signature go, but writes over the rest of the boot area. If you have a computer of the kind that typically runs Windows, your fixed disks almost certainly have DOS partitioning.

To use grubinstall, you will need the stage 1 and stage 2 loader files from the GRUB package; these are inputs to grubinstall. (it is actually a misnomer to call what is in those files the loaders; they are actually templates for the loaders. One normally uses them in combination with other information to create a runnable instance of GRUB).

Unlike some other methods of using GRUB, when you use grubinstall, GRUB does not execute stage 2 code from your filesystem. grubinstall makes a copy in the boot area (not in any filesystem) and that is what gets loaded at boot time. That means after you run grubinstall, you don't have to worry about any files moving around in your filesystem. You can even delete the GRUB package from your filesystem completely; it isn't necessary for boot.

Floppy Disk

You can use grubinstall to install to a floppy disk. It's not easy to have anything else on the floppy in addition to GRUB, but you don't necessarily need anything else; you can have GRUB access configuration files and operating system images from some other device. You can even load a new floppy disk after GRUB starts up and have GRUB access files on that.

GRUB Version

There are two rather different versions of GRUB around: the original GRUB and GRUB 2. The GRUB web site refers to original GRUB as Legacy GRUB, but don't let that make you believe it's obsolete for new use. When I investigated both in October 2007, I found original GRUB to be superior for my purposes. Its advantages: it is simpler, more mature, and better documented.

Consequently, I created grubinstall for original GRUB and it may not be straightforward to use it with GRUB 2.

In particular, I have used it successfully with GRUB 0.97.

Arguments

boot_device_file names the device special file for the boot device. grubinstall writes GRUB onto this device.

It doesn't actually have to be a device special file -- any seekable file will do. You might want to create a disk image in a regular file and transfer it to a bootable disk when you are done.

Options

-stage1=filename
This names the file that contains the GRUB stage 1 loader, from the GRUB package. The file actually contains the template of the entire contents of a boot sector, which includes a template of the stage 1 loader and some arbitrary data for a partition table. grubinstall uses only the loader part.

grubinstall uses the contents of this file as the template for the stage 1 loader it writes into the boot sector (i.e. the first sector) of the boot device.

-stage2=filename
This names the file that contains the GRUB stage 2 loader, from the GRUB package. Actually, the file is just a template for the Stage 2 loader.

grubinstall uses the contents of this file as the template for the stage 2 loader it writes on the boot device.

-config=grub_filename
This is the file name by which GRUB is supposed to access its configuration file. Note that this is a GRUB file name, not a Unix file name, and grubinstall does not access the file in any way or even verify that such a file exists. All grubinstall does is include this name in the stage 2 loader it writes on the boot device so that said loader can access the configuration file at boot time.

See GRUB documentation for information on GRUB file names. But in all likelihood, what you will want is (0x80,0)/ followed by the Unix filename of the file in your system.

If you don't specify this option, grubinstall sets up GRUB to use no configuration file. That means it won't display a menu; just a GRUB command prompt. You will have to type in the necessary boot commands longhand. One command you might type is a config command, which causes GRUB to process a configuration file you name on the command.

Note that if you specify with -config a file that doesn't actually exist at boot time, it's not a catastrophe. It just means GRUB behaves as if you had not specified a configuration file at all (see above).