How to Install Linux Mainline Kernel on Rocky Linux

The Linux kernel is the foundation of every Rocky Linux system, managing hardware, memory, processes, and security. While Rocky Linux ships with a stable, enterprise-tested kernel, you may need features, hardware support, or security patches that have not yet been backported to the distribution kernel. The ELRepo project provides pre-built mainline kernel packages that give you access to the latest stable kernel from kernel.org without manual compilation.

This guide walks through setting up the ELRepo repository and installing the mainline kernel on Rocky Linux. You will learn how to import the repository, choose between kernel-ml (mainline) and kernel-lt (long-term support), install your chosen kernel, and verify the installation. By the end, you will have a newer kernel running alongside your stock kernel, with the ability to switch between them at boot time.

These instructions apply to Rocky Linux 8, 9, and 10. The main difference is that Rocky Linux 10 only offers kernel-ml (mainline), while Rocky 8 and 9 also provide kernel-lt (long-term support). Commands work identically across all three versions unless noted otherwise.

Compare ELRepo Kernel Options

ELRepo provides two kernel branches, each suited to different use cases. Understanding the difference helps you choose the right kernel for your environment.

Kernel OptionBranch TypeStabilityRocky 8Rocky 9Rocky 10Best For
kernel-mlMainline stableLatest features, newer driversYesYesYesNewest hardware, latest features, developers
kernel-ltLong-term supportConservative updates, extended maintenanceYes (5.4.x)Yes (6.1.x)NoProduction servers, stability-focused environments
Stock kernelRHEL-basedEnterprise-tested, vendor-patchedYesYesYesMost users who do not need newer features

For most users seeking newer kernel features, kernel-ml is the recommended choice because it tracks the latest stable release from kernel.org. If you prefer a more conservative upgrade path with longer maintenance cycles, kernel-lt provides a middle ground between the stock kernel and bleeding-edge releases. Note that Rocky Linux 10 users can only install kernel-ml since ELRepo does not offer kernel-lt for EL10.

Update Rocky Linux Before Kernel Installation

Before installing a new kernel, update your existing packages to ensure compatibility and reduce the risk of dependency conflicts. This step also refreshes your package metadata so DNF knows about the latest available versions.

sudo dnf upgrade --refresh

If this command installs a kernel update, reboot before proceeding so your running kernel matches your installed packages. This prevents potential version mismatches during the ELRepo kernel installation.

Import the ELRepo Repository

ELRepo provides kernel packages that are not included in Rocky Linux’s default repositories. To install kernels using DNF, you must first import the ELRepo GPG key and then add the repository to your system.

Import the ELRepo GPG Key

The GPG key verifies that packages you download actually come from ELRepo and have not been tampered with. Import the key with the following command:

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

This command produces no output on success. To confirm RPM imported the key, check the database:

rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE} %{SUMMARY}\n' | grep -i elrepo

You should see output similar to:

gpg-pubkey-baadae52-6540544e gpg(elrepo.org (RPM Signing Key for elrepo.org) <secure@elrepo.org>)

Install the ELRepo Release Package

After importing the GPG key, install the ELRepo release package for your Rocky Linux version. This package configures the repository files in /etc/yum.repos.d/ so DNF can find ELRepo packages.

Version 10:

sudo dnf install https://www.elrepo.org/elrepo-release-10.el10.elrepo.noarch.rpm -y

On version 9:

sudo dnf install https://www.elrepo.org/elrepo-release-9.el9.elrepo.noarch.rpm -y

Running version 8:

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

Verify Available Kernels

Once you install the repository, verify the setup succeeded by listing the available kernel packages. This confirms DNF can reach ELRepo and shows you which kernel versions are currently available.

dnf list available --disablerepo='*' --enablerepo=elrepo-kernel | grep -E '^kernel-(ml|lt)\.'

On Rocky Linux 9, you should see both kernel-ml and kernel-lt packages:

kernel-lt.x86_64                        6.1.159-1.el9.elrepo       elrepo-kernel
kernel-ml.x86_64                        6.18.3-1.el9.elrepo        elrepo-kernel

For Rocky Linux 10, only kernel-ml appears because ELRepo does not provide kernel-lt for EL10:

kernel-ml.x86_64                        6.18.3-1.el10.elrepo       elrepo-kernel

The version numbers shown above reflect the packages available at the time of writing. ELRepo updates kernel-ml frequently as new stable kernels are released, so you will likely see different version numbers when you run this command.

Install the Mainline Kernel

With ELRepo configured, you can now install the mainline kernel. The installation process adds the new kernel alongside your existing stock kernel, so you can switch between them at boot time if needed.

Install kernel-ml (Mainline)

This package provides the latest stable kernel from the mainline branch. Install it with:

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

