Search

Chapter 7. Making persistent changes to the GRUB boot loader

download PDF

Use the grubby tool to make 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. Editing a Kernel Argument

You can change a value in an existing kernel argument. For example, you can change the virtual console (screen) font and size.

Procedure

  • Change the virtual console font to latarcyrheb-sun with the size of 32.

    # grubby --args=vconsole.font=latarcyrheb-sun32 --update-kernel /boot/vmlinuz-4.18.0-372.9.1.el8.x86_64

7.5. 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

  • 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.6. 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.7. 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.8. 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.9. Changing default kernel options for current and future kernels

By using the kernelopts variable, you can change the default kernel options for both current and future kernels.

Procedure

  1. List the kernel parameters from the kernelopts variable:

    # grub2-editenv - list | grep kernelopts
    kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
  2. Make the changes to the kernel command-line parameters. You can add, remove or modify a parameter. For example, to add the debug parameter, enter:

    # grub2-editenv - set "$(grub2-editenv - list | grep kernelopts) <debug>"
  3. Optional: verify that the newly added parameter has been added to kernelopts:

    # grub2-editenv - list | grep kernelopts
    kernelopts=root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet debug
  4. Reboot the system for the changes to take effect.
Note

As an alternative, you can use the grubby command to pass the arguments to current and future kernels:

# grubby --update-kernel ALL --args="<PARAMETER>"

7.10. Additional resources

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

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.