What is inode on Linux?

Linux TLDR
Last Updated:
Reading time: 4 minutes

In this article, you will learn what an inode is, how to check an inode and its size in Linux, and their roles in soft/hard links and system updates.

What is Inode in Linux?

In your Linux filesystem, an inode (or index node) is a table of records that stores metadata information for all files and directories except for the file name and data.

The inode stores the following information about a file or directory:

  • The file’s type (e.g., regular file, directory, symbolic link, etc.)
  • The file’s permissions (e.g., owner, group, and read/write/execute permissions)
  • The file’s size
  • The file’s timestamps (e.g., creation, modification, and access times)
  • Pointers to the blocks on the disk where the file’s data is stored

Every file in the specified directory is an entry with the filename and inode number. The rest of the information about the referenced file is pulled from the inode table using the inode number.

Inode table

The inode table is located at the beginning of a partition, and the inode number used to refer to file information in the inode table is unique at the partition level.

It means that two files with the same inode number cannot exist on the same partition unless they are on separate partitions.

Role of the inode table on the partition level

Let’s see how to check the inode number of files and directories in a Linux system.

How to Check Inode in Linux?

You can easily list the inodes number assigned to files and directories in the current working directory by using the ls command:

$ ls -li

Output:

Displaying the inodes number in the current working directory

Whenever you create a new file, a unique integer number is generated in sequence and assigned to the file. The generated number is nothing more than a pointer pointing towards the file metadata in the inode table.

But keep in mind that the generated number should be less than the inode size that was set when the partition was created.

How to Find the Inode Size in Linux?

The inode number assigned to files and directories is limited to the inode size that was set when the partition was created. Once you reach the end, your system will be unable to create a new file, even if you have free space.

When you issued the β€œls -li” command, it displayed the file name, and the remaining file information, like user, group, file permissions, size, etc., is retrieved from the inode table using the inode number.

Run the following command to list the inode information for each filesystem on your Linux system:

$ df -hi

Output:

Inode information for each filesystem in Linux

How Is the Size of an Inode Determined?

As you learned, the inode size is determined when the partition is created. For most users, the default inode size is more than enough. But as a Linux user, you should know how this inode size is determined at the time of partition creation.

πŸ“
The inode size cannot be resized after the partition is created.

The default setting used to determine the inode size on the filesystem is β€œ1 inode = 2048 bytes (2 Kbytes)β€œ, considering each file should be greater than 2 Kbytes.

Most of the files will be larger than 2 kilobytes; however, if your system has many soft links or you are running a mail server that stores a huge amount of tiny files, they can lower the average file size.

A normal user will not run out of inodes, but it is possible. If that happens, the user won’t be able to add a new file to the system; however, modern filesystems like Btrfs, JFS, and XFS use dynamic inodes to automatically fit inode sizes based on the requirements.

Role of the Inodes in Soft/Hard Link

Symlinks, or β€œsoft and hard” links, are one of the most important subjects in Linux computing. Check out our detailed article about them.

First, let’s talk about the soft links.

Working of Inodes with Soft Link

In UNIX/Linux systems, whenever a soft link is created, a unique inode number is assigned to the generated soft link.

For example, there is an original β€œfile.txt” file located in my home directory, and inside β€œ~/Documents” I have a soft link to β€œfile.txtβ€œ, as shown.

File structure

Now, using the ls command, you can see that the inodes number for both of these files are different.

Checking the inode number of the soft link

This result declares that each soft link occupies one inode number in your filesystem, and separate metadata information is stored in the inode table for every soft link you create.

Working of Inodes with Hard Link

I will use the same example as a soft link, except this time β€œfile.txt” in the β€œ~/Documents” directory is a hard link.

The following is the inode number of the original β€œfile.txt” and the hard link.

Checking the inode number of the hard link

As you can clearly see, the original file and the hard link have the same inode number. Basically, whenever you create a hard link for any file, you only create a new filename that is pointing towards the same inode number.

Any changes made to a hard link, like metadata or file modification, will directly reflect on the original file.

Even if you delete the original file (basically, you are deleting the filename pointing towards the inode number), you will still be able to access the file data using the hard link. The data will stay until all of the names that can be linked to an inode number have been removed.

Role of the Inodes in System Update

When you update your Linux system, the running process uses the old library files with a different inode number, while the old version is replaced with the new version using a different inode number.

This way, the process kept running using the old library files while they updated to the new version using the separate inode number.

Why We Need Inodes is First Place?

The answer to this question is already present in this beloved article, but I understand that the inode numbers can be heavy for a beginner’s chest, so I will not leave it as something like an Easter egg.

So, to return to the original question, if you’re wondering why the inodes is so important and why we can’t simply attach the file metadata information to the file at the time of creation,

Then keep in mind that inodes are critical to allowing you to use the same file or data with multiple filenames and to allowing you to continue using your system even after a system update.

Final Tips!

Many users become aware of inodes when they have enough disk space but are unable to create a new file. Although, inode number is not something that you directly interact with, it should be known to an informed Linux user.

I hope this article provides a clear picture of inodes in Linux; if anything is missing that should be included, then let us know in the comments section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.