Reclaiming disk space, maintaining a clutter-free system, and ensuring that only the most stable kernel versions remain can significantly enhance your Fedora experience. This guide presents a detailed and unique perspective on the reasons and methods for removing old kernels, detailed instructions for various removal methods, and all the best practices needed to safeguard your system’s stability. By the end of this article, you’ll be able to confidently manage Fedora kernels and keep your system lean, efficient, and secure.
What is Fedora and How to do Kernel Management
Fedora is a widely respected Linux distribution sponsored by Red Hat. Celebrated for its groundbreaking features and unwavering commitment to open-source principles, Fedora provides a rich environment for developers, sysadmins, and enthusiasts. At the heart of every Linux system lies the kernel, a core program that manages hardware interactions, memory allocation, and process scheduling. Over time, Fedora releases frequent kernel updates that Introduce new features, resolve bugs, and improve security measures.
Because Fedora updates frequently, multiple kernel versions can accumulate on your system. While older kernels are beneficial for fallback purposes if newer versions introduce unforeseen issues, too many old kernels can clutter your system and gobble up precious space—especially if you have a separate, relatively small /boot partition. This guide will explain why removing old kernels might be beneficial, how to do it safely, and what best practices to follow to keep your Fedora system healthy.
Why You Might Want to Remove Old Kernels
Removing old kernels on Fedora can be a prudent step in system maintenance. Here are some key reasons you might consider doing so:
- Disk Space Constraints
Many Fedora installations use a dedicated /boot partition of limited size. Storing multiple old kernels can quickly exhaust the available space, leading to errors when installing new kernels or performing updates. - System Clutter
Having too many kernel entries in your GRUB boot menu can confuse you. If you reboot frequently or share the system with others, navigating a lengthy list of kernel versions can be cumbersome. - Rarely Used Kernels
Most users run the latest kernel, especially if it’s stable. Older kernels can go unused for months, taking up space that could be better utilized. - Potential Security Risks
Older kernels may lack the most recent security patches. Booting into an older kernel could expose your system to known vulnerabilities. - System Maintenance and Housekeeping
Regularly cleaning up software you no longer need—including older kernels—helps maintain a streamlined operating system, reduces confusion, and mitigates conflicts.
Removing kernels you no longer use optimizes your Fedora system regarding disk space and potential security.
Understanding Kernel Versions in Fedora
Fedora typically uses a naming convention for kernel packages that look like kernel-6.0.11-300.fc36.x86_64. This nomenclature shows:
- The main kernel version (for example, 6.0.11).
- The Fedora release identifier (for instance, fc36).
- The system architecture (x86_64 for 64-bit systems).
When a new kernel is released, Fedora automatically installs it alongside existing kernels rather than replacing them outright. The default behavior is to keep a certain number of kernels, often three, though your system might differ if you have customized DNF settings. Over time, repeated updates can lead to multiple versions accumulating.
A typical kernel installation includes several components:
- Main kernel image (vmlinuz).
- Initramfs (initial RAM filesystem) are used during the early stages of the boot process.
- Kernel modules, which provide hardware and subsystem support.
When you install a new kernel through Fedora’s package manager, the GRUB bootloader configuration is automatically updated to list the latest version among your boot options. Consequently, these packages must be removed carefully to keep your system bootable and stable.
Preparing Your System for Kernel Removal
Before removing any kernels, make sure you follow these preparatory steps:
- Back-Up Important Data
Although removing kernels rarely affects user data, any significant system change carries risk. To keep your important files safe, back up your home directory with rsync, tar, or a specialized backup utility. - Ensure You Have Internet Connectivity
If something goes wrong, the most straightforward recovery often involves reinstalling necessary packages from the Fedora repositories. A working internet connection will be crucial for this. - Know Your Recovery Options
Familiarize yourself with how to enter rescue mode or use a Fedora live USB to restore your system if the boot process fails after kernel removal. - Check GRUB Configuration
Although Fedora usually updates GRUB automatically, it’s a good idea to verify your configuration (often in /boot/grub2/grub.cfg for BIOS systems or /boot/efi/EFI/fedora/grub.cfg for UEFI). Also, consider backing up this configuration file. - Update Your System
Run sudo dnf update to ensure all packages, including the kernel and related modules, are up to date. It’s safer to perform maintenance on a fully updated system.
Following these precautions dramatically reduces the likelihood of encountering critical issues.
Checking Your Current Kernel and Installed Kernels
You need to identify which kernel you are currently running and which kernel versions are installed before you begin removing anything.
Check the Running Kernel
uname -r
- This command will display something like 6.0.11-300.fc36.x86_64, indicating the kernel version in use at that moment.
List All Installed Kernel Packages
dnf list installed kernel
or
rpm -q kernel
- These commands will show every kernel package on your system, including version numbers.
Comparing the kernel you’re currently running (from uname -r) with the list of installed kernels (from dnf list installed kernel or rpm -q kernel) helps you avoid deleting the active kernel. Keep at least one older kernel as a fallback, and never remove the currently running kernel.
Best Practices Before Removing Kernels
Some best practices can help you avoid common pitfalls:
- Leave a Fallback
Consider removing only the oldest one or two if you have three kernels installed. Keeping at least one fallback can save you if the newest kernel shows bugs or incompatibilities. - Test the Latest Kernel
Ensure your most recent kernel runs smoothly with all your hardware and software. If you haven’t encountered issues, you can safely retire older versions. - Check DNF Configuration
In /etc/dnf/dnf.conf, you might see a line like installonly_limit=3. This defines the number of kernels Fedora keeps by default. Adjusting this number can automate the number of old kernels remaining on your system. - Use Official Fedora Repositories
Rely on Fedora’s official repositories for kernel packages to ensure maximum compatibility and reliability. - Create System Snapshots
If your system uses Btrfs or LVM with snapshot capabilities, make a snapshot before any significant system modification. This allows you to revert if you encounter problems.
By following these strategies, kernel removal becomes significantly safer.
Method 1: Removing Kernels Using DNF
Using the DNF package manager is the most straightforward way to remove old kernels. It handles dependencies automatically and updates GRUB for you. Follow these steps:
- Identify the Kernel You Want to Remove
Check
dnf list installed kernelÂ
to find the exact version. For instance, you might see a line like kernel-6.0.11-300.fc36.x86_64.
Remove the Kernel
sudo dnf remove kernel-6.0.11-300.fc36.x86_64
- Replace the version number with the one you intend to remove. DNF will display a list of packages to be removed and ask for confirmation.
- Confirm the Removal
After confirming, DNF purges the kernel and its associated modules. - Verify
Run
dnf list installed kernelÂ
Again, this is to confirm that the kernel has been removed.
This method is reliable because DNF ensures no orphaned packages remain and that bootloader configuration is typically updated automatically.
Method 2: Removing Kernels Using Package Cleanup (DNF Utils)
If you have multiple old kernels and want a streamlined approach, Fedora’s dnf-utils package (or dnf-plugins-core) provides the package-cleanup command, which automates the process.
Install dnf-utils (If Needed)
sudo dnf install dnf-plugins-core
- Many modern Fedora installs come with this package by default but check to be sure.
List Old Kernels
sudo package-cleanup --oldkernels --count=2
- This shows which kernels would be removed if you keep only the newest two. Adjust the –count value as desired.
Remove Old Kernels Automatically
sudo package-cleanup --oldkernels --count=2 -y
- This command removes all but the two newest kernels without manually specifying each version.
The package-cleanup method is perfect for users who frequently want to ensure older kernels are removed in bulk.
Method 3: Manual Removal of Old Kernels
Manual removal involves deleting kernel files from /boot and /lib/modules/, then manually updating GRUB. This is risky and not recommended unless you deeply understand how the Linux boot process works.
- Locate Kernel Files
Files for a kernel version are typically in /boot with names like vmlinuz-<version> and initramfs-<version>.img. Kernel modules reside in /lib/modules/<version>.
Remove Kernel Files
For instance:
sudo rm /boot/vmlinuz-6.0.11-300.fc36.x86_64
sudo rm /boot/initramfs-6.0.11-300.fc36.x86_64.img
sudo rm -r /lib/modules/6.0.11-300.fc36.x86_64
- Always double-check these version numbers, and never remove the files for the kernel you are currently running.
Update GRUB
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
For UEFI systems:
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
Manual removal is more error-prone and can leave orphaned files or break the system if not done correctly. Whenever possible, stick to the more automated methods.
Method 4: Using Graphical Tools to Remove Kernels
GNOME Software, Fedora’s default GUI package manager, can also remove kernel packages:
- Open GNOME Software
Look for it in your applications menu. - Go to Installed Software
Switch to the Installed tab. You might need to search for “kernel” to see the entries for your installed kernels. - Remove Unwanted Kernels
Select the older kernels you want to uninstall. Enter your administrative password when prompted. - Reboot and Verify
Check the GRUB menu to ensure the kernel list reflects your changes.
While convenient, GNOME Software may not show as much detail or warnings as DNF. Many users prefer DNF for simplicity and transparency. However, if you choose a purely graphical approach, GNOME Software can work.
Ensuring Bootloader Updates and Verification
After removing kernels, verify that the bootloader has been updated:
- Check GRUB Configuration
Look in /boot/grub2/grub.cfg (BIOS) or /boot/efi/EFI/fedora/grub.cfg (UEFI) to confirm it lists only the kernels you kept.
Run grub2-mkconfig Manually
If you suspect GRUB didn’t update properly, use:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
or
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
For UEFI systems.
- Reboot
Check the GRUB menu during startup to confirm that only the expected kernel versions are listed.
Ensuring GRUB is accurate prevents unbootable scenarios and eliminates references to non-existent kernels.
Common Pitfalls and How to Avoid Them
Removing kernels is generally safe if approached correctly, but here are some pitfalls to watch out for:
- Removing the Active Kernel
Always check uname -r first to avoid accidentally removing the kernel you’re currently using.
- Being Too Aggressive
Keep at least one fallback kernel. Removing all but the newest kernel can be risky if the latest one has undiscovered issues. - Forgetting to Update GRUB
Fedora handles this automatically, but manual verification ensures no stale GRUB entries linger. - Not Keeping Backups
Always have a backup strategy, especially if you make significant system-level changes. - Dependency Issues
Some third-party modules or custom drivers rely on specific kernel versions. Verify those dependencies before you remove any kernel.
Adhering to best practices helps avoid disruptions and ensures a stable system.
How Many Kernels Should You Keep?
The correct number of kernels to keep varies by user and environment:
- Minimal Approach
Keep two kernels: the last one and a backup plan. This is normal for desktop users who wish to free up more space on the disk. - Moderate Approach
Keep three or four kernels, ensuring multiple fallback options in case of regressions. - Conservative Approach
Keep five or more kernels, often for servers or specialized systems requiring broad fallback flexibility.
Fedora’s default installonly_limit=3 is a good starting point for most desktop users, providing enough flexibility without too much clutter.
Automating Kernel Cleanup
Manually removing old kernels each time an update arrives can be tedious. Here are ways to automate cleanup:
Configure dnf.conf
In /etc/dnf/dnf.conf, look for:
installonly_limit=3
- Adjust this number to define how many kernels you want to retain. Whenever a new kernel is installed, DNF automatically prunes the oldest.
Cron Jobs or Systemd Timers
If you want more control, schedule a recurring command:
sudo package-cleanup --oldkernels --count=3 -y
This can run weekly or monthly as needed.
- Third-Party Tools
Some system maintenance utilities can also manage kernel cleaning. Before using third-party solutions, always check compatibility with Fedora’s package management.
Automation saves time and ensures your system’s/boot partition doesn’t fill up unexpectedly.
Troubleshooting Kernel Removal Issues
Even with care, issues might arise:
- The system Fails to Boot
This usually indicates the active kernel was removed or GRUB was corrupted. Boot from an older kernel if it’s still listed, or use a Fedora live USB to chroot into your system and reinstall a kernel. - Missing Kernel Modules
Custom modules can break if you remove a kernel tied to them. Reinstall or recompile the modules for the kernel you plan to use. - Space Not Freed in /boot.
Some leftover files may still reside in /boot or /lib/modules/. Double-check those directories and manually remove any stragglers. - Error Messages in GNOME Software or DNF
Occasionally, partial removals or broken dependencies can cause errors. Run sudo dnf to clean everything and retry. You can also investigate with dnf history to see what happened.
Keeping a Fedora live USB handy is a lifesaver for quickly fixing a broken system after kernel or package removals.
Restoring a Removed Kernel (If Necessary)
Sometimes, you may need an older kernel that you removed. Reinstalling it is often possible if it’s still in the Fedora repositories:
Search the Kernel Package
sudo dnf search kernel | grep <version>
- Replace <version> with the specific version number (6.0.11-300.fc36.x86_64).
Install the Kernel
sudo dnf install kernel-6.0.11-300.fc36.x86_64
- If the package is still available, DNF will download and install it, along with any missing components.
Update GRUB
Re-run:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Or the appropriate command for your boot setup.
- Reboot
After reboot, the reinstalled kernel should be visible in your GRUB menu.
Older kernels might be removed from official repositories if they’re no longer maintained. In such cases, you may need to track down the RPM package from an archive or trusted third-party resource.
Kernel Removal in Fedora Cloud or Minimal Installs
Some Fedora environments, such as cloud images or minimal installations, handle kernel management a bit differently:
- Limited Disk Space
In cloud-based VMs, disk space can be minimal. Frequent kernel updates quickly fill partitions, making automated cleanup crucial. - Automated Tools
Some cloud platforms supply automation scripts or rely on ephemeral images where persistent kernel management isn’t necessary. - Minimal Installs
Without GUI tools, you rely solely on the command line (DNF or package cleanup). This approach is typically sufficient, given that minimal installs aim to reduce bloat.
No matter the environment, the fundamental principle remains the same: keep only the kernels you need, ensuring a fallback for safety.
Security Considerations
Removing old kernels is often a security-enhancing step because it reduces the chance of booting into vulnerable versions. Still, keep these points in mind:
- Always Stay Updated
The newest kernel usually includes vital security patches. If you encounter any issues with the latest kernel, address them promptly. - Secure Boot
If Secure Boot is enabled, newly installed or custom-compiled kernels may need to be signed. Removing older signed kernels without having a properly signed replacement could lead to boot failures. - Compliance Requirements
Various older kernels may be required to be kept in an enterprise or security-related environment to help with audits or even forensics. There is a fine line between data compliance and system cleanliness maintenance.
By incorporating these factors, you ensure that cleaning old kernels does not disrupt your system or organization’s security levels.
Performance and Stability After Kernel Removal
Removing old kernels generally improves system health by preventing confusion and freeing disk space. Direct performance gains may be minimal, but the indirect benefits include:
- Faster Package Operations
Fewer kernels mean fewer packages for DNF to process during system updates or upgrades. - Reduced Boot Confusion
A concise GRUB menu helps you boot into the correct kernel quickly and reduces the likelihood of accidentally using an outdated version. - Less Disk I/O
A smaller /boot partition with fewer files can marginally reduce read times, although these improvements are generally negligible.
Kernel removal enhances system cleanliness, often correlating with better user experience and more straightforward maintenance.
Conclusion
Proper kernel management is one crucial task in operating system stability. Since Fedora runs several updates regularly, it is not unusual to find several kernel images installed over time. It is good to have some extra kernels for a contingency, but if you have too many, you will find yourself storing and managing unnecessary disks. This tutorial will help you remove unnecessary kernels, which save disk space, declutter your GRUB menu, and reduce security vulnerabilities.
Key takeaways for removing kernels in Fedora include:
- Always verify which kernel you’re currently running with uname -r.
- Keep at least one fallback kernel to safeguard against regressions.
- Use DNF or package cleanup to automatically handle dependencies and clean up unneeded packages.
- Confirm that GRUB is updated so that only valid kernels are listed.
- Consider automating kernel removal with installonly_limit in /etc/dnf/dnf.conf or via scheduled cleanup scripts.
Deploying all these strategies will keep a Fedora system lean and flexible whilst strengthening your security posture and eliminating older, more vulnerable kernels from your machine. Whether you installed Fedora on your workstation server or are using it in cloud capability, observing these steps makes the Linux environment work better.
Remember always to keep backups of critical data and have a Fedora live USB on standby if you need to repair or restore a kernel. Once you become comfortable removing older kernels and keeping only the best and most stable versions, you’ll be well-equipped to tackle other aspects of Fedora administration with confidence and ease.
About the writer
Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.