Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Every time I install a new Linux kernel, it gets left in the grub_config, making the boot menu longer each time.

I know I can manually search through the installed packages and remove them.

Does Ubuntu provide any easier way to clean them up or keep them from showing in the boot list?

share|improve this question
sudo apt-get autoremove should do the trick on Ubuntu 14.04+ – hobs Dec 1 '15 at 17:17

34 Answers 34

This is by far the best answer in my opinion:

Follows the last command on the site above somewhat tweaked:

sudo apt-get purge $(dpkg -l 'linux-*' | awk '/^ii/{print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -E -e -[0-9]+(\.[0-9]+){2}-[^-]+)
share|improve this answer

Here's the script I use to keep 2 kernel packages installed (i.e. the current one and the previous one). It also removes the initrd-VERSION-generic.old-dkms files left around by DKMS, which can fill-up a small boot partition.

The script:

echo "**Removing -generic.old-dkms files from /boot**" && rm -f /boot/*-generic.old-dkms # if using DKMS it creates initrd-VERSION-generic.old-dkms in /boot and doesn't clean them up, meaning after a few kernel upgrades /boot can become full
OLDKERNEL=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | awk '{print "linux-image-" $0}')
OLDHEADERS=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | sed 's/-generic//g' | awk '{print "linux-headers-" $0}')
OLDHEADERS=${OLDHEADERS//-pae/} # remove -pae string as linux-header packages don't have it in their names
if [ -n "$OLDKERNEL" -o -n "$OLDHEADERS" ]; then
apt-get -q remove --purge $OLDKERNEL $OLDHEADERS
echo "**Finished removing old kernels**"
echo "**No old kernels found**"
share|improve this answer
  1. Open the terminal.
  2. Type the command sudo su.
  3. Open file directory using xdg-open /boot/ in the bash shell.
  4. Then remove all the kernel files that you don't require.
  5. Give the command update-grub.
share|improve this answer
-1 this does not add anything to (which was downvoted to -3, if you note), and is just as dangerous. – muru Aug 31 '14 at 9:19

in addition to the above answers you could try to remove the kernel image + + config files manually. grub looks for those files in the /boot directory.

remove any files not related to the kernel version(s) you use. if you are using only the latest version, let's say 3.2.0-25, it should be safe to remove all 2.6.* and 3.0.* versions. so you type ls -alF /boot/2.6. to see what's there and remove those. same with all the other versions except the one(s) you are using.

NB: when updating the kernel it may be good policy to keep the version that previously worked best for you

share|improve this answer
This seems likely to break things, particularly when 3rd party modules have been installed. – user108430 Apr 1 '13 at 15:24

protected by Community Aug 2 '15 at 6:05

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.