grub – Command line shell tool for multiboot grub

GRUB (Grand Unified Bootloader) is a boot loader package that allows users to choose between multiple operating systems installed on a computer or select different kernel configurations for a single operating system. The grub command is a command-line shell tool for configuring and managing GRUB.

Overview

The grub command can be used to install and configure GRUB, manage boot entries, and troubleshoot boot issues. Here are some common use cases:

Install GRUB

To install GRUB, use the following command:

grub-install /dev/sda

This will install GRUB on the master boot record (MBR) of the first hard drive (/dev/sda).

Configure GRUB

To configure GRUB, edit the /etc/default/grub configuration file and then regenerate the grub configuration file using the update-grub command. For example, to set the default boot entry to Ubuntu, edit the GRUB_DEFAULT line in /etc/default/grub to read:

GRUB_DEFAULT="Ubuntu"

Then regenerate the grub configuration file using the following command:

update-grub

Manage boot entries

To manage boot entries, edit the /etc/grub.d/40_custom file and then regenerate the grub configuration file using the update-grub command. For example, to add a custom boot entry for Windows, add the following lines to /etc/grub.d/40_custom:

menuentry "Windows" {
    set root=(hd0,1)
    chainloader +1
}

Then regenerate the grub configuration file using the following command:

update-grub

Troubleshoot boot issues

If you encounter boot issues, you can use the grub command to manually boot into a specific kernel or rescue mode. For example, to boot into the second kernel entry, use the following command:

grub> set root=(hd0,1)
grub> linux /boot/vmlinuz-4.15.0-72-generic root=/dev/sda1
grub> initrd /boot/initrd.img-4.15.0-72-generic
grub> boot

Options

Here are some of the available options for the grub command:

Option Description
grub-install Install GRUB on a device
grub-mkconfig Generate a GRUB configuration file
grub-mkimage Generate a bootable image of GRUB
grub-probe Probe device information for a given path
grub-reboot Set the default boot entry for the next boot only
grub-set-default Set the default boot entry permanently
grub-editenv Manage the GRUB environment block

Troubleshooting tips

Here are some common issues you may encounter with the grub command and how to troubleshoot them:

GRUB not installed

If you get an error message saying that GRUB is not installed, you can install it using the grub-install command.

GRUB configuration not updated

If you make changes to the GRUB configuration file but they are not reflected in the boot menu, you may need to regenerate the configuration file using the update-grub command.

Boot entry not found

If a boot entry is not found or is not working, check that the device and path information in the configuration file are correct.

Notes

The grub command is a powerful tool for managing the GRUB bootloader. However, it should be used with caution as incorrect usage can cause boot issues. Always make a backup of your configuration files before making changes.