What is Inode in Linux
What We’ll Cover
- What is a Inode
- Deep into inodes table structure
- What inode contains
- Why we need inodes
- How to use inodes
- How to check inodes numbers
- Conclusion
What is a Inode ?
An inode is a abbreviation of the index node. It is a data structure, which provides unique identifier for a specific piece of metadata on a given file system.
An inode contains all the information about a file except its name and file content. An inode is 128 bytes. The inode contains all the administrative data needed to read a file. Every file’s metadata is stored in inodes in a table structure.
In other words, inode is a unique identifier operate on each filesystem, independent of the others.
Deep into inodes table structure
Inode is a array of 15 disk addresses (0 to 14) points to the data blocks that store the contents of the file.
The first 12 are direct addresses; that is, they point directly to the first 12 logical storage blocks of the file contents. If the file is larger than 12 logical blocks, the 13th address points to an indirect block, which contains direct block addresses instead of file contents.
The 14th address points to a double indirect block, which contains addresses of indirect blocks.
The 15th address is for triple indirect addresses, if they are ever needed.
What inode contains?
The inode information is kept in the cylinder information block, and contains the following:
- The type of the file
- The mode of the file (the set of read-write-execute permissions)
- The number of hard links to the file
- The user ID of the owner of the file
- The group ID to which the file belongs
- The number of bytes in the file
- An array of 15 disk-block addresses
- The date and time the file was last accessed
- The date and time the file was last modified
- The date and time the file was created
Why we need Inodes ?
When you create a new file or a directory, it is assigned that file name and a inode number. Both are stored as entries in a directory.
How to use Inodes ?
When creating or copying a file, Linux system assigns a new inode number. However, when moving a file, the inode number will only change if the file is moved to a different filesystem (if it is within same file system inode number will not change). This applies to directories as well. This is the reason why you can not create hard links across filesystems.
Most of the time we see, low space in a filesystem due to inodes. Even if you have enough free space (free space to store data) on your disk, you won’t be able to create new files.
Using up all the inodes can also result in problems of your system.
- Data loss
- Applications crashing
- OS restarting
- Processes don’t restart
- Periodic tasks not firing
To fix high inode usage problems:
- Delete unnecessary files and directories.
- Delete Cache files.
- Delete Old email files.
- Delete Temporary files.
How to check inodes numbers?
The total number of inodes in a filesystem is defined when it is created and it cannot be changed dynamically. So, it is important to regularly check inode usage to guarantee it adjusts to the configured limits.
There are different cmmands to check inode numbers and number of links and available inodes spaces
df -ih <File System>stat <File Name>stat <Directory Name>ls -il <File Name>ls -ild <Directory Name>
Conclusion
Considering all above, it is very important to understand the usage and behaviors of inodes in Linux filesystems. This covered the concepts and some basic commands you should know when working with inodes. This makes helps when examining file systems and maintaining low inode usage.
Please add a comment, if there is anything needed to be corrected or added. Thanks for reading.