Files are piling up in /usr/src/. How can I stop this?

I have been having many serious system issues over the past few weeks and have been scratching my head as to why. I've now worked out that this problem is having no inodes left on the root partition

$ df -i
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
/dev/sda6       732960 724565    8395   99% /
udev            125179    518  124661    1% /dev
tmpfs           127001    464  126537    1% /run
none            127001      4  126997    1% /run/lock
none            127001      8  126993    1% /run/shm
/dev/sda7      5234688 144639 5090049    3% /home

What is the cause? I've found that 400K of those are in use in /usr/src

$ ls /usr/src
linux-headers-3.2.0-25-generic      linux-headers-3.2.0-33
linux-headers-3.2.0-25-generic-pae  linux-headers-3.2.0-33-generic
linux-headers-3.2.0-26              linux-headers-3.2.0-33-generic-pae
linux-headers-3.2.0-26-generic      linux-headers-3.2.0-35
linux-headers-3.2.0-26-generic-pae  linux-headers-3.2.0-35-generic
linux-headers-3.2.0-27              linux-headers-3.2.0-35-generic-pae
linux-headers-3.2.0-27-generic      linux-headers-3.2.0-36
linux-headers-3.2.0-27-generic-pae  linux-headers-3.2.0-36-generic
linux-headers-3.2.0-29              linux-headers-3.2.0-36-generic-pae
linux-headers-3.2.0-29-generic      linux-headers-3.2.0-39
linux-headers-3.2.0-29-generic-pae  linux-headers-3.2.0-39-generic
linux-headers-3.2.0-30              linux-headers-3.2.0-39-generic-pae
linux-headers-3.2.0-30-generic      linux-headers-3.2.0-40
linux-headers-3.2.0-30-generic-pae  linux-headers-3.2.0-40-generic
linux-headers-3.2.0-31              linux-headers-3.2.0-40-generic-pae
linux-headers-3.2.0-31-generic      linux-headers-3.2.0-41
linux-headers-3.2.0-31-generic-pae  linux-headers-3.2.0-41-generic
linux-headers-3.2.0-32              linux-headers-3.2.0-41-generic-pae
linux-headers-3.2.0-32-generic      linux-headers-3.2.0-43
linux-headers-3.2.0-32-generic-pae

Surely not all of these are actually needed? I've tried apt-get autoremove but it leaves them all be. I don't want to remove them manually, but this is crippling my machine. They also take up almost 2G of the 11G system partition that is getting full (>80%) aside from the inode issue.

How can I safely remove the headers that are not needed?


This should work:

sudo apt-get autoremove

You can read more at the AptGet How-to.


You can search for packages that own these files using

dpkg -S /usr/src/*

Check your current kernel version

uname --kernel-release

And remove all old kernel (linux-image-*) and header packages (linux-headers-*) that are not currently used but are still installed.

You can also mark these packages as automatically installed and they should get autoremoved.