Is it safe to remove old kernels after installing the latest mainline?

I have installed the mainline kernel 3.10 as recommended here so that I can have my WiFi.

I'm running into space problems as described here (dpkg configuration running out of space, having separate /boot)

Is it safe to run the recommended command described in this blog as pointed out in that answer? If not, how should it be modified? I'm using:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | 
 sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | 
 xargs sudo apt-get -y purge

dpkg --list | grep linux-image

ii  linux-image-3.10.1-031001-generic         3.10.1-031001.201307131550           amd64        Linux kernel image for version 3.10.1 on 64 bit x86 SMP
ii  linux-image-3.8.0-19-generic              3.8.0-19.30                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-26-generic              3.8.0-26.38                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-27-generic              3.8.0-27.40                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-29-generic              3.8.0-29.42                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-extra-3.8.0-19-generic        3.8.0-19.30                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-extra-3.8.0-26-generic        3.8.0-26.38                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-extra-3.8.0-27-generic        3.8.0-27.40                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
iF  linux-image-extra-3.8.0-29-generic        3.8.0-29.42                          amd64        Linux kernel image for version 3.8.0 on 64 bit x86 SMP
iU  linux-image-generic                       3.8.0.29.47                          amd64        Generic Linux kernel image

I'm not sure about which ones are the latest. Please show me which ones are definitely the oldest and unneeded so they can be removed with sudo apt-get purge linux-image-x.x.x.x-generic.


Solution 1:

Yes it's safe to remove kernels you don't use. However I would check this question first for other recommended ways to remove old kernels:

  • How do I remove old kernel versions to clean up the boot menu?

Solution 2:

Use Computer Janitor!

The easy way to do this using the Ubuntu Tweak that have Computer Janitor.

enter image description here

Install

sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak

Solution 3:

Hm, I would leave 1 or 2 kernels in the installed systems. It is almost not possible, but it could be that by update the newest kernel gets malformed. So it would be possible to return then via the next installed kernel into system.

I only say this not because of Ubuntu, but of else distributions, where sometimes updates malformed the installation somehow. Ubuntu is quite secure and quite reliable with updating files. It belongs only to the circumspectly user or admin, to allow himself an additional emergency-mode for his system, besides the protected-mode.