GRUB comes with a shell script, grub-install, which uses the GRUB shell to automate the installation. The grub-install command installs the GRUB Legacy boot loader. In the following example, the boot loader is installed in the MBR of the first SATA hard disk:
# grub-install /dev/sda
The grub-install command also creates configuration files in the /boot/grub directory. Here are the grub-install command options:
Command Options | Descriptions |
-h, –help | print this message and exit |
-v, –version | print the version information and exit |
–root-directory=DIR | install GRUB images under the directory DIR instead of the root directory |
–grub-shell=FILE | use FILE as the grub shell |
–no-floppy | do not probe any floppy drive |
–force-lba | force GRUB to use LBA mode even for a buggy BIOS |
–recheck | probe a device map even if it already exists. This option is unreliable and its use is strongly discouraged. |
NOTE: To install the newer GRUB2 boot loader, use the following command:
# grub2-install /dev/sda
Installing from the GRUB command line
To install GRUB from the native command environment, make a GRUB boot disk as described previously. You will use that disk to boot to the GRUB command line to do the installation. If you know which partition holds the GRUB files, you’re all set. Otherwise, you can find the partition with the find command:
grub> find /boot/grub/stage1 (hd0,0)
Here, the files are on (hd0,0). Use that information to set the GRUB root device:
grub> root (hd0,0)
Run the setup command to install GRUB. To install GRUB on the MBR, run setup as follows:
grub> setup (hd0)
If you are going to chainload Linux and want to install GRUB on the boot sector of the Linux partition, run setup like this:
grub> setup (hd0,0)