Learn how to remove old kernels in Linux 9 with our step-by-step guide. Free up disk space, streamline system performance, and enhance security by safely removing outdated kernel versions from your Linux system. #centlinux #linux #linuxkernel
Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU operating system, which was written to be a free (libre) replacement for Unix.
Since the late 1990s, it has been included as part of a large number of operating system distributions, many of which are commonly also called Linux.
Linux is provided under the GNU General Public License version 2 only, but it contains files under other compatible licenses.
Linux is deployed on a wide variety of computing systems, such as embedded devices, mobile devices (including its use in the Android operating system), personal computers, servers, mainframes, and supercomputers. It can be tailored for specific architectures and for several usage scenarios using a family of simple commands (that is, without the need of manually editing its source code before compilation); privileged users can also fine-tune kernel parameters at runtime.
Most of the Linux kernel code is written using the GNU extensions of GCC to the standard C programming language and with the use of architecture-specific instructions (ISA) in limited parts of the kernel. This produces a highly optimized executable (vmlinux) with respect to utilization of memory space and task execution times. (Source: Wikipedia)
Removing old Linux kernels can help in maintaining a clean and efficient system. Here are some reasons why removing old kernels might be beneficial:
Overall, removing old Linux kernels helps optimize disk space usage, improve system performance, enhance security, simplify maintenance, and streamline backup and restore processes. It is recommended to periodically review and remove old kernels to keep the system clean and efficient.
Recommended Online Training: Learn Bash Shell in Linux for Beginners
It is a very common practice to update Linux operating systems, periodically and especially at the time of installing a new software. On each installation of new Linux Kernel, the Yum keeps your previous Kernels intact and may keep maximum last 3 Kernels at a time. It is the default limit and you can customize it according to your requirement.
A typical GRUB menu with mutiple Linux Kernels may look like the following.
Continue reading this article to get rid of old Linux kernels and keep your GRUB boot menu tidy.
We are using a minimal Rocky Linux 9 virtual machine with following specifications.
By using a ssh client, Login to your Rocky Linux 9 server as root user.
Execute the following rpm command, to list the installed kernels in your Linux operating system.
# rpm -q kernel kernel-5.14.0-70.13.1.el9_0.x86_64 kernel-5.14.0-70.22.1.el9_0.x86_64 kernel-5.14.0-70.26.1.el9_0.x86_64
Usually the latest Linux Kernel should be active on your operating system. Unless someone has explicitly set an older version as default Linux kernel.
You can confirm it by executing following commands.
# uname -r 5.14.0-70.26.1.el9_0.x86_64 # grubby --default-kernel /boot/vmlinuz-5.14.0-70.26.1.el9_0.x86_64
If the above command returns a kernel other than the latest one, then you have to set the default kernel for GRUB.
List down the available Linux kernels in /boot directory.
# ls /boot/vm* /boot/vmlinuz-0-rescue-f118dcfb3b884e518d8d105671e2c0ea /boot/vmlinuz-5.14.0-70.13.1.el9_0.x86_64 /boot/vmlinuz-5.14.0-70.22.1.el9_0.x86_64 /boot/vmlinuz-5.14.0-70.26.1.el9_0.x86_64
Execute the following command to set a default kernel for GRUB.
# grubby --set-default /boot/vmlinuz-5.14.0-70.26.1.el9_0.x86_64 The default is /boot/loader/entries/f118dcfb3b884e518d8d105671e2c0ea-5.14.0-70.26.1.el9_0.x86_64.conf with index 0 and kernel /boot/vmlinuz-5.14.0-70.26.1.el9_0.x86_64
By default, Yum Package Manager installs Linux kernels separately, while keeping the old versions intact for fallback support.
This behavior can be controlled by two Yum Package Manager directives.
Check the current value of installonly_limit directive.
# grep limit /etc/dnf/dnf.conf installonly_limit=3
Execute following dnf command at Linux Bash prompt to remove the old versions of Linux kernels.
# dnf -y remove --oldinstallonly --setopt installonly_limit=2 kernel Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: kernel x86_64 5.14.0-70.13.1.el9_0 @minimal 0 kernel x86_64 5.14.0-70.22.1.el9_0 @baseos 0 kernel-core x86_64 5.14.0-70.13.1.el9_0 @minimal 73 M kernel-core x86_64 5.14.0-70.22.1.el9_0 @baseos 73 M kernel-modules x86_64 5.14.0-70.13.1.el9_0 @minimal 20 M kernel-modules x86_64 5.14.0-70.22.1.el9_0 @baseos 20 M Transaction Summary ================================================================================ Remove 6 Packages Freed space: 185 M Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Erasing : kernel-5.14.0-70.22.1.el9_0.x86_64 1/6 Running scriptlet: kernel-5.14.0-70.22.1.el9_0.x86_64 1/6 Erasing : kernel-5.14.0-70.13.1.el9_0.x86_64 2/6 Running scriptlet: kernel-5.14.0-70.13.1.el9_0.x86_64 2/6 Erasing : kernel-modules-5.14.0-70.13.1.el9_0.x86_64 3/6 Running scriptlet: kernel-modules-5.14.0-70.13.1.el9_0.x86_64 3/6 Erasing : kernel-modules-5.14.0-70.22.1.el9_0.x86_64 4/6 Running scriptlet: kernel-modules-5.14.0-70.22.1.el9_0.x86_64 4/6 Running scriptlet: kernel-core-5.14.0-70.22.1.el9_0.x86_64 5/6 Erasing : kernel-core-5.14.0-70.22.1.el9_0.x86_64 5/6 Running scriptlet: kernel-core-5.14.0-70.22.1.el9_0.x86_64 5/6 Running scriptlet: kernel-core-5.14.0-70.13.1.el9_0.x86_64 6/6 Erasing : kernel-core-5.14.0-70.13.1.el9_0.x86_64 6/6 Running scriptlet: kernel-core-5.14.0-70.13.1.el9_0.x86_64 6/6 Verifying : kernel-5.14.0-70.13.1.el9_0.x86_64 1/6 Verifying : kernel-5.14.0-70.22.1.el9_0.x86_64 2/6 Verifying : kernel-core-5.14.0-70.13.1.el9_0.x86_64 3/6 Verifying : kernel-core-5.14.0-70.22.1.el9_0.x86_64 4/6 Verifying : kernel-modules-5.14.0-70.13.1.el9_0.x86_64 5/6 Verifying : kernel-modules-5.14.0-70.22.1.el9_0.x86_64 6/6 Removed: kernel-5.14.0-70.13.1.el9_0.x86_64 kernel-5.14.0-70.22.1.el9_0.x86_64 kernel-core-5.14.0-70.13.1.el9_0.x86_64 kernel-core-5.14.0-70.22.1.el9_0.x86_64 kernel-modules-5.14.0-70.13.1.el9_0.x86_64 kernel-modules-5.14.0-70.22.1.el9_0.x86_64 Complete!
You may notice that, instead of altering the installonly_limit directive value in dnf.conf file, we are setting it at the runtime for current dnf command only.
Reboot your Linux operating system now.
# reboot
Check the GRUB boot menu, The old kernels has been removed from the list.
Congratulations on successfully learning how install Mainline Kernel on Rocky Linux 9! By upgrading to the latest kernel version, you’ve taken a significant step towards enhancing the performance, security, and compatibility of your system. Enjoy the benefits of the latest kernel updates and explore the new features and improvements they bring. Remember to periodically review and remove old kernels to maintain a clean and efficient system. Happy computing! If you face difficulty in understanding the above article than you should buy and read Practical Guide to Linux Commands, Editors, and Shell Programming (PAID LINK) by Mark Sobell & Matthew Helmke.
Puppy Linux is a fast, lightweight OS designed for speed and simplicity, perfect for old…
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
This website uses cookies.
View Comments
ith work cheyyunnilla do