Journaling & Crash Recovery

How Linux ext4 journals metadata and replays committed transactions after a crash, with limits on file-data durability and recovery guarantees.

published: reading time: 6 min read author: Geek Workbench updated: November 20, 2026
Quick Summary

How Linux ext4 journals metadata and replays committed transactions after a crash, with limits on file-data durability and recovery guarantees.

Journaling & Crash Recovery

An unexpected shutdown can interrupt a filesystem update. A journal records information that lets the filesystem replay certain committed updates when it is mounted again. This article focuses on Linux ext4; the mount-mode details below are ext4-specific.

For ext4, journaling primarily protects filesystem consistency. It does not guarantee that every application write or the latest file contents survive a crash. The details depend on the filesystem, its data mode, the kernel, and the storage device.

How the ext4 Journal Works

The ext4 journal uses JBD2, a journal layer also used by other Linux filesystems. A transaction is written to the journal and marked committed before its logged changes are applied to their final locations. If the system stops before a valid commit record is durable, recovery does not replay that transaction. If it stops after commit but before checkpointing is complete, recovery can replay the committed transaction.

This is a metadata-consistency mechanism. It helps avoid filesystem structures that reflect only half of a metadata update, such as a directory entry pointing to a block that the filesystem still marks as free.

The ext4 journal can detect some corrupted records with checksums when the relevant feature is enabled. A checksum detects corruption; it does not verify that an application wrote the right data or that a transaction completed at the application level.

ext4 Data Modes

The Linux kernel documentation describes three ext4 data modes. The default is data=ordered. These modes define how file data is ordered relative to journaled metadata; none is a general promise that an application’s complete update will survive a crash.

ext4 mode What is journaled or ordered Limit
data=ordered Metadata is journaled. Related file data is written to the main filesystem before the metadata commit. Recent application writes can still be lost if they were not made durable.
data=writeback Metadata is journaled, but file data writes are not ordered before the metadata commit. A crash can expose stale or incomplete file contents.
data=journal File data and metadata are written through the journal. This has higher write cost, does not provide application-level transactions, and current kernel documentation marks the mode deprecated for removal in January 2028.

The mode is selected by filesystem mount configuration. Check the kernel version and the Linux kernel ext4 documentation before changing it. The current documentation marks data=journal as deprecated, with support scheduled for removal in January 2028. Do not disable write ordering or storage flush behavior as a performance shortcut.

What Recovery Does and Does Not Mean

On a mount after an unclean shutdown, ext4 replays valid committed journal transactions and ignores incomplete or invalid records. This restores the filesystem structures covered by those transactions.

It does not mean:

  • Every write that an application issued reached stable storage.
  • A multi-file application update is atomic.
  • The latest file contents are intact.
  • Recovery always finishes within a fixed number of seconds.

Recovery time depends on the journal and filesystem state, storage, kernel, and amount of work required. A filesystem may mount cleanly while an application still needs to validate or rebuild its own data.

For durable application updates, use the application’s documented commit and synchronization mechanisms. A filesystem journal is not a replacement for application transactions, backups, or data validation.

For Java path and file-stream examples, see the Java I/O and NIO guide. That article covers Java APIs; this one covers ext4 journal recovery and does not imply that closing a stream alone makes application data durable.

Checking an ext4 mount

Record the kernel, e2fsprogs, filesystem, and mount options for the system you are investigating:

uname -r
e2fsck -V
findmnt --target /path/to/mount --noheadings --output SOURCE,FSTYPE,OPTIONS

The following output shape is illustrative; replace the placeholders with values from the target system. It is not the result of a crash-recovery test:

$ uname -r
6.x.y-<distribution-kernel-release>
$ e2fsck -V
e2fsck 1.47.x (<build date>)
$ findmnt --target /path/to/mount --noheadings --output SOURCE,FSTYPE,OPTIONS
/dev/vdb1 ext4 rw,relatime

If findmnt does not list a data= option, check the default for that system’s kernel rather than inferring a mode from this example. Mount options and version formats vary by distribution.

After an unexpected shutdown, kernel logs can help confirm whether recovery occurred or errors were reported. On systemd-based Linux systems, inspect the relevant messages with:

journalctl --dmesg --since "1 hour ago"

The exact messages depend on the kernel and the recovery path. Do not run filesystem repair tools against a mounted filesystem. If e2fsck is needed, follow the distribution’s recovery procedure on an unmounted filesystem, and preserve a backup or image before attempting repairs. Avoid disabling, clearing, or recreating a journal as a generic response to errors.

Testing Recovery Safely

A recovery test belongs on a disposable VM disk or filesystem image, never on a production volume or a disk with important data. The steps below describe a test plan; this article does not report results from a crash test.

  1. Record the Linux kernel version, e2fsprogs version, filesystem type, and mount options.
  2. Create a fresh ext4 test filesystem in an isolated VM and write a small workload with known committed and uncommitted records.
  3. Trigger an abrupt VM power-off at a controlled point, then boot the same image and inspect the kernel recovery messages.
  4. Check that the filesystem mounts and its metadata can be read. Separately verify which application records were durable.
  5. Restore a fresh copy of the test image before repeating the experiment with another mount mode.

A clean mount tests filesystem recovery. Comparing application records tests the durability behavior the application actually needs. Results from one kernel, virtual disk, and mode do not establish a guarantee for another environment.

Journaling and Other Filesystem Designs

Copy-on-write filesystems use a different update strategy: write changed blocks to new locations and then update references to them. Filesystems such as Btrfs and ZFS also have their own checksumming and recovery mechanisms. These designs can help with particular failure cases, but they do not make hardware failures or application-level data loss impossible. Review the filesystem’s own documentation and durability model.

Further Reading

Summary

Linux ext4 journaling helps recover filesystem metadata after an interrupted update. The default data=ordered mode orders related file data before metadata commits, but it does not promise that the latest application writes survive. Check the actual mode and kernel documentation, keep backups, and test recovery only on disposable storage.

Category

Related Posts

ASLR & Stack Protection

Explore ASLR, PIE, stack canaries, and NX on Linux with GCC, then inspect a harmless C program to see what each mitigation does and where it falls short.

#operating-systems #aslr-stack-protection #computer-science

Assembly Language Basics: Writing Code the CPU Understands

Learn x86-64 Linux assembly with the System V ABI: track registers, assemble and run a small program, debug it in GDB, then compare AArch64.

#operating-systems #assembly-language-basics #computer-science

Boolean Logic & Gates

Understanding AND, OR, NOT gates and how they combine into arithmetic logic units — the building blocks of every processor.

#operating-systems #boolean-logic-gates #computer-science