ext4, XFS & btrfs

ext4 journal modes, XFS advantages, tune2fs, xfs_repair, btrfs copy-on-write, and filesystem selection.

Overview

Choosing the right filesystem has significant implications for performance, data integrity, and operational complexity. Linux ships three mature general-purpose filesystems — ext4, XFS, and btrfs — each with distinct trade-offs.

ext4

ext4 is the evolution of ext2/ext3 and the default on most Debian/Ubuntu/RHEL systems. Key features: extents (contiguous block ranges replacing block maps), dir_index (htree-indexed directories for large dirs), journal for crash consistency, delayed allocation, and online defragmentation.

Journal modes control what the journal protects: - writeback — only metadata is journaled, data may be written before or after metadata. Fastest, least safe — can expose stale data in files after a crash. - ordered (default) — data written to disk before metadata journaled. Prevents stale data exposure. Good balance of safety and performance. - journal — both data and metadata are journaled. Safest, but doubles write I/O. Only useful for high-integrity requirements.

XFS

XFS is a high-performance 64-bit journaling filesystem originally from SGI. It excels at parallel I/O (multiple allocation groups enable concurrent writes), large files, and workloads with millions of files. It uses dynamic inode allocation — no fixed inode limit. xfs_repair replaces fsck; online defrag with xfs_fsr.

btrfs

btrfs is a copy-on-write (COW) filesystem with built-in RAID, snapshots, deduplication, and checksums. COW means writes never overwrite existing blocks — new data is written to free blocks, then the metadata updated atomically. This enables instant snapshots at zero cost.

Key concepts

ext4 journal modes
writeback = metadata only, fastest; ordered = data before metadata (default, safe); journal = data+metadata both journaled, safest but 2x write I/O.
tune2fs
Reads and modifies ext4 filesystem parameters. tune2fs -l /dev/sda1 prints all metadata. tune2fs -e remount-ro /dev/sda1 sets error behavior to remount read-only on detected errors.
XFS allocation groups
XFS divides the filesystem into allocation groups (typically 8). Each has its own free space B-tree and inode B-tree, enabling parallel allocation from multiple threads without lock contention.
xfs_repair
XFS consistency checker and repair tool. Unlike fsck.ext4, it does not need to be run routinely — XFS journal replays automatically. Run only after forced unmount or detected corruption. Requires unmounted filesystem.
btrfs COW
Copy-on-write: writes always go to new blocks. Old blocks remain until all references are released. Enables instant snapshots (just copy the root inode reference) and checksums (detected silently correctable errors).
xfs_freeze
xfs_freeze -f /mountpoint flushes all in-flight I/O and suspends writes. Used to create a crash-consistent snapshot of the underlying block device (LVM snapshot, EBS snapshot). Resume with xfs_freeze -u.

When to use it

  • New database server — XFS for parallel I/O, no fixed inode limit, and excellent large-file performance
  • Default /boot and system partitions on RHEL/Debian — ext4 is well-understood and universally supported
  • Snapshot-heavy workloads (CI build cache, container images on disk) — btrfs or ZFS for COW snapshots
  • Diagnosing filesystem errors — tune2fs -l to inspect ext4 state, xfs_info for XFS parameters
  • Recovery from XFS corruption — xfs_repair (requires unmounted filesystem)

Interview questions

  • How do you inspect and tune an ext4 filesystem? What does tune2fs show you?
  • When would you choose XFS over ext4 for a production server?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio