Manage the Boot Kernel with Grubby on Oracle Linux

10
2
Send lab feedback

Manage the Boot Kernel with Grubby on Oracle Linux

Introduction

Grubby is a flexible and powerful command-line tool that provides users with an easy way to modify the bootloader configuration used by Oracle Linux without users having to manually edit the GRUB (GRand Unified Bootloader) or GRUB2 configuration files directly. In most cases, changing the default kernel is unnecessary because Oracle Linux defaults to a configuration and behavior to use and boot the most recent kernel version first. Grubby is also scriptable, making managing your system's default kernel requirements easier. Reasons why you should consider using grubby include:

  • It has a simple command-line structure that makes managing bootloader settings much easier.
  • It provides an easy way to list and manage multiple kernels, simplifying updating kernel parameters or changing the default kernel.
  • It works with both UEFI and BIOS-based systems.
  • It removes the risk associated with manual editing of bootloader files directly.

Objectives

In this tutorial, you'll learn how to:

  • Determine the currently loaded kernel
  • Determine the default kernel
  • Determine which kernel versions are available on the system
  • Use grubby to manage kernels

Prerequisites

  • Minimum of a single Oracle Linux system

  • Each system should have Oracle Linux installed and configured with:

    • A non-root user account with sudo access
    • Access to the Internet

Deploy Oracle Linux

Note: If running in your own tenancy, read the linux-virt-labs GitHub project README.md and complete the prerequisites before deploying the lab environment.

  1. Open a terminal on the Luna Desktop.

  2. Clone the linux-virt-labs GitHub project.

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
  3. Change into the working directory.

    cd linux-virt-labs/ol
  4. Install the required collections.

    ansible-galaxy collection install -r requirements.yml
  5. Deploy the lab environment.

    ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6"

    The free lab environment requires the extra variable local_python_interpreter, which sets ansible_python_interpreter for plays running on localhost. This variable is needed because the environment installs the RPM package for the Oracle Cloud Infrastructure SDK for Python, located under the python3.6 modules.

    The default deployment shape uses the AMD CPU and Oracle Linux 8. To use an Intel CPU or Oracle Linux 9, add -e instance_shape="VM.Standard3.Flex" or -e os_version="9" to the deployment command.

    Important: Wait for the playbook to run successfully and reach the pause task. At this stage of the playbook, the installation of Oracle Linux is complete, and the instances are ready. Take note of the previous play, which prints the public and private IP addresses of the nodes it deploys and any other deployment information needed while running the lab.

Check Available Kernels

Kernels are named to include the upstream version number and the distribution build numbering. The kernel names on Oracle Linux indicate they are standard RedHat Compatible Kernel (RHCK) or Unbreakable Enterprise Kernel (UEK) based. Additionally, the names identify their system architecture. For example, the el8 suffix would indicate an RHCK, while el8uek would indicate a UEK. Several methods are available for checking which kernels are available on a system:

  1. Open a terminal and connect via SSH to the ol-node-01 instance.

    ssh oracle@<ip_address_of_instance>
  2. Use the RPM package manager to list all available kernels that you could install.

    sudo rpm -qa kernel*

    The output includes both the kernel and other kernel-related packages.

  3. List all the kernels currently installed.

    sudo grubby --info=ALL | grep ^kernel
  4. List the kernels in the /boot directory.

    sudo ls -l /boot/vmlinuz*

    This command returns a list of kernels available on the system. However, because kernels are named differently, the kernel version that the system currently uses is not easily identifiable.

  5. Obtain more detailed information about the currently active kernel.

    sudo grubby --info "/boot/vmlinuz-$(uname -r)"

    The output includes more detailed information about the boot configuration associated with each kernel in the system's /boot directory, such as the boot index number, startup arguments, boot entry id, etc.

Confirm Details of the Default Kernel

  1. Check which kernel is the default kernel used at boot.

    sudo grubby --default-kernel

    Notice that the output includes the path to the default kernel.

  2. Check which kernel is currently running on a system.

    sudo uname -r

    If the default kernel and the currently running kernel are not identical, the underlying reasons might be one of the following:

    • You installed a newer kernel, but you have not rebooted the system
    • During a system reboot, you selected an alternative kernel manually to be the operative kernel
    • You manually updated the default kernel but have not rebooted the system after the update
  3. Check the title of the default kernel.

    sudo grubby --default-title

    This output matches the value seen in the GRUB2 menu when starting Oracle Linux Server.

  4. Get the index number for all of the currently installed kernels.

    sudo grubby --info=ALL | grep -E "^kernel|^index"
  5. Return the default kernel's index number.

    sudo grubby --default-index

    The index number returned should match the value returned in the previous command.

Alter the Default Kernel

  1. Switch to a different default kernel, specifying the full path to the designated kernel.

    sudo grubby --set-default $(ls -al /boot/vmlinuz* | awk 'FNR == 2 { print $9 }')

    The change takes effect immediately and persists across system reboots.

    Note: Make sure you specify the full path to the designated default kernel

  2. Set the default kernel by its boot entry number.

    sudo grubby --set-default-index=0

    Refer to the man grubby manual page for more information regarding additional boot arguments for configuring kernel and boot operations.

Change Kernel Command-Line Boot Parameters

Use the --update-kernel option to update a kernel entry in combination with --args to add new arguments or --remove-args to remove existing arguments. You can specify multiple arguments for each option in a quoted space-separated list. You can add and remove arguments in the same operation.

To update a specific kernel, provide the --update-kernel option with the full path to the kernel you're updating. To update all kernel entries to use a specific kernel boot argument, you can set --update-kernel=ALL.

  1. Update the default kernel entries to change the loglevel and LANG arguments.

    sudo grubby --update-kernel=DEFAULT --args "loglevel=3,LANG=en_GB.UTF-8"

    Important: You should test any changes to kernel parameters on a specific kernel rather than using the --update-kernel=ALL switch to apply any change to all kernels on your system. Using this approach will make it easier to recover from any mistake.

  2. Check for the implemented change across kernels.

    sudo grubby --info=ALL | grep -E "LANG=en_GB.UTF-8|loglevel=3"
  3. Remove a kernel parameter.

    Suppose you modify any kernel parameters, and the system does not boot afterward. In that case, you can revert the changes by booting into a previous kernel via the GRUB menu presented during startup. After the system has started using the previous kernel, remove the parameters that caused the problem.

    It is also useful if you want to remove a parameter from a specific kernel for any reason.

    sudo grubby --remove-args="loglevel=3,LANG=en_GB.UTF-8" --update-kernel=DEFAULT
  4. Confirm the loglevel and LANG parameters are gone.

    sudo grubby --info=ALL | grep -E "LANG=en_GB.UTF-8|loglevel=3"

Next Steps

This tutorial introduced you to the grubby command, which can help you select which boot kernel to set as the default or how to configure extra command-line boot options for your Oracle Linux system. Check out the Oracle Linux documentation to learn more about using grubby to manage your system.

SSR