87

I'm running Ubuntu 12.04, and two active linux images 3.2.0-37 and 3.2.0-36. In the /usr/src/ directory i find:

linux-headers-3.2.0-23    
linux-headers-3.2.0-23-generic    
linux-headers-3.2.0-26    
linux-headers-3.2.0-26-generic
linux-headers-3.2.0-29    
linux-headers-3.2.0-29-generic
linux-headers-3.2.0-31    
linux-headers-3.2.0-31-generic    
linux-headers-3.2.0-32    
linux-headers-3.2.0-32-generic    
linux-headers-3.2.0-33    
linux-headers-3.2.0-33-generic    
linux-headers-3.2.0-34    
linux-headers-3.2.0-34-generic    
linux-headers-3.2.0-35    
linux-headers-3.2.0-35-generic    
linux-headers-3.2.0-36    
linux-headers-3.2.0-36-generic     
linux-headers-3.2.0-37     
linux-headers-3.2.0-37-generic

Today I sudo apt-get purge linux-image-x.x.x.x-generic *34 and *35

I have to add that /boot contains only *36 and *37.

Is it safe to remove all of these except *37 and *36 ? Thank you in advance.

4 Answers4

110

Those are header files are contained in the linux-headers-* and linux-headers-*-generic packages. It should be safe to remove them through apt-get. Maybe apt-get autoremove will already suggest that to you. Please do not remove them manually!

19

I just had this issue, and the suggestion to use apt-get autoremove did not work for me.

I resolved it by doing:

sudo apt-get purge linux-headers-3.2.0-23

on such linux headers that lived in /usr/src. I did not remove the headers that correspond to the kernel currently being used.

Restarted the server successfully.

user12345
  • 4,631
2

This is very similar, but more readable, than the helpful comment from Reinier Post in user12345's answer.

apt list --installed linux-*5* | grep -v $(uname -r) | xargs sudo apt -y purge

It missed one dev header package without the standard numbering, but also didnt pickup the linux-sound-base for Alsa, which might be desired. You can compare both by removing the xargs pipe, like this dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/(.*)-([^0-9]+)/1/")"'/d;s/^[^ ]* [^ ]* ([^ ]*).*/1/;/[0-9]/!d'

alchemy
  • 850
0

To anyone coming in off a Google search years later: You can also uninstall old kernels in the Synaptic Package Manager. Just double check which one you're currently using by typing 'uname -a' into the terminal.

Jeremy Kerr
  • 27,829