Abstract


Summary

Every file in Linux has two parts: the data you see, and the metadata that describes it. The inode is where Linux filesystems stores that metadata.

What is inside?

  • File type (regular file, directory, symlink, etc.)
  • Permissions (rwx for user/group/other)
  • Owner (UID, GID)
  • Timestamps:
    • atime – last access time
    • mtime – last modification time
    • ctime – last inode modification time
  • Size (in bytes)
  • Link count (number of directory entries pointing to the inode)
  • Pointers to data blocks on disk

What is not inside?

File name & file path.

File names are stored in directory entries. That’s why you can have two different file names pointing to the same inode (hard links).

Show inode attributes

stat <FILE_NAME>

Find all files sharing the same inode

find / -xdev -inum <INODE_NUMBER> 2>/dev/null

Search the whole file system for every filename that points to the specified inode number, but don’t cross into other mounted filesystems, and hide any permission errors from the output.

Inode Number

  • To uniquely identify a Inode

Obtian the inode number

ls -i

Directory Entry


/dir1/fileA β†’ inode #1234 β†’ data blocks
/dir2/fileB β†’ inode #1234 β†’ same data blocks
  • Directories are just special files that map filenames β†’ inode numbers

File deletion

The data cant be overridden as long as the number of Hard File System Link isn’t 0.

Deleted files may be recoverable if inode and data blocks haven’t been overwritten!

Moving files

Within same filesystem = instant (just updates directory entry).

Cross-filesystem = must copy data.

Inode Pointer to Data Blocks


  • Direct pointers: Point directly to data blocks.
  • Indirect pointers:
    • Single indirect β†’ points to a block of more block addresses
    • Double indirect β†’ two levels
    • Triple indirect β†’ three levels
  • This supports both small files (few pointers) and large files (a lot of pointers needed)

Inode Exhaustion


  • We are unable to create new File System even if there is still space on Disk. Because we have no more Inode to record the metadata of the data piece on the Disk

When can this happen and how can it be handled?

This can happen when we have a lot of small files like cache files.

This problem can be avoided on ZFS (Zettabyte File System) where Inode is allocated dynamically.

Check the total number inode available & used

df -i