try:

dnf remove --oldinstallonly

you can modify /etc/dnf/dnf.conf line install_only_limit=x (where x=3 by default)

Answer from stuartah on Stack Exchange
🌐
Amazon Web Services
aws.amazon.com › premiumsupport › knowledge-center › revert-stable-kernel-ec2-reboot
Revert to a stable kernel after updates to an EC2 instance | AWS re:Post
January 2, 2026 - An update prevented my Amazon Elastic Compute Cloud (Amazon EC2) instance reboot. I want to revert to a stable kernel.
Discussions

Downgrade kernel version in Amazon linux 2

Resolved:

# yum -y install kernel-4.14.104-95.84.amzn2.x86_64

# grubby --set-default /boot/vmlinuz-4.14.104-95.84.amzn2.x86_64

To check that the setting took:

# grubby --default-kernel

Reboot

More on reddit.com
🌐 r/aws
1
6
April 4, 2019
How to remove old kernels?
$ dpkg -l "linux-image*" "linux-headers*" Will show you all installed kernels and their headers, then you can remove them like: $ sudo apt purge linux-image-6.12.2-amd64 But it's better to use $ sudo apt autoremove to remove all except for the last two. In rare cases there might be some leftovers that were not removed automatically. I use purge over remove because it is meant to delete remaining configuration files and not just the package. More on reddit.com
🌐 r/debian
30
26
December 17, 2024
removing 6.2 Linux kernel from grub/boot options
https://pve.proxmox.com/wiki/Host_Bootloader More on reddit.com
🌐 r/Proxmox
9
4
April 2, 2023
How to remove these old Kernels I'm no longer using on my Mint Cinnamon 21? I'm currently on 5.15.0-47-generic.
Mint's do that for you but It keep 2 old kernels for safety in case you can't boot with the new ones. More on reddit.com
🌐 r/linuxmint
17
46
September 22, 2022
🌐
AWS
docs.aws.amazon.com › amazon linux › user guide › updating al2023 › updating the linux kernel on al2023
Updating the Linux Kernel on AL2023 - Amazon Linux 2023
2 weeks ago - Update the Linux kernel to latest versions to benefit from new features and performance improvements.
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › how-to-uninstall-kernel-from-linux-remove-old-kernel-versions
How to Uninstall Kernel from Linux (Remove Old Kernel Versions) - GeeksforGeeks
July 23, 2025 - #!/bin/bash # Ensure the script ... --list | grep linux-image | awk '{print $2}' | grep -v "$current_kernel" | xargs sudo apt-get -y purge# Update the bootloaderecho "Updating GRUB..."sudo update-grubecho "Old kernels removed ...
🌐
Webnoidschools
webnoidschools.com › how-to-delete-old-unused-kernels-in-alma-linuxcentos-rhel
How to Delete Old Unused Kernels in Alma Linux,CentOS, RHEL -
February 25, 2025 - One of these utilities is package-cleanup which you can use to delete old kernel as shown below, the count flag is used to specify the number of kernels you want to leave on the system. # package-cleanup –oldkernels –count=2 · Lamp Setup In Ubuntu · Lamp Setup In Centos/Redhat · Lamp Setup In Amazon Linux ·
🌐
Reddit
reddit.com › r/aws › downgrade kernel version in amazon linux 2
r/aws on Reddit: Downgrade kernel version in Amazon linux 2
April 4, 2019 -

I've tried following the instructions here as I need to go back 1 version, from 106 to 104: https://www.thegeekdiary.com/centos-rhel-7-change-default-kernel-boot-with-old-kernel/

Doesn't seem to work. Is there a workaround? Or is there a way for me to redeploy an instance with an older version?

🌐
Bobcares
bobcares.com › blog › aws-ec2-revert-to-a-known-stable-kernel-how-to-do-it
AWS EC2 revert to a known stable kernel - How to do it
June 29, 2021 - To replace the corrupt kernel with the stable kernel, you can use one of the following procedures: GRUB1 (Legacy GRUB) for Red Hat 6 and Amazon Linux
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
[SOLVED] Removing old kernels. - Linux Mint Forums
April 12, 2025 - There are non-GUI ways to do this, but they use multi-line scripts which don't go over well in these forums, IME. Also, if you want apt to actually change anything on the system, it has to be run with sudo. The shown apt autoremove will never do anything. No sudo. I'd be surprised if sudo apt ...
Find elsewhere
🌐
Blogger
amazonserver.blogspot.com › 2013 › 01 › cleanup-amazon-linux.html
Amazon Server: Cleanup Amazon Linux
January 19, 2013 - Disk usage after creation: $ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 932M 6.9G 12% / and after "sudo yum update": $ df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 978M 6.9G 13% / $ sudo du -sh /* 7.7M bin 25M boot 5.0M etc 28K home 58M lib 22M lib64 4.0K local 16K lost+found 4.0K media 4.0K mnt 56M opt 44K root 11M sbin 4.0K selinux 4.0K srv 12K tmp 534M usr 115M var Remove previous kernels Size of /boot/ directory depends on amount of previous versions of kernel in your system. Sometimes "yum update" upgrades the linux kernel and size of /boot directory incrementally increases. It is possible to remove old kernels from the file system (System.map-, config-, initramfs-, vmlinuz- files) and from the "/boot/grub/menu.lst" file
🌐
GitHub
github.com › bbbburns › remove-old-kernels
GitHub - bbbburns/remove-old-kernels: Interactively remove all of the old kernels from your AWS Ubuntu machine.
The intent of this small script is to find old Linux kernels and their installed packages and remove them using "dpkg".
Author   bbbburns
🌐
TecMint
tecmint.com › home › linux distros › centos › how to delete old unused kernels in centos, rhel and fedora
How to Delete Old Unused Kernels in CentOS, RHEL and Fedora
September 8, 2017 - In this article, we will explain how to safely remove old unused kernel images on CentOS, RHEL and Fedora systems. It is important to update kernel before removing.
🌐
nixCraft
cyberciti.biz › nixcraft › howto › ubuntu linux › ubuntu 18.04 deleting all unused old linux kernels
Ubuntu 18.04 remove all unused old kernels - nixCraft
April 9, 2024 - It is a part of the byobu package ... # keep at least 2 kernels # $ sudo purge-old-kernels --keep 2 · And there you have it. You successfully removed old kernel and header packages from the Ubuntu Linux system....
🌐
Artembutusov
artembutusov.com › how-to-rebuild-amazon-linux-kernel-in-amazon-linux
How to rebuild Amazon Linux kernel in Amazon Linux – Artem Butusov Blog
Keep in mind, if you use grub-mkconfig / grub2-mkconfig then your new kernel will be most likely the first that will be booted by grub because it should have higher kernel version number than other available kernels in /boot. If it is not true, then you can remove vmlinuz-* and initramfs-* kernel files for not used kernels and rerun grub-mkconfig / grub2-mkconfig to get your kernel record to be populated first in the menu for sure.
🌐
AWS re:Post
repost.aws › knowledge-center › amazon-linux-2-kernel-upgrade
Upgrade Amazon Linux 2 kernel version | AWS re:Post
August 13, 2024 - The following example shows that the old kernel is still active: [ec2-user@kernel-upgrade ~]$ uname -r 4.14.268-205.500.amzn2.x86_64 · To activate the latest installed kernel version, reboot the instance: ... Note: To upgrade the Amazon Linux 2 kernel from 5.10.x to Amazon Linux Extra 5.15.x, ...
🌐
Linux.org
linux.org › home › forums › general linux forums › general linux topics
Trying to remove old kernels - but receiving conflicting information. | Linux.org
July 29, 2024 - 2. I figured that I interpreted the command correctly, as the man page mentioned that the "remove --oldinstallonly" parameter would include the kernel version 5.14.0, as it is the oldest version: ************************************************* dnf [options] remove --oldinstallonly Removes ...
Top answer
1 of 16
653

16.04 and newer versions of Ubuntu

sudo apt autoremove

This command removes packages that were automatically installed to resolve a dependency, but are now no longer depended on. This includes old versions of linux-headers-* and linux-image-*. (It’s also smart about this process, leaving one spare version of the kernel around as a fallback!)

11.10 and newer versions of Ubuntu

GRUB2 and its display of all kernels

The latest versions of Grub2 installed in Ubuntu automatically display the latest kernel and hides the older kernels that you may have installed.

If you do not see your grub - then remember to press Shift whilst booting.

As you can see, only the latest kernel is displayed.

If you select the option shown (press Enter) then all the old kernels become visible and available to boot from.

How to permanently delete older kernels

First boot with the latest available kernel.

There are a number of ways to delete old kernels. Personally, I wouldn't touch Computer Janitor since this is acknowledged to break your computer with its suggestions.

synaptic

An alternative is Synaptic (sudo apt install synaptic)

search for linux-image, right-click a kernel and choose complete removal and finally click the Apply button to delete the kernel.

Repeat the search but this time for linux-header - you can delete the associated headers for the kernel image chosen previously.

Synaptic though will not attempt to verify what you are trying to remove... you could inadvertently delete your newest kernel - or even delete all of your kernels via this tool leaving you with an unbootable Ubuntu!.

Remember to check which kernel you are using type:

uname -r

The result would be similar to:

Remember the result and the number - make sure you don't delete the corresponding image or header.

Recommendation

My recommendation is to keep at least two or preferably three kernels including the latest. The reason for the recommendation is that you will have at least one/two other kernels to boot with, if for what-ever reason the latest kernel you are unable to boot with or introducing a regressed capability such as broken wireless.

2 of 16
432

First, reboot your System to be sure it is using the latest kernel. Then open terminal and check your current kernel:

uname -r 

DO NOT REMOVE THIS KERNEL!

Next, type the command below to view/list all installed kernels on your system.

dpkg --list 'linux-image-*'

Find all the kernels that lower than your current kernel. When you know which kernel to remove, continue below to remove it. Run the commands below to remove the kernel you selected.

sudo apt-get purge linux-image-x.x.x-x-generic 

Finally, run the commands below to update grub2

sudo update-grub2 

Reboot your system.

🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to remove old kernels on ubuntu
How to Remove Old Kernels on Ubuntu
December 17, 2025 - A common problem when keeping old kernels is having an extensive list of bootable images on the GRUB (boot) menu. This guide will help you remove old and unused Linux kernels on your Ubuntu system (20.04, 22.04, 24.04, and 26.04).
🌐
OSTechNix
ostechnix.com › home › linux › linux kernel › how to remove old unused linux kernels
How To Remove Old Unused Linux Kernels - OSTechNix
February 17, 2024 - A: You can use the command sudo dnf remove --oldinstallonly --setopt installonly_limit=2 kernel to remove all but the 2 most recent versions of the kernel. Please note that this command only works if the latest kernel is active.