Can’t remember how much I dug this info on the internet, always when in emergency.
Hence I’ve decided once forever to write a small note here.
Suppose that in /boot directory there is a kernel you want to remove, identified by files like:
- abi-2.6.38-15-generic-pae
- config-2.6.38-15-generic-pae
- initrd.img-2.6.38-15-generic-pae
- System.map-2.6.38-15-generic-pae
- vmcoreinfo-2.6.38-15-generic-pae
- vmlinuz-2.6.38-15-generic-pae
Here’s the right command:
apt-get remove --purge linux-image-2.6.38-15-generic-pae
If you are brave and wanna go scripting wild ð first you check what kernel are you booting with using the command:
uname -r
This will give you an output like: “2.6.38-16-generic-pae”
Then you check which other kernels you have, except the one you’re booting with, using the command:
dpkg -l|egrep '^ii  linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`
(yes, if you do not use egrep on the first grep it won't work)
This will return the list of kernels which are not the one you’re executing (because you excluded that one with grep -v):
linux-headers-2.6.38-15
linux-headers-2.6.38-15-generic
linux-headers-2.6.38-15-generic-pae
linux-headers-2.6.38-16
linux-headers-2.6.38-16-generic
linux-headers-generic
linux-headers-generic-pae
linux-image-2.6.38-15-generic-pae
linux-image-generic-pae
Finally, you run the remove command using:
sudo apt-get remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
TO BE CHECKED: the command above might remove also metapackages such as linux-headers-generic-pae. Hence it is safer to remove one by one the needed packages from the above list.