{"id":12928,"date":"2019-03-29T03:10:26","date_gmt":"2019-03-29T03:10:26","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12928"},"modified":"2019-03-29T03:10:26","modified_gmt":"2019-03-29T03:10:26","slug":"how-to-delete-old-unused-kernels-in-centos-rhel-and-fedora","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-delete-old-unused-kernels-in-centos-rhel-and-fedora\/","title":{"rendered":"How to Delete Old Unused Kernels in CentOS, RHEL and Fedora"},"content":{"rendered":"<p>In this article, we will show how to remove old\/unused kernel images on\u00a0<strong>RHEL\/CentOS\/Fedora<\/strong>\u00a0systems. However, before you remove an old kernel, it is important to keep your kernel up to date; install the latest version in order to leverage new kernel functions and to protect your system from vulnerabilities that have been discovered in older versions.<\/p>\n<p>To install or upgrade to latest kernel version in\u00a0<strong>RHEL\/CentOS\/Fedora<\/strong>\u00a0systems, read this guide:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/install-upgrade-kernel-version-in-centos-7\/\" target=\"_blank\" rel=\"noopener\">How to Install or Upgrade to Latest Kernel Version in CentOS 7<\/a><\/li>\n<\/ol>\n<p><strong>Attention<\/strong>: On the contrary, is recommended to keep at least one or two old kernels to fall back to in case there is a problem with an update.<\/p>\n<p>To display the current version of Linux (kernel) running on your system, run this command.<\/p>\n<pre># uname -sr\r\n\r\n<strong>Linux 3.10.0-327.10.1.el7.x86_64<\/strong>\r\n<\/pre>\n<h4>List All Installed Kernels on System<\/h4>\n<p>You can list all kernel images installed on your system like this.<\/p>\n<pre># rpm -q kernel\r\n\r\n<strong>kernel-3.10.0-229.el7.x86_64\r\nkernel-3.10.0-229.14.1.el7.x86_64\r\nkernel-3.10.0-327.3.1.el7.x86_64\r\nkernel-3.10.0-327.10.1.el7.x86_64<\/strong>\r\n<\/pre>\n<h4>Removing Old\/Unused Kernels on CentOS\/RHEL<\/h4>\n<p>You need to install\u00a0<strong>yum-utils<\/strong>, which is an assortment of utilities that integrate with\u00a0<strong>yum<\/strong>\u00a0to make it more powerful and easier to use, by extending its original features in several different ways.<\/p>\n<pre># yum install yum-utils\r\n<\/pre>\n<p>One of these utilities is\u00a0<strong>package-cleanup<\/strong>\u00a0which 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.<\/p>\n<pre># package-cleanup --oldkernels --count=2\r\n<\/pre>\n<div class=\"code-label\">Removing Old Kernels<\/div>\n<pre>Loaded plugins: fastestmirror, langpacks, product-id, versionlock\r\n--&gt; Running transaction check\r\n---&gt; Package kernel.x86_64 0:3.10.0-229.el7 will be erased\r\n---&gt; Package kernel.x86_64 0:3.10.0-229.14.1.el7 will be erased\r\n---&gt; Package kernel-devel.x86_64 0:3.10.0-229.1.2.el7 will be erased\r\n---&gt; Package kernel-devel.x86_64 0:3.10.0-229.14.1.el7 will be erased\r\n--&gt; Finished Dependency Resolution\r\n\r\nDependencies Resolved\r\n\r\n===============================================================================================================================================================================================\r\n Package                                       Arch                                    Version                                                Repository                                  Size\r\n===============================================================================================================================================================================================\r\nRemoving:\r\n kernel                                        x86_64                                  3.10.0-229.el7                                         @anaconda                                  131 M\r\n kernel                                        x86_64                                  3.10.0-229.14.1.el7                                    @updates                                   131 M\r\n kernel-devel                                  x86_64                                  3.10.0-229.1.2.el7                                     @updates                                    32 M\r\n kernel-devel                                  x86_64                                  3.10.0-229.14.1.el7                                    @updates                                    32 M\r\n\r\nTransaction Summary\r\n===============================================================================================================================================================================================\r\nRemove  4 Packages\r\n\r\nInstalled size: 326 M\r\nIs this ok [y\/N]: y\r\nDownloading packages:\r\nRunning transaction check\r\nRunning transaction test\r\nTransaction test succeeded\r\nRunning transaction\r\n  Erasing    : kernel-devel.x86_64                            1\/4 \r\n  Erasing    : kernel.x86_64                                  2\/4 \r\n  Erasing    : kernel-devel.x86_64                            3\/4 \r\n  Erasing    : kernel.x86_64                                  4\/4 \r\nLoading mirror speeds from cached hostfile\r\n * base: centos.mirror.snu.edu.in\r\n * epel: repo.ugm.ac.id\r\n * extras: centos.mirror.snu.edu.in\r\n * rpmforge: kartolo.sby.datautama.net.id\r\n * updates: centos.mirror.snu.edu.in\r\n  Verifying  : kernel-3.10.0-229.el7.x86_64                   1\/4 \r\n  Verifying  : kernel-devel-3.10.0-229.14.1.el7.x86_64        2\/4 \r\n  Verifying  : kernel-3.10.0-229.14.1.el7.x86_64              3\/4 \r\n  Verifying  : kernel-devel-3.10.0-229.1.2.el7.x86_64         4\/4 \r\n\r\nRemoved:\r\n  kernel.x86_64 0:3.10.0-229.el7           kernel.x86_64 0:3.10.0-229.14.1.el7           kernel-devel.x86_64 0:3.10.0-229.1.2.el7           kernel-devel.x86_64 0:3.10.0-229.14.1.el7          \r\n\r\nComplete!\r\n<\/pre>\n<p><strong>Important<\/strong>: After running the above command, it will remove all old\/unused kernels and keep the current running and old latest kernel as backup.<\/p>\n<h4>Removing Old\/Unused Kernels on Fedora<\/h4>\n<p>Fedora now uses\u00a0<a href=\"https:\/\/www.tecmint.com\/dnf-commands-for-fedora-rpm-package-management\/\" target=\"_blank\" rel=\"noopener\">dnf package manager<\/a>, a new version of\u00a0<a href=\"https:\/\/www.tecmint.com\/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement\/\" target=\"_blank\" rel=\"noopener\">yum package manager<\/a>, so you need to use this command below to remove old kernels on Fedora.<\/p>\n<pre># dnf remove $(dnf repoquery --installonly --latest-limit 2 -q) \r\n<\/pre>\n<p>Another alternative way to remove old kernels automatically is setting the kernel limit in\u00a0<strong>yum.conf<\/strong>\u00a0file as shown.<\/p>\n<pre>installonly_limit=2\t\t#set kernel count\r\n<\/pre>\n<p>Save and close the file. The next time you run an update, only two kernels will be left on the system.<\/p>\n<p>You may also like to read these following related articles on Linux kernel.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/load-and-unload-kernel-modules-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Load and Unload Kernel Modules in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/upgrade-kernel-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">How to Upgrade Kernel to Latest Version in Ubuntu<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/change-modify-linux-kernel-runtime-parameters\/\" target=\"_blank\" rel=\"noopener\">How to Change Kernel Runtime Parameters in a Persistent and Non-Persistent Way<\/a><\/li>\n<\/ol>\n<p>In this article, we described how to remove old\/unused kernel images on RHEL\/CentOS\/Fedora systems. You can share any thoughts via the feedback from below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/delete-old-kernels-in-centos-rhel-and-fedora\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will show how to remove old\/unused kernel images on\u00a0RHEL\/CentOS\/Fedora\u00a0systems. However, before you remove an old kernel, it is important to keep your kernel up to date; install the latest version in order to leverage new kernel functions and to protect your system from vulnerabilities that have been discovered in older versions. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-delete-old-unused-kernels-in-centos-rhel-and-fedora\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Delete Old Unused Kernels in CentOS, RHEL and Fedora&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12928","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12928"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12928\/revisions"}],"predecessor-version":[{"id":12929,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12928\/revisions\/12929"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}