Can I, and how do I, remove older versions of the kernel in Ubuntu?

I installed Ubuntu 9.10 on a computer with 4 GB available space (I can't delete stuff from the Windows partition yet). After two automatic Update Manager updates, my disk space is almost all gone. In grub I can see the following list of OS choices:

Ubuntu, Linux 2.6.31-20-generic
Ubuntu, Linux 2.6.31-20-generic (recovery mode)
Ubuntu, Linux 2.6.31-19-generic
Ubuntu, Linux 2.6.31-19-generic (recovery mode)
Ubuntu, Linux 2.6.31-14-generic
Ubuntu, Linux 2.6.31-14-generic (recovery mode)
Windows

I'm confident -20 is running well, so is it possible to remove the -14 and -19 versions? Note that I'm asking is it possible to remove those kernel versions from the disk, not just from grub. Will this free up much disk space?


Solution 1:

run uname -a to verify you are running the right kernel

sudo apt-get remove '.*2.6.31-14.*'
sudo apt-get remove '.*2.6.31-19.*'

should do the trick... it will remove the kernel and any other related packages for that version. Give it a look over to make sure that only kernel related stuff matches before you enter 'y'.. I don't know of any packages that would have a version of 2.6.31-14 that are not kernel related, but it doesn't hurt to check.

I'd leave the previous kernel for a while until you are sure that the latest one is stable.

also,

running apt-get clean will remove all of the old .debs you have on your system.

you can install debian-goodies and run dpigs to see what packages are the biggest.

justin@eee:~$ dpigs
111836 openoffice.org-core
88128 linux-image-2.6.31-19-generic
71556 linux-headers-2.6.31-19
48516 google-chrome-unstable
44848 openoffice.org-common
44044 wireshark-common
37776 libgl1-mesa-dri
33976 gimp-data
33012 smbclient
24672 vim-runtime

There is also the "Disk Usage Analyzer" program in Accessories that you can use to see what is taking up space, or run

du -acx / | sort -n

You can also try system -> administration -> computer janitor, but I never use it and have heard mixed things about it.