{"id":5864,"date":"2016-05-06T18:54:45","date_gmt":"2016-05-06T18:54:45","guid":{"rendered":"http:\/\/ubuntuhandbook.org\/?p=5864"},"modified":"2016-05-06T18:54:45","modified_gmt":"2016-05-06T18:54:45","slug":"remove-old-kernels-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2016\/05\/remove-old-kernels-ubuntu-16-04\/","title":{"rendered":"How to Easily Remove Old Kernels in Ubuntu 16.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/03\/kernel-icon-tux.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/03\/kernel-icon-tux.png\" alt=\"Linux Kernel\" width=\"245\" height=\"250\" class=\"alignleft size-full wp-image-5727\" \/><\/a><\/p>\n<p>For LVM, encrypted, or limited-storage systems, you need to regularly remove old kernels to prevent your computer (\/boot partition) from running out of storage space.<\/p>\n<p>Removing old kernels is easy. You can do it manually, or set unattended-upgrades to do it automatically. For details, open terminal from App Launcher or via <b>Ctrl+Alt+T<\/b> shortcut keys, and follow the steps below:<\/p>\n<p><b>Remove Automatically Installed Kernels:<\/b><\/p>\n<p>1. To remove the kernels that were automatically installed via regular system updates, open terminal and run:<\/p>\n<pre style=\"border:none;\">sudo apt autoremove --purge<\/pre>\n<p>It will ask you to type in user password and then remove old kernels as well as other automatically installed packages that are no longer needed.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/autoremove.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/autoremove-600x114.jpg\" alt=\"autoremove\" width=\"600\" height=\"114\" class=\"aligncenter size-large wp-image-5865\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/autoremove-600x114.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/autoremove-450x85.jpg 450w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/autoremove.jpg 641w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>2. To enable automatic removing of old kernels:<br \/>\n<div class=\"arconix-box arconix-box-red\"><i class='fa fa-2x pull-left fa-exclamation-triangle'><\/i><div class=\"arconix-box-content\">Enable Kernel autoremoving may cause problems if your package management is broken, see <a href=\"https:\/\/bugs.launchpad.net\/ubuntu\/+source\/unattended-upgrades\/+bug\/1357093\" target=\"_blank\">this bug<\/a>.<\/div><\/div><\/p>\n<li>Run command to enable unattended upgrades. For Desktop Ubuntu 16.04, this is enabled by default.\n<pre style=\"border:none;\">sudo dpkg-reconfigure unattended-upgrades<\/pre>\n<\/li>\n<li>Edit the config file via command (first install gksu via <code>sudo apt install gksu<\/code>):\n<pre style=\"border:none;\">gksudo gedit \/etc\/apt\/apt.conf.d\/50unattended-upgrades<\/pre>\n<\/li>\n<p>When the file opens, uncomment the following line and change the value to true:<\/p>\n<p><code>\/\/Unattended-Upgrade::Remove-Unused-Dependencies \"false\";<\/code><\/p>\n<p>So it looks like:<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/automatic-remove.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/automatic-remove-600x309.jpg\" alt=\"automatic-remove\" width=\"600\" height=\"309\" class=\"aligncenter size-large wp-image-5866\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/automatic-remove-600x309.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/automatic-remove-450x232.jpg 450w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/automatic-remove.jpg 802w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><b>Remove Manually Installed Kernels:<\/b><\/p>\n<p>If you install latest kernels from <a href=\"http:\/\/kernel.ubuntu.com\/~kernel-ppa\/mainline\/\" target=\"_blank\">Kernel PPA<\/a>, or build your own kernels with patches, a &#8220;purge-old-kernels&#8221; script is the best and the easiest way to remove old kernels.<\/p>\n<p>1. The script is maintained in byobu package, so first install it via:<\/p>\n<pre style=\"border:none;\">sudo apt install byobu<\/pre>\n<p>2. Then run the script regularly to remove old kernels:<\/p>\n<pre style=\"border:none;\">sudo purge-old-kernels<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/purge-old-kernel-script.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/purge-old-kernel-script-600x245.jpg\" alt=\"purge-old-kernel-script\" width=\"600\" height=\"245\" class=\"aligncenter size-large wp-image-5867\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/purge-old-kernel-script-600x245.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/purge-old-kernel-script-450x183.jpg 450w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/05\/purge-old-kernel-script.jpg 827w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><b>Remove Old Kernels via DPKG<\/b><\/p>\n<p>If your \/boot partition has already full while doing an upgrade or package install, and <code>apt<\/code> <i>(the script above uses apt)<\/i> can&#8217;t remove packages due to broken dependency, here you can manually find out the old kernel packages and remove them via DPKG:<\/p>\n<p><b>1.<\/b> Run command to check out current kernel and DON&#8217;T REMOVE it:<\/p>\n<pre style=\"border:none;\">uname -r<\/pre>\n<p><b>2.<\/b> List all kernels excluding the current booted:<\/p>\n<pre style=\"border:none;\">dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)<\/pre>\n<p>Example output:<\/p>\n<pre style=\"background:none;\"><span style=\"color:red\">rc  linux-image-4.4.0-15-generic<\/span>               4.4.0-15.31                                         amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP\n<span style=\"color:red\">ii  linux-image-4.4.0-18-generic<\/span>               4.4.0-18.34                                         amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP\n<span style=\"color:red\">rc  linux-image-4.6.0-040600rc3-generic<\/span>        4.6.0-040600rc3.201604120934                        amd64        Linux kernel image for version 4.6.0 on 64 bit x86 SMP<\/pre>\n<p>There will be three status in the listed kernel images:<\/p>\n<ul>\n<li><b>rc<\/b>: means it has already been removed.<\/li>\n<li><b>ii<\/b>: means installed, eligible for removal.<\/li>\n<li><b>iU<\/b>: DON&#8217;T REMOVE. It means not installed, but queued for install in apt.<\/li>\n<\/ul>\n<p>3. Remove old kernel images in status <span style=\"color:red\">ii<\/span>, it&#8217;s &#8220;linux-image-4.4.0-18-generic&#8221; in the example above:<\/p>\n<pre style=\"border:None;\">sudo dpkg --purge <span style=\"color:red;\">linux-image-4.4.0-18-generic<\/span><\/pre>\n<p>If the command fails, remove the dependency packages that the output tells you via <code>sudo dpkg --purge PACKAGE<\/code>.<\/p>\n<p>And also try to remove the respective header and common header packages (Don&#8217;t worry if the command fails):<\/p>\n<pre style=\"border:None;\">sudo dpkg --purge <span style=\"color:red;\">linux-image-4.4.0-18<\/span>-header <span style=\"color:red;\">linux-image-4.4.0-18<\/span><\/pre>\n<p>Finally you may fix the apt broken dependency via command:<\/p>\n<pre style=\"border:None;\">sudo apt -f install<\/pre>","protected":false},"excerpt":{"rendered":"<p>For LVM, encrypted, or limited-storage systems, you need to regularly remove old kernels to prevent your computer (\/boot partition) from running out of storage space. Removing old kernels is easy. You can do it manually, or set unattended-upgrades to do it automatically. For details, open terminal from App Launcher or via Ctrl+Alt+T shortcut keys, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[515],"class_list":["post-5864","post","type-post","status-publish","format-standard","hentry","category-howtos","tag-remove-old-kernels-ubuntu"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/5864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=5864"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/5864\/revisions"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=5864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=5864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=5864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}