What is an inode and what are they used for?

By Blue Matador on September 29, 2020

Inodes, speculated to be short for “index nodes,”  have been around since the introduction of the first UNIXThe Linux penguin file system around the late 1970s. 

They were adopted into Linux in the 90s—and for good reason. They’re an excellent way to keep track of how your files are stored, and the method many systems are still based on today.

What is an inode?

An inode is a file data structure that stores information about any Linux file except its name and data. 

What are inodes used for?

Data is stored on your disk in the form of fixed-size blocks. If you save a file that exceeds a standard block, your computer will find the next available segment on which to store the rest of your file. Over time, that can get super confusing.

That’s where inodes come in. While they don’t contain any of the file’s actual data, it stores the file’s metadata, including all the storage blocks on which the file’s data can be found. 

Information contained in an inode:

  • File size
  • Device on which the file is stored 
  • User and group IDs associated with the file
  • Permissions needed to access the file
  • Creation, read, and write timestamps
  • Location of the data (though not the filepath)

Inodes are also independent of filenames. That means you can copy a single file, rename it, and still have it point to the same inode as the original.

Where inodes can get weird

Much like your fixed-size blocks of data, inodes are also uniform. It is possible that you have a file that exceeds the size of your inode. In this case, your original inode will have to point to another inode in order to fully encompass the file’s metadata. This is called an indirect pointer.

Inode indirect pointer graphYeah... weird. Source.

On top of that, the number of inodes you have on your disk is static.  That means if you have enough files, you may run out of inodes before you run out of disk space. If you run out of inodes, you’ll have to rebuild your filesystem and include a larger limit for inodes.

Handy inode commands on Linux

Use the command df-i to pull basic data about your inode usage, including the file system on which the inodes are stored, your total inode count, how many are in use (in count and %), and how many remain. 

[bluematador ~]$ df -i /dev/bluem1
Filesystem     Inodes IUsed  IFree IUse% Mounted on
/dev/bluem1    654972   516  654456   1% /boot

Use -inum to find files associated with a certain inode. Inversely, use ls-i to get the inode number of a file.

ls -i Command: display inode
$ls -i /dir/bluem_article
129792 /dir/bluem_article
129792 is the inode of /dir/bluem_article.

What can go wrong with inodes

Running out of inodes can look weird, because it’s likely you’ll still have free disk space. So how do you know if you’ve run out of inodes? 

From our inode troubleshooting page:

The moment a file system runs out of inodes, all new files and folders will be rejected. Until that point, no adverse effects will manifest. Once inodes are 100% used, you’ll begin to notice:

  • Data loss
  • Applications crashing
  • OS restarting
  • Processes don’t restart
  • Periodic tasks not firing

If you notice any of the above, use df-i to confirm that you’ve reached inode capacity.

What to Read Next

Subscribe to get blog updates in your inbox.

Get automated cloud monitoring
for instant insights.