Menu Close
Settings Close

Language and Page Formatting Options

Red Hat Training

A Red Hat training course is available for RHEL 8

Chapter 7. Making persistent changes to the GRUB boot loader

This chapter provides a list of procedures using the grubby tool that lead to persistent changes in GRUB.

7.1. Prerequisites

  • You have successfully installed RHEL on your system.
  • You have root permission.

7.2. Listing the default kernel

By listing the default kernel, you can find the file name and the index number of the default kernel to make permanent changes to the GRUB boot loader.

Procedure

  • To find out the file name of the default kernel, enter:
# grubby --default-kernel
/boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
  • To find out the index number of the default kernel, enter:
# grubby --default-index
0

7.3. Viewing the GRUB menu entry for a kernel

You can list all the kernel menu entries or view the GRUB menu entry for a specific kernel.

Procedure

  • To list all kernel menu entries, enter:

    # grubby --info=ALL
    index=0
    kernel="/boot/vmlinuz-4.18.0-372.9.1.el8.x86_64"
    args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet $tuned_params zswap.enabled=1"
    root="/dev/mapper/rhel-root"
    initrd="/boot/initramfs-4.18.0-372.9.1.el8.x86_64.img $tuned_initrd"
    title="Red Hat Enterprise Linux (4.18.0-372.9.1.el8.x86_64) 8.6 (Ootpa)"
    id="67db13ba8cdb420794ef3ee0a8313205-4.18.0-372.9.1.el8.x86_64"
    index=1
    kernel="/boot/vmlinuz-0-rescue-67db13ba8cdb420794ef3ee0a8313205"
    args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet"
    root="/dev/mapper/rhel-root"
    initrd="/boot/initramfs-0-rescue-67db13ba8cdb420794ef3ee0a8313205.img"
    title="Red Hat Enterprise Linux (0-rescue-67db13ba8cdb420794ef3ee0a8313205) 8.6 (Ootpa)"
    id="67db13ba8cdb420794ef3ee0a8313205-0-rescue"
  • To view the GRUB menu entry for a specific kernel, enter:

    # grubby --info /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
    grubby --info /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
    index=0
    kernel="/boot/vmlinuz-4.18.0-372.9.1.el8.x86_64"
    args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet $tuned_params zswap.enabled=1"
    root="/dev/mapper/rhel-root"
    initrd="/boot/initramfs-4.18.0-372.9.1.el8.x86_64.img $tuned_initrd"
    title="Red Hat Enterprise Linux (4.18.0-372.9.1.el8.x86_64) 8.6 (Ootpa)"
    id="67db13ba8cdb420794ef3ee0a8313205-4.18.0-372.9.1.el8.x86_64"
Note

Try tab completion to see available kernels within the /boot directory.

7.4. Adding and removing arguments from a GRUB menu entry

You can add, remove, or simultaneously add and remove arguments from the GRUB Menu.

Procedure

  • To add arguments to a GRUB menu entry, use the --update-kernel option in combination with --args. For example, following command adds a serial console:

    # grubby --args=console=ttyS0,115200 --update-kernel /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64

    The console arguments are attached to the end of the line, the new console will take precedence over any other configured consoles.

  • To remove arguments from a GRUB menu entry, use the --update-kernel option in combination with --remove-args. For example:

    # grubby --remove-args="rhgb quiet" --update-kernel /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64

    This command removes the Red Hat graphical boot argument and enables log messages, that is verbose mode.

  • To add and remove arguments simultaneously, enter:

    # grubby --remove-args="rhgb quiet" --args=console=ttyS0,115200 --update-kernel /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64

Verification steps

  • To review the permanent changes you have made, enter:

    # grubby --info /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
    index=0
    kernel="/boot/vmlinuz-4.18.0-372.9.1.el8.x86_64"
    args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap $tuned_params zswap.enabled=1 console=ttyS0,115200"
    root="/dev/mapper/rhel-root"
    initrd="/boot/initramfs-4.18.0-372.9.1.el8.x86_64.img $tuned_initrd"
    title="Red Hat Enterprise Linux (4.18.0-372.9.1.el8.x86_64) 8.6 (Ootpa)"
    id="67db13ba8cdb420794ef3ee0a8313205-4.18.0-372.9.1.el8.x86_64"

7.5. Adding a new boot entry

You can add a new boot entry to the bootloader menu entries.

Procedure

  1. Copy all the kernel arguments from your default kernel to this new kernel entry.

    # grubby --add-kernel=new_kernel --title="entry_title" --initrd="new_initrd" --copy-default
  2. Get the list of available boot entries.

    # ls -l /boot/loader/entries/*
    -rw-r--r--. 1 root root 408 May 27 06:18 /boot/loader/entries/67db13ba8cdb420794ef3ee0a8313205-0-rescue.conf
    -rw-r--r--. 1 root root 536 Jun 30 07:53 /boot/loader/entries/67db13ba8cdb420794ef3ee0a8313205-4.18.0-372.9.1.el8.x86_64.conf
    -rw-r--r--  1 root root 336 Aug 15 15:12 /boot/loader/entries/d88fa2c7ff574ae782ec8c4288de4e85-4.18.0-193.el8.x86_64.conf
  3. Create a new boot entry. For example, for the 4.18.0-193.el8.x86_64 kernel, issue the command as follows:

    # grubby --grub2 --add-kernel=/boot/vmlinuz-4.18.0-193.el8.x86_64 --title="Red Hat Enterprise 8 Test" --initrd=/boot/initramfs-4.18.0-193.el8.x86_64.img --copy-default

Verification

  • Verify that the newly added boot entry is listed among the available boot entries.

    # ls -l /boot/loader/entries/*
    -rw-r--r--. 1 root root 408 May 27 06:18 /boot/loader/entries/67db13ba8cdb420794ef3ee0a8313205-0-rescue.conf
    -rw-r--r--. 1 root root 536 Jun 30 07:53 /boot/loader/entries/67db13ba8cdb420794ef3ee0a8313205-4.18.0-372.9.1.el8.x86_64.conf
    -rw-r--r-- 1 root root 287 Aug 16 15:17 /boot/loader/entries/d88fa2c7ff574ae782ec8c4288de4e85-4.18.0-193.el8.x86_64.0~custom.conf
    -rw-r--r--  1 root root 287 Aug 16 15:29 /boot/loader/entries/d88fa2c7ff574ae782ec8c4288de4e85-4.18.0-193.el8.x86_64.conf

7.6. Changing the default boot entry with grubby

With the grubby tool, you can change the default boot entry.

Procedure

  • To make a persistent change in the kernel designated as the default kernel, enter:
# grubby --set-default /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64
The default is /boot/loader/entries/67db13ba8cdb420794ef3ee0a8313205-4.18.0-372.9.1.el8.x86_64.conf with index 0 and kernel /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64

7.7. Updating all kernel menus with the same arguments

You can add the same kernel boot arguments to all the kernel menu entries.

Procedure

  • To add the same kernel boot arguments to all the kernel menu entries, attach the --update-kernel=ALL parameter. For example, this command adds a serial console to all kernels:

    # grubby --update-kernel=ALL --args=console=ttyS0,115200
    Note

    The --update-kernel parameter also accepts DEFAULT or a comma-separated list of kernel index numbers.

7.8. Additional resources

  • The /usr/share/doc/grub2-common directory.
  • The info grub2 command.