Issue
Updating Fedora is strange. Even after several updates, the old versions stick around and use up space on my computer. I'm on Fedora x39 now but want to get rid of the old ones. Any ideas on how to do that?"
I need a way to delete
the older kernel
in my OS.
Solution
What is the proper method to remove old kernels from a RHEL based system?
To answer in short
dnf remove --assumeyes --oldinstallonly --setopt installonly_limit=2 kernel
In example as an Ansible task
- name: Remove old kernel images
shell:
cmd: dnf remove --assumeyes --oldinstallonly --setopt installonly_limit=2 kernel
warn: false
register: kernel_removal
when: ansible_distribution == 'RedHat' and ansible_distribution_major_version | int > 7
failed_when: kernel_removal.rc != 0 and (kernel_removal.rc != 1 and "No old installonly packages found for removal" not in kernel_removal.stderr_lines)
as the respective Ansible Modules don't handle all of the options.
Further Reading, Background Information, Documentation
Fedora Forum
Red Hat Documentation
Other Stack Sites
- How to remove old kernel images from Debian derivates?
- How do I remove old kernel versions to clean up the boot menu?
Answered By - U880D Answer Checked By - Terry (WPSolving Volunteer)