The --enablerepo=elrepo-kernel flag temporarily enables the ELRepo kernel repository for this transaction. This flag is necessary because ELRepo disables the kernel repository by default to prevent accidental kernel upgrades during routine system updates.

Install Additional Kernel Packages (Optional)

If you need to compile kernel modules or build software that requires kernel headers, install the additional development packages. This is common for users building NVIDIA drivers on Rocky Linux, VirtualBox guest additions, or custom kernel modules. For background on kernel headers and development packages, see the related guide.

sudo dnf --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml-headers -y

You can also install extra modules and tools if you need them:

sudo dnf --enablerepo=elrepo-kernel install kernel-ml-modules-extra kernel-ml-tools -y

Only install kernel-ml-devel and kernel-ml-headers if you actually need them. Most desktop users running prebuilt software do not require these packages. If you later need to compile a module and see errors about missing kernel headers, you can install them at that time.

Alternative: Install kernel-lt (Long-Term Support)

If you prefer a long-term support kernel over the latest mainline release, install kernel-lt instead. This option is only available on Rocky Linux 8 and 9.

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

The kernel-lt branch receives security patches and bug fixes for an extended period but does not include the newest features found in kernel-ml. Choose kernel-lt if your priority is stability over features.

Reboot and Select the New Kernel

After installation, you must reboot to load the new kernel. The kernel runs at the lowest level of the operating system, so changes require a full system restart.

sudo reboot

During boot, the GRUB menu appears briefly. Rocky Linux typically sets the newest kernel as the default, so the mainline kernel should boot automatically. If it does not, select it manually from the GRUB menu.

After the system boots, verify the running kernel:

uname -r

This output shows the kernel version. For Rocky Linux 10 with kernel-ml, you should see something like:

6.18.3-1.el10.elrepo.x86_64

For more detailed system information including the kernel version, hostname, and architecture:

uname -a
Linux rocky10 6.18.3-1.el10.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan  2 11:45:22 EST 2026 x86_64 x86_64 x86_64 GNU/Linux

Set the Default Boot Kernel

Rocky Linux typically boots the most recently installed kernel by default. However, you may want to explicitly set which kernel boots automatically or verify the current configuration.

Check the Current Default Kernel

Use grubby to see which kernel is set as the default:

sudo grubby --default-kernel

This command outputs the path to the default kernel, for example:

/boot/vmlinuz-6.18.3-1.el10.elrepo.x86_64

List All Installed Kernels

To see all kernels available for booting:

sudo grubby --info=ALL | grep -E '^(index|kernel|title)'

Example output showing both mainline and stock kernels:

index=0
kernel="/boot/vmlinuz-6.18.3-1.el10.elrepo.x86_64"
title="Rocky Linux (6.18.3-1.el10.elrepo.x86_64) 10.1 (Red Quartz)"
index=1
kernel="/boot/vmlinuz-6.12.0-124.21.1.el10_1.x86_64"
title="Rocky Linux (6.12.0-124.21.1.el10_1.x86_64) 10.1 (Red Quartz)"

Change the Default Kernel

If you want to boot a specific kernel by default, set it using the kernel path or index number:

sudo grubby --set-default /boot/vmlinuz-6.18.3-1.el10.elrepo.x86_64

Alternatively, use the index number from the list above:

sudo grubby --set-default-index=0

Update the Mainline Kernel

ELRepo updates kernel-ml packages when new stable kernels are released. To check for and install kernel updates, run your regular system upgrade command:

sudo dnf upgrade --refresh

Because the elrepo-kernel repository is disabled by default, kernel-ml updates will not appear unless you explicitly enable the repository. To include ELRepo kernels in your upgrade check:

sudo dnf --enablerepo=elrepo-kernel upgrade

After any kernel update, reboot your system to load the new kernel. You can select which kernel to boot from the GRUB menu if you encounter issues with the updated version.

Restore the Stock Kernel

If the mainline kernel causes issues with your hardware or software, you can return to the stock Rocky Linux kernel. The stock kernel remains installed and available in GRUB, so you simply need to select it at boot time.

Boot the Stock Kernel from GRUB

Reboot your system and watch for the GRUB menu. Use the arrow keys to select the stock kernel entry (it will not have “elrepo” in the version string) and press Enter. Rocky Linux 10 uses the 6.12.x kernel series, Rocky Linux 9 uses 5.14.x, and Rocky Linux 8 uses 4.18.x by default.

After booting into the stock kernel, verify with:

uname -r

The output should show the stock kernel version without the “elrepo” suffix.

Set the Stock Kernel as Default

Once booted into the stock kernel, set it as the default if you want to stop using the mainline kernel:

