When you’re in a Linux/DevOps/SRE job interview, one of the quickest ways for your interviewer to find out if you have gone beyond the absolute basics of Linux is to ask about inodes. These questions can take a few forms; we’ll cover inode interview questions one by one here.

 

What is a Linux inode?

On Linux, files are very simple structures that contain no metadata (information about themselves). Instead, each file is associated with an inode that has information about the file (size, location on disk, creation and modification time, permissions, etc.). Basically, when you ask Linux for information about a file (e.g. when you use the ‘ls’ command), Linux sees a filename and an inode number, and then goes and looks up the information in the referenced inode.

For example:

  1. You list a directory (ls -l).
  2. Directories are just lists of filename-inode pairs and other directories. Let’s pretend there is only one file in this directory.
  3. For each file (just one file), Linux lists the filename and then looks up the metainformation about that file and prints it next to the filename:
    • drwx------ 85 dave dave 4096 Apr 29 2020 code
    • (perms, ownership, size in bytes, modification date — all from inode)

 

What fields does an inode have?

The inode contains all the metainformation necessary to list and read a file:

  1. Size of the file (in bytes).
  2. Location on disk (needed to actually read the file).
  3. (user) owner and (group) ownership.
  4. File permissions.
  5. File creation and modification timestamps (access timestamps, too, if that’s turned on).
  6. Refcount (reference count): how many hardlinks lead to this file, i.e. how many times it’s ‘referenced’ on the filesystem.

 

How would you check for free inodes?

You can check for free inodes with the Linux command

df -i

To get a directory listing with inode numbers, use the ‘-i’ flag:

[dave@interviewanxiety compsci_interview]$ ls -i
19664639 debug 19664641 selection_sort.go 19664643 string_match.go
19664640 linked_list.go 19664642 shuffle.py 19664644 t9.py

This is what directories really contain — all the additional information you get from a long listing is actually looked up from that inode.

 

What could be happening when you can’t write to a filesystem but there’s space on the disk remaining?

Common example Linux errors include:

  • Disk quota exceeded.

There are several possible answers to this question, but inode exhaustion is one possible cause.

 

References