Upgrade Linux Kernel on AlmaLinux 8 with ELRepo | Easy Setup

Posted on

Upgrade Linux Kernel on AlmaLinux 8 with ELRepo | Easy Setup

Upgrade Linux Kernel on AlmaLinux 8 with ELRepo | Easy Setup

The Linux kernel is the core component of the Linux operating system. It manages the system’s resources and facilitates communication between hardware and software components. Critically, it also maintains the security of your system. In this tutorial, we’ll guide you through the process of upgrading the Linux kernel on AlmaLinux 8 using the ELRepo repository. This is a relatively straightforward method that provides access to newer kernel versions than those available in the default AlmaLinux repositories.

This article will demonstrate how to Upgrade Linux Kernel on AlmaLinux 8 via ELRepo. We will cover the step-by-step process, from checking your current kernel version to setting the newly installed kernel as the default boot option. Before you begin, ensure you are logged into your AlmaLinux 8 server as a non-root user with sudo privileges. If you need assistance with this, refer to a guide on initial server setup with AlmaLinux 8.

1. Check the Current Linux Kernel Version on AlmaLinux

First, determine your current kernel version. Open a terminal and execute the following command:

uname -msr

The output will resemble this:

**Output**
Linux 4.18.0-372.9.1.el8.x86_64 x86_64

This output indicates the kernel version currently running on your system. It is crucial to know the current version before proceeding with the upgrade. Next, update your AlmaLinux repository to ensure you have the latest package information. Run the following command:

sudo dnf -y update

2. Add ELRepo Repository on AlmaLinux 8

To Upgrade Linux Kernel on AlmaLinux 8, you’ll need to install the ELRepo repository. ELRepo provides access to a wider range of kernel versions, including the latest releases directly from kernel.org. Import the ELRepo GPG key using the following command:

sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Fix db5 error(-30969) from dbenv

Note: You might encounter a "db5 error(-30969) from dbenv->open: BDB0091 DB_VERSION_MISMATCH: Database environment version mismatch" error during the key import. If so, resolve it by running these commands:

# sudo dnf upgrade --refresh rpm glibc
# sudo rm /var/lib/rpm/.rpm.lock
# sudo dnf upgrade dnf

After resolving the potential error, rerun the import command. Once the key is successfully imported, install the ELRepo repository using the following command:

sudo dnf install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

A successful installation will produce output similar to the following:

[Image of successful ELRepo installation]

3. List Available Kernels on AlmaLinux 8

Now that ELRepo is installed, list the available kernels. This will allow you to see which kernel versions are available for installation. Use the following command:

sudo dnf list available --disablerepo='*' --enablerepo=elrepo-kernel

The output will display a list of available kernels.

[Image of available kernels in ELRepo]

Examine the right-hand column for the kernel version numbers (e.g., ‘5.4.220-1.e18.elrepo’). These represent the specific kernel versions you can install. In this example, the Linux 6 kernel is the latest mainline release.

4. Install the Latest Kernel on AlmaLinux 8

Now, you can install your desired kernel version. To install the latest mainline kernel on AlmaLinux 8, use the following command:

sudo dnf --enablerepo=elrepo-kernel install kernel-ml

The output should look similar to this:

**Output**
Installed:
  kernel-ml-6.0.5-1.el8.elrepo.x86_64
  kernel-ml-core-6.0.5-1.el8.elrepo.x86_64
  kernel-ml-modules-6.0.5-1.el8.elrepo.x86_64

Complete!

To install the latest stable kernel, use the following command:

sudo dnf --enablerepo=elrepo-kernel install kernel-lt

The output should be similar to this:

**Output**
Installed:
  kernel-lt-5.4.220-1.el8.elrepo.x86_64
  kernel-lt-core-5.4.220-1.el8.elrepo.x86_64
  kernel-lt-modules-5.4.220-1.el8.elrepo.x86_64

Complete!

5. Reboot and Choose the New Linux Kernel on AlmaLinux

After installation, reboot your server:

reboot

During the reboot process, you’ll encounter the GRUB boot menu. Use the arrow keys to select the newly installed Linux kernel and press Enter. The operating system should boot normally using the new kernel.

6. Set the Default Kernel Version on AlmaLinux 8

To make the newly installed kernel the default, modify the GRUB configuration. This ensures that the system boots into the new kernel automatically upon subsequent restarts. Navigate to /etc/default/ and open the grub file with a text editor:

sudo vi /etc/default/grub

Locate the line GRUB_DEFAULT=X and change it to GRUB_DEFAULT=0. This instructs the boot loader to select the first kernel in the list (typically the latest installed) as the default. Save the file.

Then, regenerate the kernel configuration using the following command:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

The output will confirm the configuration generation:

**Output**
Generating grub configuration file ...
done

Reboot the server one last time:

reboot

Verify that the boot loader now defaults to the new kernel. After the reboot, check the kernel version:

uname -msr

The output should now reflect the newly installed kernel:

**Output**
Linux 6.0.5-1.el8.elrepo.x86_64 x86_64

Conclusion

This guide provided a detailed walkthrough on how to Upgrade Linux Kernel on AlmaLinux 8 using the ELRepo repository. Upgrading your kernel improves system security, performance, hardware compatibility, and provides bug fixes and new features.

Now, let’s explore alternative approaches to achieving the same goal.

Alternative Solutions for Upgrading the Kernel on AlmaLinux 8

While ELRepo is a popular and relatively easy method, there are other ways to Upgrade Linux Kernel on AlmaLinux 8. These alternatives offer different trade-offs in terms of complexity, control, and potential risk.

1. Using kpatch for Live Kernel Patching

kpatch is a live patching technology that allows you to apply security patches to the Linux kernel without requiring a reboot. This is particularly useful in production environments where downtime needs to be minimized. While kpatch doesn’t directly upgrade the kernel to a newer version, it keeps the existing kernel secure and stable by applying patches on the fly.

Explanation:

kpatch works by injecting code into the running kernel to fix vulnerabilities. These patches are built from source code differences between the vulnerable kernel version and the patched version. Because the kernel isn’t fully replaced, a reboot is not needed.

How to use kpatch:

  1. Install kpatch utilities:

    sudo dnf install kpatch
  2. Generate a kpatch patch:

    • First, you need to have debuginfo packages installed that correspond to your kernel version. You can check this with rpm -qa | grep debuginfo. If you don’t have them, install them using sudo dnf debuginfo-install kernel-<your_kernel_version>.
    • Next, create a patch using kpatch-build. This command requires you to provide the sources for the vulnerable kernel and the patched kernel. This is a complex process.
  3. Load the kpatch patch:

    sudo kpatch load <your_patch_file.kp>
  4. Verify that the patch is loaded:

    sudo kpatch list

Caveats:

  • kpatch doesn’t upgrade the kernel; it only applies patches. Therefore, you won’t get new features or hardware support.
  • Setting up kpatch and generating patches can be complex and requires a good understanding of kernel internals.
  • Not all vulnerabilities can be patched with kpatch.

2. Building and Installing a Kernel from Source

Building the kernel from source offers the ultimate control over the kernel configuration and allows you to use the very latest (or even development) versions of the kernel. This method is significantly more complex than using ELRepo but can be beneficial for users who need specific kernel features or want to contribute to kernel development.

Explanation:

Building from source involves downloading the kernel source code from kernel.org, configuring it to match your system’s hardware and desired features, compiling the code, and installing the resulting kernel modules.

How to build and install a kernel from source:

  1. Download the kernel source code:

    wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.tar.xz
    tar -xvf linux-6.6.tar.xz
    cd linux-6.6
  2. Configure the kernel:

    • Copy your existing kernel configuration:

      cp /boot/config-$(uname -r) .config
    • Use a configuration tool to customize the kernel (optional):

      make menuconfig
  3. Compile the kernel:

    make -j $(nproc)
  4. Install the kernel modules:

    sudo make modules_install
  5. Install the kernel:

    sudo make install
  6. Update the bootloader:

    • This step varies depending on your bootloader. In most cases, the make install step will automatically update the bootloader. If not, you might need to manually edit your bootloader configuration file (/boot/grub2/grub.cfg or similar).
    • dracut --force will generally update the initramfs and Grub2 configuration automatically.

Caveats:

  • Building from source is a time-consuming process.
  • It requires significant technical expertise, including knowledge of kernel configuration and compilation.
  • Incorrect configuration can lead to an unbootable system.
  • You are responsible for manually applying security patches and updates.

While these alternative methods present different approaches to managing your kernel, ELRepo remains a practical and accessible solution for most users who want to Upgrade Linux Kernel on AlmaLinux 8. However, understanding the other options can be valuable for specific use cases or for those seeking a deeper understanding of the Linux kernel.