Inodes

Foreword

In this article, we briefly describe what an inode is, where they are used and give an example of a problem that frequently occurs, as well as the corresponding solution approach.



What is an inode?

Inodes are a data structure used for file system management and have a unique number for identification. An inode exists for each name entry in a directory structure, regardless of the file type, and contains the corresponding metadata and a reference to it.

Metadata in this context includes, for example, information on the file type, the UID and GID of the owner and the group, the access rights set, the file size, a reference to the disk sectors of a file (the size of these sectors depends on the file system and the associated formatting), etc.



Scope of application of inodes

These are used with all unixoid operating systems such as Linux (and corresponding derivatives) or macOS. With the file systems ext2 | ext 3 | ext4, these are created completely and unchangeably in the form of lists/tables as changeable file headers directly during the system installation.



Problem example

You use a CMS for your website with various installed plugins, e.g. for caching the web content.

Suddenly your website is no longer accessible and you receive an error message suggesting that the hard disk has no more free space.


Analysis

Then connect to your server, e.g. via SSH, and check the hard disk usage as follows:

Establish connection:

ssh root@sXXXXX.creoline-demo.tld

Check hard disk usage:

df -h

Output:

File system Size Used Used% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 392M 532K 391M 1% /run
/dev/sda2 20G 8.5G 11G 46% /
tmpfs 2.0G 1.2M 2.0G 1% /dev/shm
tmpfs 5.0M 24K 5.0M 1% /run/lock
tmpfs 392M 0 392M 0% /run/user/0


According to the output, more than 50% of the usable hard disk capacity is still available, so the hard disk appears writable. However, it is not possible to create new files, for example.

You should check whether there are still enough inodes available:

df -i

Output:

File system Inodes IUsed IFree IUse% Mounted on
udev 496122 362 495760 1% /dev
tmpfs 500931 614 500317 1% /run
/dev/sda2 1310720 1310720 0 100% /
tmpfs 500931 2 500929 1% /dev/shm
tmpfs 500931 34 500897 1% /run/lock
tmpfs 100186 20 100166 1% /run/user/0


Here you can see that the system partition containing the root directory has all available inodes in use.

Cause

In this example, the cache plugin has generated lots of small files that were not automatically cleaned up after they were no longer needed.

As a file is always assigned an inode regardless of its size, the available pool of inodes can be used up more quickly by countless small files than the number of sectors used to calculate the disk space used at the end.


Remedy

You can display the inode allocation per directory as follows:

du -h --inodes --max-depth=1 /var/www/vhosts/


Output:

36 /var/www/vhosts/system
5 /var/www/vhosts/default
1300000 /var/www/vhosts/sXXXXX.creoline-demo.tld
101 /var/www/vhosts/chroot
9 /var/www/vhosts/.skel
1300000 /var/www/vhosts/


Next, change to the directory /var/www/vhosts/sXXXXX.creoline-demo.tld and repeat the previous query:

du -h --inodes --max-depth=1 /var/www/vhosts/sXXXXX.creoline-demo.tld


Repeat this process until you have found the directory in which the inodes are bound by small files.

As soon as you have found this, navigate to the corresponding directory with cd:

cd /var/www/vhosts/sXXXXX.creoline-demo.tld/httpdocs/demo-cms/plugins/XYZ/examplecache/

Delete the content with the following command:

rm -rf * or rm -rf /var/www/vhosts/sXXXXX.creoline-demo.tld/httpdocs/demo-cms/plugins/XYZ/examplecache/*


Before using the rm -rf command, make absolutely sure that you are in the correct directory or that you have specified the correct absolute path in order to avoid unintentional deletion of data.


As soon as this process is complete, check the inode usage by the CMS again:

root@sXXXXX:/var/www/vhosts# du -h --inodes --max-depth=1 /var/www/vhosts/
36 /var/www/vhosts/system
5 /var/www/vhosts/default
3.3K /var/www/vhosts/sXXXXX.creoline-demo.tld
101 /var/www/vhosts/chroot
9 /var/www/vhosts/.skel
3.5K /var/www/vhosts/


Inode assignment system-wide:

root@sXXXXX:/# df -i
File system inodes IUsed IFree IUse% Mounted on
udev 496122 362 495760 1% /dev
tmpfs 500931 614 500317 1% /run
/dev/sda2 1310720 190768 1119952 15% /
tmpfs 500931 2 500929 1% /dev/shm
tmpfs 500931 34 500897 1% /run/lock
tmpfs 100186 20 100166 1% /run/user/0
Similar articles