86

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.

1

4 Answers 4

108

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!

9
  • 7
    apt-get autoremove did not remove the header files for me
    – user12345
    Oct 17, 2014 at 23:51
  • 11
    Except sometimes apt-get autoremove can't run because of an out of disk space error, due in part to /usr/src/linux* taking up 2G of space on a small drive. Feb 22, 2016 at 21:12
  • 4
    Yap. Sometimes it is not the disk space, but no more inodes being left -> if df -i shows 100% usage, you are de facto left with no space whatsoever. Only solution is then to delete some /usr/src/linux* stuff, to get apt to work again. Apr 6, 2017 at 0:48
  • 3
    Try sudo apt autoremove rather than apt-get.
    – jaybrau
    Jun 12, 2018 at 14:22
  • 10
    FWIW, apt-get autoremove worked for me -- freed 3.3GB of space on my 8GB AWS instance. Thank you! Aug 16, 2018 at 2:11
18

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.

1
1

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.

2
  • 4
    Your answer should explain how to do this, specifically. Mar 3, 2017 at 20:08
  • If I'm already at the command line issuing a command to determine which kernel version I'm using, I may as well issue the very simple apt-get autoremove.
    – ephsmith
    Aug 28, 2020 at 1:30
1

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'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .