grub Command in Linux



The grub command, short for GRand Unified Bootloader, is a versatile tool used to configure and manage the boot process in Linux systems. It provides various options and flags to customize the boot behavior and troubleshoot boot-related issues.

Whether it's adding new kernels, modifying boot parameters, or setting the default kernel, GRUB commands provide the necessary tools to manage these tasks efficiently.

Table of Contents

Here is a comprehensive guide to the options available with the grub command −

Understanding the grub Command

The GRUB (Grand Unified Bootloader) is a critical piece of software in Linux systems, responsible for loading and managing the operating system's boot process. Understanding the various options and flags available in the GRUB command can be quite beneficial for system administrators and users who wish to customize their boot process.

grub Command Options

Here's an in-depth look at some of the key options and flags used in GRUB:

Options Descriptions
RUB_DEFAULT This option sets the default menu entry that GRUB will select. It can be a numeric value, representing the position of the menu entry in the list, or the string 'saved', which instructs GRUB to default to the last saved entry.
GRUB_TIMEOUT This flag determines the amount of time, in seconds, that GRUB will wait before automatically booting the default entry. Setting this to zero will cause GRUB to boot immediately without displaying the menu.
GRUB_BACKGROUND This option allows users to set a background image for the GRUB menu, enhancing the visual appearance of the boot menu.
GRUB_DISTRIBUTOR It's often used by distribution maintainers to set a distributor-specific identifier, which can be displayed on the boot menu.
GRUB_CMDLINE_LINUX This is used to pass kernel options at boot. Any parameters specified here will be passed to the kernel every time the system boots.
GRUB_INIT_TUNE With this flag, you can set a tune that GRUB will play when it starts.
GRUB_SAVEDEFAULT If set to 'true', GRUB will automatically save the last selected menu entry as the default for future boots.
GRUB_DISABLE_RECOVERY This option, when set to 'true', disables the generation of recovery mode menu entries.
GRUB_TERMINAL The terminal output can be configured with this option. Setting it to 'console' will force GRUB to use the system console for its display.
GRUB_GFXMODE This flag sets the resolution for the GRUB menu. You can specify resolutions like '640x480' or '1024x768'. Some systems may also support specifying 'auto' to automatically set the best resolution.

These are just a few of the many options available in GRUB. For a comprehensive list, users can refer to the GNU GRUB manual, which provides detailed explanations of all commands and options.

For those interested in further customization or troubleshooting, the ArchWiki and Red Hat documentation provide extensive information on kernel parameters and GRUB commands, respectively. These resources are invaluable for anyone looking to delve deeper into the workings of GRUB and the Linux boot process.

Examples of grub Command in Linux

The GRUB (GRand Unified Bootloader) is a fundamental component in the Linux system that allows users to manage the booting process. It provides flexibility and control over how operating systems are loaded. Here is an in-depth look at various GRUB commands and their applications:

Basic Usage − The most common way to use GRUB is through the command line interface (CLI). You can access the GRUB command line by pressing the "e" key during the boot process, which will allow you to edit the boot parameters.

Example 1: Adding a New Kernel Entry

This command is used to add a new kernel entry to the GRUB menu. The --add-kernel option specifies the path to the kernel, while --title gives a name to the entry, and --initrd points to the initial ramdisk image.

grubby --add-kernel=path_to_kernel --title="entry_title" --initrd=path_to_initrd

Example 2: Removing a Kernel Entry

To remove an existing kernel entry from the boot menu, this command is utilized. The --remove-kernel option requires the path to the kernel you wish to remove:

grubby --remove-kernel=path_to_kernel

Example 3: Updating Kernel Arguments

If you need to modify or add new arguments to a kernel's boot options, this command allows you to do so. Replace new_arguments with the desired kernel parameters.

grubby --update-kernel=path_to_kernel --args="new_arguments"

Example 4: Removing Kernel Arguments

This command removes specific arguments from a kernel's boot options.

grubby --update-kernel=path_to_kernel --remove-args="arguments_to_remove"

Example 5: Listing Installed Kernels

This command lists all the kernels installed on the system along with their associated boot options.

grubby --info=ALL

Example 6: Setting the Default Kernel

You can set the default kernel that the system will boot into using this command.

grubby --set-default=path_to_kernel

Example 7: Displaying the Default Kernel

This command displays the path to the kernel that is currently set as the default.

grubby --default-kernel

Example 8: Adding and Removing Kernel Arguments Simultaneously

This is a combination command that allows you to add and remove kernel arguments in one go.

grubby --update-kernel=path_to_kernel --args="new_arguments"
--remove-args="arguments_to_remove"

These commands offer granular control over the boot process, allowing system administrators to tailor the booting sequence to their needs.

Example 9: Specifies the Kernel Image to Boot

kernel /vmlinuz-4.15.0-55-generic

Example 10: Specifies the Initial RAM Disk (initrd) Image to Load

initrd /initramfs-4.15.0-55-generic.img

Example 11: Sets the Root Filesystem to use During the Boot Process

root=UUID=12345678-abcd-efgh-ijkl-mnopqrstuvwxyz

Example 12: Suppresses Verbose Boot Messages

quiet

Example 13: Disables the Splash Screen During Boot

splash=0

Example 14: Disables Kernel Modesetting, which can help resolve video issues

nomodeset

Example 15: Boots the System into Single-user Mode

single

Example 16: Boots the System into Emergency Mode

emergency

Example 17: Specify the Device to Resume from Hibernation or Suspend

resume=/dev/sda1

These are just a few examples of the many options and flags available in GRUB. The specific options you need will depend on your system configuration and the issues you are trying to address.

Additionally, for practical guidance on changing boot options, the Enable Sysadmin article offers valuable insights. It's important to note that incorrect settings in GRUB can prevent your system from booting properly, so any changes should be made with caution.

Conclusion

Modifying GRUB settings can affect your system's boot process. It's crucial to understand the implications of each command and to make backups of your configuration before making changes.

Remember, always backup your GRUB configuration files before making any changes, as this will allow you to restore the previous settings if needed.

Advertisements