Everything in Linux is considered a file for consistency purposes. This includes hardware devices, printers, directories, and processes. Regular files such as music, text, video, and other multimedia files also have additional data associated with them called metadata
What is Inodes in Linux? Inodes are the backbone of the Linux filesystem. They manage metadata about a file and are an important part of how Linux works internally.
What is the structure of the file system?
The file system is divided into two parts – data blocks and inodes. The number of blocks is fixed after creation and cannot be changed.
The name, path, location, links, and other attributes of the file are not in the directory. Directories are simply tables containing filenames with the corresponding inode number.
You can create a hard link so that the same file has more than one name. When you create a hard link, it also creates a new name in the inode table, but does not move the file.
If you were to move a large file, it would take a long time. It is more efficient to create a name entry in the new directory and delete the old one. You can rename files in the same way.
– /
The top of the hierarchy is the file system itself. There are filenames in the file system. The file names refer to inodes. Inodes refer to physical data.
What is Inodes in Linux?
Inode is a data structure. It identifies a file or directory on the file system and is stored in a directory entry. Inodes indicate the blocks that make up the file. The inode contains all the administrative data needed to read the file. The metadata for each file is stored in inodes in the table structure.
When using a program that refers to a file by name, the system will look in the file for the directory entry in which it exists to find the corresponding inode. This gives your system the file data and information it needs to carry out processes or operations.
Inodes are usually found at the beginning of a section. They store all information associated with a file, except for the file name and actual data. All files in any Linux directory have a filename and an inode number. Users can get metadata for a file by specifying the inode number.
File names and inode numbers are stored in a separate index and are associated with the inode. You can reference the metadata representing the file. It is possible to have multiple filenames that refer to the same piece of data or inode, as you can see in the image below.
What is the inode number?
Each inode in a Linux structure has a unique number. It is also called a sequence number and has the following attributes:
- Size
- Owner
- Date / time
- Permissions and Access Control
- Disk location
- File types
- Number of links
- Additional file metadata
To check the list of inode numbers, use the following command:
ls -i
The screenshot below shows a directory with inode numbers in the leftmost column.
How does Inodes work?
When you create a new file, it is assigned a filename and an inode number. Both are stored as directory entries. Running ls (ls -li) will show you a list of filenames and inode numbers that are stored in the directory.
Use the command below to list inode information for each file system.
df -hi
How many Inodes do you use?
One way to run out of space on the filesystem is to use all of your inodes. Even if your disk has enough free space, you won’t be able to create new files.
Using all inodes can also cause your system to stop suddenly. To view a list of inode usage statistics such as used, free, and percentage, enter the following command:
sudo df -ih
Additional methods are used inodes
The way inodes work on Linux makes it impossible for inode numbers to conflict. It is not possible to create a hard link between different file systems. However, you can use softlinks across different file systems. You can delete the original files while keeping the data accessible via the hard link.
When deleting a file, all you have to do is remove one of the names that point to a specific inode number. The data will remain until you delete all names associated with the same inode number. Updating Linux systems does not require a system reboot, mainly due to the way inodes work.
A process can use a library file while another process replaces the same file with a newer updated version and creates a new inode. The running process continues to use the old file. The next time you use the same process, it will use the new version.
Users do not interact directly with inodes, but they are a fundamental component of Linux file structures.
–