Last night our system ran out of inodes. Luckily I manage to delete few old kernels using the following steps

  1. sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v \ uname -r | xargs sudo apt-get purge $1

  2. sudo apt-get autoremove

  3. sudo update-grub

I manage to get back some inodes but still more than 85 inodes are occupied.

Using ncdu I found out that the /usr/src/linux-headers-3.16.0.[69|71|73|..] directories still contain a few old kernel headers.

I'm not sure if they are needed or not given my current Linux version is 3.19.0-80-generic.

So I have two questions here:

  1. Is it safe to delete them?

  2. If so how to delete them?


This is covered in detail in the Ubuntu wiki; I’ll summarise here.

Regarding the first part of your question, Ubuntu kernels set up appropriate configuration to ensure that apt autoremove won’t remove the running kernel (and the latest one, and one backup kernel); so you can remove all the obsolete kernels by marking them as automatically installed (in case they’ve lost that marker):

sudo apt-mark auto '^linux-image-[34].*'

(this will produce warnings for all the kernel packages which aren’t installed, but they can be ignored), then removing the obsolete packages:

sudo apt autoremove

The kernel headers are also safe to delete, and are protected by the same configuration as the kernel images, so the same recipe applies:

sudo apt-mark auto '^linux-headers-[34].*'
sudo apt autoremove
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.