How to remove old unused kernels on Fedora/Linux

You can use the following command to remove old kernels.
## dnf repoquery set negative --latest-limit ##
## as how many old kernels you want keep ##
dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
Step 1. Be sure you are notrunning the kernel you plan on removing:
Type uname -r in terminal and it will display the current kernel using by your system.
Or You can use the uname -a in terminal to check what kernel is currently used by your server:



Step 2. Then, decide which kernel you want to delete:
Open the terminal and type sudo dnf list installed kernel or you can use dnf list installed “kernel-*”. It will list all the kernels on the system.



Step 3. Remove old kernels manually
Type this command sudo yum remove <KERNEL NAME> in terminal and then type the kernel version do you want to delete.



Step 4. you can delete the old unused kernel automatically by using this command.
package-cleanup --oldkernels –count=1
5. You can check that old kernel is deleted or not by using this command.
dnf list installed “kernel-*”
It will display the list of kernel on your system after deleting the old one.