Is your Linux system acting up after a recent kernel update? Experiencing hardware issues, driver conflicts, or system instability? Don’t panic! Rolling back to a previous, stable kernel is a straightforward process that can quickly restore your system’s functionality and stability. This comprehensive guide will walk you through every step of rolling back your Linux kernel using GRUB, the Grand Unified Bootloader, ensuring a smooth and successful recovery.
Why Roll Back Your Linux Kernel?
Kernel updates, while essential for security and feature improvements, can sometimes introduce unforeseen problems. These issues can manifest in various ways, including:
- Hardware Incompatibility: Newer kernels might break compatibility with older hardware, such as network cards or graphics cards.
- Driver Issues: Updates can cause driver conflicts, leading to system crashes or malfunctions.
- System Instability: Kernel updates can introduce bugs or regressions that lead to unexpected system behavior.
- Boot Failures: In some cases, a problematic kernel update can prevent your system from booting altogether.
Rolling back to a known-good kernel allows you to bypass these issues, restore your system to a working state, and give you time to troubleshoot the problem or wait for a fix from the kernel developers.
Booting Into a Previous Kernel Using GRUB
The first step in rolling back your kernel is accessing the GRUB boot menu. Here’s how:
Step 1: Accessing the GRUB Menu:
- Restart your computer. As the system boots, you’ll need to interrupt the normal boot process to access the GRUB menu.
- BIOS Systems: Press and hold the Shift key during the boot process.
- UEFI Systems: Repeatedly press the Esc key during the boot process.
- Hidden Menu: Some distributions hide the GRUB menu by default. If the above methods don’t work, you might need to press a specific key combination (e.g., Esc, Del, F2, F12) or consult your distribution’s documentation.
Step 2: Navigating to Advanced Options:
- Once in the GRUB menu, use your arrow keys to navigate.
- Look for an option labeled “Advanced options” or something similar, usually followed by the name of your Linux distribution (e.g., “Advanced options for Ubuntu,” “Advanced options for Fedora”).
- Press Enter to select this option.
Step 3: Selecting a Previous Kernel:
- The “Advanced options” menu will display a list of available kernel versions, including recovery modes.
- Use the arrow keys to choose the older, known-stable kernel you wish to boot into. Avoid recovery mode unless you specifically need it for troubleshooting.
- Press Enter to boot into the selected kernel.
Step 4: Verifying System Stability:
- After booting into the older kernel, carefully observe your system to ensure that the previous issues (e.g., driver problems, instability) are resolved. If your system behaves as expected, congratulations! You’ve successfully rolled back your kernel.
Setting the Default Kernel in GRUB
If the older kernel proves stable and solves your problems, you may want to make it the default kernel to ensure it boots automatically on subsequent restarts. Here’s how:
Step 1: Identify the Menu Entry:
You’ll need to find the correct entry number for the kernel in the GRUB menu. Open a terminal and run the following command:
sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub/grub.cfg
- This command lists all boot entries with a corresponding index number.
- Locate the index number for the older, stable kernel you want to use.
Step 2: Set the Default Kernel:
Use the following command, replacing <index-number>
with the index number you identified in Step 1:
sudo grub2-set-default <index-number>
Step 3: Update the GRUB Environment:
Confirm the default setting by running:
sudo grub2-editenv list
Step 4: Reboot and Verify:
- Reboot your system.
- GRUB should now automatically boot into the selected kernel.
Removing a Problematic Kernel (Optional)
Once you are certain that the older kernel works, you can optionally remove the problematic, newer kernel to free up disk space and prevent accidental booting into it. The removal process varies slightly depending on your Linux distribution:
On Debian, Ubuntu, and Derivatives:
Step 1: List Installed Kernel Images:
dpkg --list | grep linux-image
Step 2: Remove the Unwanted Kernel:
sudo apt remove linux-image-<version>
Replace <version>
with the exact version string from the previous list.
Step 3: Update GRUB:
sudo update-grub
On Fedora, CentOS, and RHEL:
Step 1: List Installed Kernels:
dnf list installed kernel
Step 2: Remove the Problematic Kernel:
1sudo dnf remove kernel-<version>
Step 3: Clean Up (Optional): If residual files remain in /boot, remove them manually, For example:
sudo rm /boot/vmlinuz-<version> /boot/initramfs-<version>.img
Step 4: Rebuild GRUB Configuration (If Necessary):
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Downgrading the Kernel Package (If Needed)
If you’ve removed the older kernel and need to reinstall it, or if the older kernel is missing, you can downgrade the kernel package.
Debian/Ubuntu-Based Systems:
Step 1: Search for Older Kernel Packages:
apt list --all-versions linux-image
Step 2: Install the Specific Older Kernel Package:
sudo apt install linux-image-<old-version>
sudo apt install linux-headers-<old-version>
(Install the matching headers if you use proprietary drivers).
Step 3: Update GRUB and Reboot:
Fedora/CentOS/RHEL Systems:
Step 1: Download Kernel RPMs: Download the required kernel RPMs from the official archives or trusted sources.
Step 2: Install the Downloaded RPMs:
sudo dnf install ./kernel-*.rpm
Step 3: Update GRUB and Reboot:
Arch Linux Systems:
Step 1: Use the Downgrade Script or Download: Use the downgrade AUR script or manually download the older kernel from the Arch Linux Archive.
Step 2: Install the Desired Kernel Version:
sudo pacman -U linux-<old-version>.pkg.tar.zst
Step 3: Prevent Automatic Upgrades:
Add the following line to /etc/pacman.conf
to prevent automatic upgrades:
IgnorePkg = linux linux-headers
Preventing Automatic Kernel Upgrades (Temporarily)
To prevent automatic kernel updates until the issue is resolved, you can temporarily disable them.
Debian/Ubuntu:
Create a file in /etc/apt/preferences.d/
specifying your desired kernel version with a high Pin-Priority
.
Fedora/CentOS:
Add exclude=kernel*
to /etc/dnf/dnf.conf
or /etc/yum.conf
.
Arch Linux:
Add IgnorePkg = linux linux-headers
to /etc/pacman.conf
.
Important: Remember to remove these restrictions when you’re ready to test new kernel updates.
Troubleshooting and Best Practices
- Mismatched Headers: Install matching kernel headers and modules when using proprietary drivers or virtualization tools.
- Live USB: Use a live USB to mount partitions, chroot into your installation, and repair kernel or GRUB settings if your system becomes unbootable.
- Fallback: Keep at least one additional working kernel.
- Backups: Back up important data before kernel changes.
- Documentation: Document each step to help with troubleshooting.
- Official Repositories: Use official repositories for kernel packages to minimize risks.
Conclusion
Rolling back a Linux kernel using GRUB is a critical skill for any Linux user or administrator. By following the steps outlined in this guide, you can quickly and effectively restore your system’s functionality after a problematic kernel update. Remember to always back up your data, document your actions, and take your time to ensure a smooth and successful rollback. This knowledge empowers you to maintain a stable and reliable Linux environment.

We do not support or promote any form of piracy, copyright infringement, or illegal use of software, video content, or digital resources.
Any mention of third-party sites, tools, or platforms is purely for informational purposes. It is the responsibility of each reader to comply with the laws in their country, as well as the terms of use of the services mentioned.
We strongly encourage the use of legal, open-source, or official solutions in a responsible manner.
Comments