sudo grubby --set-default /boot/vmlinuz-$(rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' kernel | head -1)

Remove the Mainline Kernel (Optional)

If you want to completely remove the mainline kernel packages, first ensure you have booted into the stock kernel. You cannot remove the currently running kernel.

Before removing kernel packages, confirm you are running the stock kernel by checking uname -r. Attempting to remove the running kernel will fail and may leave your system in an inconsistent state.

Remove the mainline kernel packages:

sudo dnf remove kernel-ml kernel-ml-core kernel-ml-modules

If you installed development packages, remove those as well:

sudo dnf remove kernel-ml-devel kernel-ml-headers

Disable or Remove the ELRepo Repository (Optional)

If you no longer want ELRepo on your system, you can disable it to prevent future installations or remove it entirely.

To disable the repository without removing it:

sudo dnf config-manager --set-disabled elrepo
sudo dnf config-manager --set-disabled elrepo-kernel

Verify the repository is disabled:

dnf repolist --all | grep elrepo
elrepo                           ELRepo.org Community Enterprise Linux Repositor disabled
elrepo-kernel                    ELRepo.org Community Enterprise Linux Kernel Re disabled

To completely remove ELRepo from your system:

sudo dnf remove elrepo-release

Troubleshooting

GPG Key Import Fails on Rocky Linux 10

Rocky Linux 10 uses stricter cryptographic policies that may reject the ELRepo GPG key with an error like:

error: Certificate 309BC305BAADAE52:
  Policy rejects 309BC305BAADAE52: Policy rejected asymmetric algorithm

If you encounter this error, you can install the ELRepo release package with GPG checking temporarily disabled:

sudo dnf install https://www.elrepo.org/elrepo-release-10.el10.elrepo.noarch.rpm -y --nogpgcheck

DNF will still verify package signatures during subsequent installations. This workaround only affects the initial repository package installation.

System Fails to Boot After Kernel Installation

If your system does not boot after installing the mainline kernel, the stock kernel remains available in GRUB. Follow these steps:

  1. Restart your system and watch for the GRUB menu (it may only display for a few seconds).
  2. Use the arrow keys to select the stock kernel entry (without “elrepo” in the name).
  3. Press Enter to boot the stock kernel.
  4. Once booted, set the stock kernel as default using grubby --set-default as described in the Restore section above.

NVIDIA or VirtualBox Modules Stop Working

Third-party kernel modules built against your previous kernel (NVIDIA drivers, VirtualBox, VMware) will not work with the new kernel until you rebuild them. DKMS-based modules should rebuild automatically, but you may need to reinstall proprietary drivers.

For NVIDIA drivers installed via ELRepo’s kmod packages, install the kernel-ml compatible versions:

sudo dnf --enablerepo=elrepo install kmod-nvidia

For VirtualBox or other DKMS-based modules, ensure you have the kernel-ml-devel package installed and then rebuild:

sudo dnf --enablerepo=elrepo-kernel install kernel-ml-devel
sudo dkms autoinstall

ELRepo Kernel Repository Shows No Packages

If dnf list available --enablerepo=elrepo-kernel returns no results, verify the repository is correctly configured:

dnf repolist --all | grep elrepo

A missing repository means you need to reinstall the ELRepo release package for your Rocky Linux version. When the output shows the repository as disabled, that is expected behavior; use --enablerepo=elrepo-kernel to access kernel packages.

DNF config-manager Command Not Found

The error “No such command: config-manager” indicates that the dnf-plugins-core package is missing. Minimal Rocky Linux 10 installations often lack this package:

sudo dnf install dnf-plugins-core -y

After installing, retry the config-manager command. Desktop installations typically include this package by default.

Conclusion

You now have the ELRepo mainline kernel installed on Rocky Linux, giving you access to the latest stable kernel features and hardware support. The stock kernel remains available in GRUB for fallback if needed, and you can optimize DNF for faster updates to streamline future kernel upgrades. Keep kernel-ml updated through regular dnf --enablerepo=elrepo-kernel upgrade commands to receive new features and security patches as they are released.

2 thoughts on “How to Install Linux Mainline Kernel on Rocky Linux”

  1. Nice. A few issues:
    1) using `–repo=elrepo-kernel` can be used as a shortcut for `–enablerepo=elrepo-kernel –disablerepo=”*”`
    2) The steps leave elrepo-kernel disabled as it is never explicitly enabled. So subsequent `dnf upgrade` comands will reinstall the 5.14 kernel again. You probably want to add the step `dnf config-manager –set-enabled=elrepo-kernel` to leave it enabled.
    3) The command to disable the kernel repo again uses “elrepo” and not “elrepo-kernel” as the reponame.

    Reply

Leave a Comment

Let us know you are human: