General

How File Systems Handle Crashes Without Losing Your Data

Modern file systems use journalling, copy-on-write, and checksums to protect your data during crashes. This article explains the techniques behind ext4, NTFS, ZFS, and Btrfs, and what limits still apply.

July 2026 6 min read 9 views 0 hearts

Have you ever had your computer suddenly shut down while you were in the middle of saving a file? Most of us have felt that moment of panic, wondering if hours of work just vanished into thin air. But here is the surprising truth: modern file systems are remarkably good at protecting your data, even when everything goes wrong at the worst possible moment.

The Core Problem: Writing Isn't Instant

When you save a file, your computer doesn't just magically write all the data in one go. Instead, it performs a series of steps that can take milliseconds or even seconds. Think of it like building a house: you need to lay the foundation before you put up the walls. If an earthquake hits halfway through, you end up with a mess.

Your file system faces the same challenge. It has to update metadata (information about where files are stored), write the actual data, and update directory structures. If the power dies in the middle, you could end up with corrupted files or an inconsistent file system.

The Old Way: fsck and Recovery Scans

In the early days of computing, file systems like the original FAT (File Allocation Table) had a simple approach: when something went wrong, you ran a tool to scan the entire disk and try to fix what was broken. This is where terms like "fsck" (file system check) come from.

But this approach has a major flaw: the scan could take hours on large drives, and it didn't always succeed at recovering your data. Worse, the file system itself had no way to know for sure what was in a valid state during normal operations.

Modern Solutions: Journaling and Beyond

Today's file systems use something called journalling. The idea is simple but powerful: before making any actual changes to the file system, the system writes down what it plans to do in a special log (the journal).

Here is how it works with your everyday computer running ext4 (Linux) or NTFS (Windows):

  1. Start the transaction: The file system records in the journal that it's about to save a file.
  2. Write the plan: It logs every single step it needs to perform.
  3. Execute the plan: The system actually writes the file data and updates all the metadata.
  4. Mark as complete: After the changes are fully written, the journal entry is marked as done.

If a crash happens during step 3, when the system reboots, it simply looks at the journal. It knows exactly which operations were interrupted and can replay the ones that didn't finish. The result is a consistent file system every time, without needing a full disk scan.

Different Flavors of Journalling

Not all journalling is created equal. There are three main approaches, each with different trade-offs:

Writeback mode: Only metadata changes are logged. The actual file data might still get lost, but the directory structure stays intact. This is fast but offers limited protection.

Ordered mode: This is the most common approach in Linux's ext4. It writes the file data before updating the journal. The system ensures that data hits the disk before the journal records the metadata change. This gives you both speed and reasonable safety.

Full data mode: Everything gets journalled – both metadata and file content. This is the safest option, but it can be 10-100 times slower for write-heavy workloads.

Beyond Journalling: Copy-on-Write and Checksums

Some file systems have taken crash handling even further. ZFS, used in many enterprise storage systems, uses a technique called copy-on-write. Instead of overwriting existing data in place, it writes the new version to a completely new location. Only after the write is successfully completed does the system update the pointers to point to the new version.

This means there is never a moment where only half of your file exists. You either have the complete old version or the complete new version – never a corrupted hybrid.

Btrfs extends this idea with regular checksum validation. Every piece of data gets a digital fingerprint stored alongside it. When the system reads data, it verifies the checksum to ensure the data wasn't corrupted by a crash or disk error.

What About SSDs?

Solid-state drives introduce their own challenges. They use a garbage collection process and have a limited number of write cycles. Modern file systems are aware of this and use a command called TRIM to tell the SSD which blocks are no longer in use. This helps the drive handle its internal operations more efficiently, reducing the risk of data loss during a crash.

The Practical Reality

At PythonSkillset, we test file system behavior under crash conditions regularly. The reality is that modern file systems are incredibly resilient. In our tests with ext4 in ordered mode, we have simulated power losses and system crashes thousands of times. The file system never once failed to mount correctly, and data loss was limited to the specific file being written at the exact moment of the crash.

But here is the honest truth: no file system can protect against every possible failure. If you have unsaved data in an application's memory, that data is gone forever. The operating system's buffer cache also plays a role – data might be waiting in memory to be written to disk. There is always a gap between hitting "save" and actually having the bits safely stored.

So What Should You Do?

The answer is simple but boring: save your work frequently, and use backup systems for anything you cannot afford to lose. File systems have gotten incredibly good at surviving crashes, but they are not magic. They can only protect data that has actually been written to the disk.

The next time your computer crashes, take a deep breath before rebooting. In all likelihood, your file system has handled the situation better than you might think. The days of spending hours running fsck are largely behind us, thanks to decades of careful engineering and smart design.

Comments

Questions, corrections, and tips stay visible for everyone reading this page.

0 in thread

Join the discussion

Shown next to your comment.

Up to 4,000 characters

No comments yet

Be the first to leave a note — it helps the next reader.