Clean-up inodes 100% usage caused by linux headers

Inodes are used to describe directories and files in linux system. They are created when a disk is partitioned and the amount is fixed. When all inodes are used up in some cases, you will not be able to create new file even though the storage is not full. You can check your inodes usage by:

df -i

One common case that could cause the inodes to be fully utilised - the linux headers file. This could happens when the server is not rebooted for a long time and multiple versions of linux headers are accumulated without being able to complete the upgrades. Below are some steps to fix this problem:

(1) You can check a list of headers in the following directory:

cd /usr/src

(2) Then you can check which version you are currently using:

uname -r

You might notice that you are using a much older version and there is a lot of newer version in the directory above.

(3) You can try to clean the older version (if there is) with this command:

sudo apt-get autoremove

(4) If you got lucky then it will clear some space for you. But it is likely that you see an error like the following. The reason is the inodes are used-up when the system is downloading and unpacking a new version of linux header. Because it is not fully unpacked, it will gives this error and require you to fix it before you can run the autoremove.

You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 linux-headers-generic : Depends: linux-headers-4.4.0-133-generic but it is not installed
E: Unmet dependencies. Try using -f.

(5) Now if you run the install command as suggested. You will get a disk full failure of course. So we have to manually remove some of the header with the command below. And DO NOT remove the current version that you are using.

sudo rm -rf /usr/src/linux-headers-4.4.0-XXX{,-generic}

(6) Once you have removed a few of those. You have enough space (or inodes) now and you can run the following command:

sudo apt-get -f install

(7) Reboot your server.

(8) Run the clean-up command again and it should be successful this time.

sudo apt-get autoremove

(9) Now you should have cleared a lot of storage and free up inodes.


AI Summary
Chrome On-device AI 2024-11-09 05:32:38

Share Article