Everything in Linux is considered a file to maintain consistency. That includes hardware devices, printers, directories, and processes. Regular files such as music, text, videos, and other multimedia files also have additional data associated with them called metadata.
What are Inodes in Linux? Inode entries are the basis of the Linux file system . They manage the metadata about a file and are essential pieces of the inner workings of Linux.
What Is The Structure Of a File System?
A file system is divided into two parts – data blocks and inodes. The number of blocks is fixed once created, and can’t be changed.
The name, path, location, links and other file attributes are not located in the directory. Directories are simply tables that contain the names of the files with the matching inode number.
You can create a hard link resulting in more than one name for the same file. When you create a hard link, it also creates a new name in the table with the inode but doesn’t move the file.
If you were to move a large file, it would take a long time. It’s more efficient to create the name entry in a new directory and delete the old entry. You can also rename files in the same way.
The top part of the hierarchy is the file system itself. Within the file system are the file names. The file names link to the inodes. The inodes link to the physical data.
What Are Inodes In Linux?
An inode is a data structure. It defines a file or a directory on the file system and is stored in the directory entry. Inodes point to blocks that make up a file. The inode contains all the administrative data needed to read a file. Every file’s metadata is stored in inodes in a table structure.
When using a program that refers to a file by name, the system will look in the directory entry file where it exists to pull up the corresponding inode. This gives your system the file data and information it needs to perform processes or operations.
Inodes are usually located near the beginning of a partition . They store all the information associated with a file except the file name and the actual data. All files in any Linux directory have a filename and an inode number. Users can retrieve the metadata for a file by referencing the inode number.
File names and inode numbers are stored in a separate index and link to the inode. You can link to the metadata that represents the file. It is possible to have multiple file names that link to one piece of data or inode as you can see in the image below.
What Is The Inode Number?
Every inode in the Linux structure has a unique number identified with it. It is also called the index number and has the following attributes:
- Permissions and access control
- Location on the disk
- File types
- Number of links
- Additional metadata about the file
To check the list of inode numbers, use the following command:
The screenshot below shows a directory with inode numbers appearing in the far-left column.
How Do Inodes Work?
When you create a new file, it is assigned a file name and inode number. Both are stored as entries in a directory. Running the ls command (ls -li) will show you a list of the file names and inode numbers that are stored in a directory.
Use the command below to list inode information for each file system.
How Many Inodes Are You Using?
One way to run out of space in a filesystem is to use up all your inodes. Even if you have enough free space on your disk, you won’t be able to create new files.
Using up all the inodes can also result in your system suddenly stopping. To see a list of statistics about inode usage such as used, free, and percentage used, type the following command:
sudo df -ih
Additional Ways Inodes Are Used
The way inodes work in Linux make it impossible to have conflicting inode numbers. It is not possible to create a hard link across different file systems. However, you can use soft links across different file systems. You can delete the original files and still have the data available through a hard link.
By deleting a file, all you have done is remove one of the names pointing to a specific inode number. The data will remain until you delete all names associated with the same inode number. Linux systems update without requiring a system reboot in large part because of the way inodes work.
A process can use a library file at the same time another process replaces the same file with a newer updated version and creates a new inode. The running process keeps using the old file. The next time you use the same process, it will use the new version.
Users don’t interact directly with inodes, but they do represent a fundamental component of Linux file structures.