Skip to content
linux storage

Inode

inode filesystem ext4 storage linux
Plain English

An inode is a file’s ID card inside the filesystem. It holds the file’s size, owner, permissions, and the location of its data on the disk. Oddly, it does not hold the file’s name; the name lives in the folder and just points to the inode. A disk can run out of inodes before it runs out of space if it holds millions of tiny files.

Technical Definition

An inode (index node) is a fixed-size structure in Unix-style filesystems such as ext4. Each file and directory has exactly one, identified by an inode number unique within that filesystem.

Stored in the inode: type, permissions, owner UID and GID, size, link count, timestamps (atime, mtime, ctime, and creation time on ext4), and pointers to data blocks (extents on ext4).

Not stored: the filename. A directory is a list of name-to-inode mappings.

Consequences:

  • Hard links are extra names for the same inode (ln file link). The data is freed only when the link count reaches zero and no process holds it open.
  • Renaming or moving within a filesystem just rewrites a directory entry; the data never moves.
  • Deleted but open files keep using space until the program closes them, which is why df and du can disagree.

Inode exhaustion: ext4 creates a fixed number of inodes at mkfs time. Millions of tiny files (mail queues, caches, session files) can use them all while space is free, and writes fail with “No space left on device.” XFS, Btrfs, and ZFS allocate inodes dynamically.

Source: inode(7) Linux manual page

Inspecting inodes

# Inode number of a file
$ ls -i /etc/hostname
1310742 /etc/hostname

# Full inode details
$ stat /etc/hostname
  File: /etc/hostname
  Size: 4          Blocks: 8          IO Block: 4096   regular file
Inode: 1310742     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)

# Inode usage per filesystem
$ df -i /
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
/dev/sda2      1572864 312455 1260409   20% /

# Space held by deleted-but-open files
$ sudo lsof +L1
In the Wild

Two inode problems show up in real tickets. First, “disk full” with plenty of space: run df -i, then find the directory with millions of small files. Second, space that will not free up after deleting a big log: a process still holds it open, which lsof +L1 reveals, and restarting that service releases it. Understanding inodes also explains why hard links, renames, and permissions behave the way they do.