← Interview Prep

Linux Kernel — The Ext2/Ext3/Ext4 Filesystems

On-disk layout: superblock, block groups, inode/block bitmaps and the inode table; inodes with indirect blocks (ext2/3) vs extents & delayed allocation & htree dirs (ext4); directories as name→inode files; journaling modes (journal/ordered/writeback); and ext2 vs ext3 vs ext4.

How a classic Linux filesystem lays itself out on disk, and what journaling (ext3) and extents (ext4) added. The concrete storage under the VFS. Original, interview-focused notes.

An ext filesystem divides the disk into block groups, each with its own inode table, bitmaps, and data blocks. A file's inode holds its metadata and pointers to data blocks; a directory is just a file mapping names → inode numbers. ext3 added a journal; ext4 replaced block pointers with extents.

On-disk layout

StructureHolds
SuperblockFilesystem-wide metadata (size, block size, counts, feature flags). Backed up in several block groups.
Block groupThe disk is split into groups so related data/metadata stay close (locality → fewer seeks on HDD).
Inode & block bitmapsOne bit per inode/block — free or used.
Inode tableThe array of inodes (metadata + data-block map). Count fixed at mkfs.
Data blocksThe file contents themselves.

Because inode count is fixed at format time, a filesystem can run out of inodes while blocks are free — the classic ENOSPC-with-space bug (df -i). See Linux Troubleshooting.

Inodes: indirect blocks vs extents

Journaling — the ext3/ext4 addition

Without a journal, a crash mid-update can leave the filesystem inconsistent, needing a slow full fsck. A journal records intended changes first, so recovery just replays/discards the log — fast and safe. ext3/ext4 offer three modes:

ModeJournalsTrade-off
journalMetadata and dataSafest, slowest (data written twice).
ordered (default)Metadata only, but data is forced to disk before the metadata commitsGood balance — no stale-data exposure after a crash.
writebackMetadata only, no data orderingFastest; a crash can expose stale block contents in a just-extended file.

Journaling protects consistency, not your unflushed data — durability still needs fsync (see Page Cache).

ext2 vs ext3 vs ext4

Likely interview questions

Kernel Internals series. Related: The VFS · Page Cache · Linux Troubleshooting.