picto_welcome.png  Welcome   

picto_download.png  Get Lubuntu   

picto_help.png  Documentation   

picto_contact.png  Get Help   


Due to Bug #1357093, the start up list (GRUB) becomes longer over time as new kernels are added. Never remove your current kernel, else your computer will not boot up. It is also generally advised to keep the most recent previous version in case you discover problems with your current kernel.

Changing the kernel-containing packages on your system requires commands with root access, so please do read RootSudo.

LVM installs and encrypted installs use a small separate /boot partition. The small partition is capable of holding only four or five kernels, and fills to capacity quickly. Regular maintenance is vital to prevent breaking your package manager.

Regular Maintenance

Removing old kernels is easy to do on a properly-operating system. You can do it manually, or set unattended-upgrades to do it automatically. If you are receiving package management errors, regular maintenance may not work until the problem is fixed. See Problems below.

Manual Maintenance

If your system is operating without error, you should be able to remove old kernels with a simple autoremove command, available using Synaptic or the shell:

sudo apt-get autoremove

The system keeps track of which kernels are older and marks them eligible for removal using this method. Most users should run autoremove every few months or so. Systems with a separate /boot partition should run autoremove every two-four weeks. Mark your calendar, make it a routine. Autoremove can be run as often as you like - running it more often will not harm your system. The automated method below runs autoremove every day.

Automatic Maintenance

The unattended-upgrades package, included with the default install of all Ubuntu flavors, includes a setting to run autoremove automatically. Enabling this setting is a two-step process.

The first step is to enable unattended-upgrades. You can do this using the GUI or the shell:

GUI

Enable unattended upgrades using System Settings --> Software & Updates --> Updates Tab. Check the box for *-security (and/or any other repositories you wish) Automatically check for updates: Set to any frequency (except 'Never') When there are security updates: Set to Download and Install Automatically

Shell

sudo dpkg-reconfigure unattended-upgrades

The second step is to edit the file ls /etc/apt/apt.conf.d/50unattended-upgrades to enable completely automatic autoremove. It's owned by root, so remember to use sudo! Locate the line:

//Unattended-Upgrade::Remove-Unused-Dependencies "false";

Uncomment the line AND change the value to "true"

Problems

If your package management is broken, or if regular maintenance above is not working, any of several problems may have occurred. You may be out of storage space, or you may have a package version mismatch, or you may have another problem.

Safely removing old kernels

For users of LVM systems, encrypted systems or limited-storage systems, the most frequent problem is that the /boot partition is simply full. The package manager cannot install a pending upgrade due to lack of space.

This problem can be fixed quickly and easily from the shell. Simply identify one or two old kernels to remove manually, which will provide the package manager enough space to install the queued upgrade.

$ uname -r                        ## This command identifies the currently-running kernel
4.2.0-21-generic                  ## This is the current kernel.
                                  ## DO NOT REMOVE it, or you will be unable to boot!

$ dpkg -l | grep linux-image      ## This command lists all the kernels in the package
                                  ## database, and their status


rc  linux-image-extra-4.2.0-14-generic   ## The oldest kernel in the database
                                         ##  Status 'rc' means it's already been removed
ii  linux-image-extra-4.2.0-15-generic   ## The oldest installed kernel. Eligible for removal. 
                                         ##  Status 'ii' means Installed.
ii  linux-image-extra-4.2.0-16-generic   ## Another old installed kernel. Eligible for removal
ii  linux-image-extra-4.2.0-18-generic   ## Another old installed kernel. Eligible for removal
ii  linux-image-extra-4.2.0-19-generic   ## The previous good kernel. Keep
ii  linux-image-extra-4.2.0-21-generic   ## DO NOT REMOVE. The currently-running kernel
iU  linux-image-extra-4.2.0-22-generic   ## DO NOT REMOVE. Status 'iU' means it's not installed, 
                                         ##  but queued for install in apt.
                                         ##  This is the package we want apt to install.
ii  linux-image-generic                  ## DO NOT REMOVE. This is the metapackage that
                                         ##  regularly updates your kernel


$ sudo dpkg --remove linux-image-extra-4.2.0-15-generic     ## Remove the oldest package
                                                            ##  using dpkg instead of apt

$ sudo apt-get autoremove                                   ## Test that the package manager works
                                                            ##  and remove remaining old kernels

Many variations on this strategy exist. You can remove *all* the older kernels using dpkg. Some people have even scripted the process. Use a method that makes sense to you *and* to the package manager.

Warning: Do NOT use the 'rm' command to delete files that were placed by the package manager, including kernel files. It merely creates a new headache for you to solve when the package manager cannot remove packages due to 'file not found'. Always use the package manager to remove files that were placed by the package manager.

Unmet Dependency Errors

If you have ignored apt and dpkg errors for a while, then some packages may have upgraded while others did not. This is an expected follow-on effect. You will see mysterious, persistent version errors upon normal upgrades.

The simple way to fix most version mismatch errors is to update the package database, clean out the package cache, and download-and-reinstall the newer version of the offending package.

This is easier than it sounds. For example, if the 'hello' package is one of those unmet dependencies:

$ sudo apt-get update                      ## Update the package database
$ sudo apt-get clean hello                 ## Delete the hello package from the local cache
$ sudo apt-get install --reinstall hello   ## Download and reinstall the latest version of hello

Oops, removed the running kernel!

If you got a bit carried away and deleted all the kernels, you fall into the "You did WHAT?!?!" class. You will be pleased to know that you are not the first, nor will be the last, person to do this. Get your LiveCD and head over to GRUB reports no operating system.

Cryptic Shell Commands

There are various cryptic shell incantations floating around help sites and search engines that promise to remove older kernels. Copy-and-paste mysterious incantations into your system at your own risk.

Lubuntu/Documentation/RemoveOldKernels (last edited 2015-12-31 19:57:01 by ian-weisser)