What is difference between Ext2 ext3 and ext4?

Ext2, Ext3, and Ext4 are all file system formats used commonly on Linux systems. They were each designed and released at different points in time and have evolved to offer improved features and functionality over their predecessors. Understanding the key differences between them can help you determine the best option for your Linux installation.

Background on Ext2, Ext3, and Ext4

Ext2 stands for “second extended file system” and was introduced in 1993. It offered improvements over the earlier Ext file system including support for larger file sizes and volumes and faster operations. However, Ext2 lacked a journaling feature which could help prevent file system corruption in the event of a crash or improper shutdown.

Ext3, released in 2001, provided journaling capabilities to improve reliability compared to Ext2. It essentially adds a journaling layer on top of Ext2 but maintains compatibility with most Ext2 drivers and tools. The journal helps quickly recover the file system structure following an unexpected crash.

Ext4 arrived in 2008 with Linux kernel 2.6.28. It provided further enhancements for storage limits, performance, and reliability. Key new features included:

  • Support for volumes and files up to 1 exbibyte (EiB) and 16 tebibytes (TiB) respectively
  • Faster file system checks and delays metadata updates to boost performance
  • Allocation improvements including multi-block allocations, delayed allocation, persistent preallocation, and extended attributes
  • Improved timestamps up to nanosecond resolution

The Ext4 file system is commonly used and recommended as the default for many Linux distributions today. However, both Ext2 and Ext3 remain in widespread use, especially for older systems.

Key Feature Differences

Here is a comparison of some of the most important differences between Ext2, Ext3, and Ext4 file systems:

Feature Ext2 Ext3 Ext4
Release Date 1993 2001 2008
Journaling No Yes Yes
Max File Size 2 TiB 2 TiB 16 TiB
Max Volume Size 2 TiB 2 TiB 1 EiB
Filesystem Checks Slower Faster than Ext2 Fastest

A few key points stand out from this top-level comparison:

  • Ext3 adds journaling capabilities on top of the Ext2 file system for improved reliability.
  • Ext4 provides large boosts to maximum file and volume sizes over its predecessors.
  • File system checks are much faster with Ext4 compared to Ext2 and Ext3.

Journaling and Reliability

One of the most critical differentiators between these file systems is journaling support. A journaling file system keeps track of changes that will be made to the file system structure before they are actually committed. It functions as a log to track both metadata and data updates.

How does journaling improve file system reliability? If an unexpected event like a crash or power loss occurs, the file system can use the journal to quickly recover. It will rerun the changes that were logged right before the abrupt stoppage. This avoids the need for a full scan and lengthy integrity check of the entire file system.

Ext3 introduced journaling capabilities to improve reliability compared to Ext2. However, tests have shown that Ext3’s journaling implementation can incur noticeable overhead and performance tradeoffs. Ext4 provides improved performance by delaying certain types of metadata updates until a transaction commit.

Improved Performance

In addition to enhanced reliability, Ext4 also delivers superior performance compared to Ext2 and Ext3. Some of the key performance improvements include:

  • Delayed allocation – Ext4 delays actually allocating disk blocks until the data is flushed to disk rather than during a write. This avoids unnecessary disk writes when data is being overwritten frequently.
  • Faster filesystem checks – The new block allocation schemes and delayed allocation in Ext4 significantly improve performance when checking disk integrity.
  • Multiblock allocation – Ext4 allocates multiple blocks at once rather than each block individually. This reduces overhead when writing large sequential files.
  • Persistent preallocation – Ext4 can preallocate contiguous blocks for a file so the filesystem does not have to allocate them later as the file grows. This helps with fragmentation.

In general, Ext4 provides more efficient allocation and layout schemes to boost both throughput and reduced latency compared to previous versions.

Larger Volume and File Sizes

A key benefit of Ext4 over Ext2 and Ext3 is substantially increased support for huge volumes and file sizes. Here are the maximums for each file system:

  • Ext2 – 2 TiB volume, 2 TiB file size
  • Ext3 – 2 TiB volume, 2 TiB file size
  • Ext4 – 1 EiB volume, 16 TiB file size

The Ext4 limits are large enough to accommodate even the needs of data centers and servers today. The bump from 2 TiB to 16 TiB max file size removes a practical barrier for storing very large files, including videos and database files, on Linux using the Ext4 file system.

When to Use Each File System

Given the evolution across these 3 file systems, when should you use each one? Here are some general guidelines:

  • Ext2 – Use for flash memory devices or small volumes where performance matters more than data integrity. The lack of journaling has minimal impact with smaller chance of corruption.
  • Ext3 – Default option for Linux distributions released before 2008. Still adequate for general use cases focused on reliability over best performance.
  • Ext4 – Recommended for most installations today. Delivers best all-around performance and features for modern systems and use cases.

However, there are cases where Ext3 may still be a preferred option over Ext4 when reliability and stability are critical. For example, databases that cannot tolerate the slight risk of corruption defects in some Ext4 implementations may be better suited for Ext3.

Converting Between File Systems

It is possible to convert between Ext2, Ext3, and Ext4 file systems in both directions. However, data loss is possible so appropriate backups should be taken.

Here is an overview of the conversion processes:

  • Ext2 to Ext3 – A simple tunefs command flips the metadata bitmaps to enable journaling. e2fsck should be run first to ensure a clean file system.
  • Ext3 to Ext2 – Similar to above, tune2fs flips off journaling and e2fsck should be run subsequently.
  • Ext2/Ext3 to Ext4 – The tune4fs command updates the metadata to Ext4 format. Resize2fs can enlarge capabilities and e2fsck checks integrity.
  • Ext4 to Ext2/Ext3 – Tune4fs turns off Ext4 features, resize2fs shrinks if needed, and e2fsck verifies.

There are some potential challenges to watch out for when converting:

  • If converting Ext2/3/4 to Ext2, latent corruption errors may surface since journal checksums are cleared.
  • Converting Ext3/4 to Ext2 eliminates fault tolerance provided by journaling.
  • Reducing volume sizes can be slow with data needing copied and fragmentation cleaned up.
  • Converting Ext4 volumes to Ext2/3 requires Linux kernel 2.6.18 or later.

To convert in Linux, backup data, unmount the targeted partition, run the necessary commands, then remount it. Reboot and verify normal operations.

Conclusion

Ext2, Ext3, and Ext4 provide an evolutionary path in Linux file system technology. Each successor offered reliability, performance, and storage improvements over its predecessor. Key enhancements included:

  • Ext3 adding metadata journaling for better data integrity compared to Ext2
  • Ext4 boosting file size limits by 8x and volume sizes by 500x over Ext2/3
  • Allocation and structure optimizations in Ext4 for faster performance

For most modern Linux installations, Ext4 is the recommended choice today for its robust feature set. However, Ext3 remains a reliable option for environments that favor stability over more advanced capabilities. And Ext2 is still usable in small volumes or for flash memory where journaling is unnecessary. All three file systems will continue evolving to support Linux growth for years to come.