How to install and boot custom kernels in Red Hat Enterprise Linux 8

Updated

Overview

The Boot Loader Specification (BLS) defines a scheme and file format to manage bootloader configurations for each boot option in a drop-in directory. There is no need to manipulate the individual drop-in configuration files.

This premise is particularly relevant in Red Hat Enterprise Linux 8 because not all architectures use the same bootloader:

  • x86_64, aarch64 and ppc64le with open firmware use GRUB2
  • ppc64le with Open Power Abstraction Layer (OPAL) uses Petitboot
  • s390x uses zipl.

Each bootloader has a different configuration file and format that has to be modified when a new kernel is installed or removed. In the previous versions of Red Hat Enterprise Linux the component that permitted this work was the grubby utility. However, for Red Hat Enterprise LInux 8 the bootloader configuration was standardized by implementing the BLS file format, where grubby works as a thin wrapper around the BLS operations.

How to install a new self-built kernel?

Use the make modules_install command to compile binaries and install those binaries into your kernel's modules directory.

How to list all installed kernels?

Execute # grubby --info=ALL | grep title to show a list of installed kernels from the command line of a booted machine:

title=Red Hat Enterprise Linux (4.18.0-20.el8.x86_64) 8.0 (Ootpa)
title=Red Hat Enterprise Linux (4.18.0-19.el8.x86_64) 8.0 (Ootpa)
title=Red Hat Enterprise Linux (4.18.0-12.el8.x86_64) 8.0 (Ootpa)
title=Red Hat Enterprise Linux (4.18.0) 8.0 (Ootpa)
title=Red Hat Enterprise Linux (0-rescue-2fb13ddde2e24fde9e6a246a942caed1) 8.0 (Ootpa)

What is $kernelopts?

$kernelopts is a variable, which contains kernel command line parameters. The variable is defined in /boot/efi/EFI/redhat/grubenv for EFI systems, and in /boot/grub2/grubenv for legacy BIOS as well as ppc64le systems. The grubenv file should not be edited with a text editor. Use the following command instead:

# grub2-editenv - set kernelopts="root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rd.debug=1 rhgb"

Alternatively, another supported way how to update the kernel command line parameters is to edit the GRUB_CMDLINE_LINUX key in the /etc/default/grub file and execute the # grub2-mkconfig -o /boot/grub2/grub.cfg command to update the GRUB2 configuration file.

What is a boot entry?

The boot entries are located in the /boot/loader/entries/ directory. For further information about boot entries, refer to What are boot entries.

How to add and remove kernel parameters to a specific boot entry?

Run the following command to add a kernel parameter:

grubby --update-kernel /boot/vmlinuz-foo --args="rd.debug=1"

Execute the following command to remove a kernel parameter:

grubby --update-kernel /boot/vmlinuz-foo --remove-args="rhgb"

IMPORTANT
Once you edited a specific boot entry, the contents of $kernelopts are stored in the relevant boot entry and have their own command line now. Therefore, any additional changes to $kernelopts will not affect that boot entry.

How to boot a specific kernel?

To set a default kernel, execute the grub2-set-default <index|title|machine_id> command as in the example below:

grub2-set-default "e7d8d6d4c5d14f2c82bcae6c79d3b8d8-4.18.0-70.el8.x86_64"

The command above uses a machine ID without the .conf suffix as an argument. The machine ID is located in the /boot/loader/entries/ directory.

To set the default kernel for the next time only reboot run

# grub2-reboot <index|title|id> 

WARNING
Be careful when setting the default kernel or selecting a next-boot-only kernel. Because installing new kernel RPMs, installing self-built kernels, and manually adding entries to the /boot/loader/entries directory will change the index values.

To set a default kernel through grubby:

# grubby --info=ALL 
# grubby --set-default /boot/vmlinuz-foo

Additional resources:

Configuring kernel command line parameters

Article Type