EXT4 Explained
ext4 (Fourth Extended File System) has been the default Ubuntu file system since Ubuntu 9.10. It improved upon ext3 by adding extents (contiguous block allocation), delayed allocation, a larger maximum file and volume size, and faster fsck. For most workloads on Ubuntu servers, ext4 is the right choice — it is extremely well-tested, has comprehensive tooling, and performs well for both small and large files.
ext4 features and internals
| Feature | What it means in practice |
|---|---|
| Extents | Allocates contiguous ranges of blocks for large files (faster than ext3 block lists) |
| Delayed allocation | Batches disk writes for better layout; can cause data loss on crash without proper sync |
| Journaling | Recovers metadata after crash; data mode options: ordered (default), writeback, journal |
| dir_index | HTree index for directories with thousands of files (fast lookup) |
| 64-bit support | Supports up to 1 EiB volumes and 16 TiB files |
| Online resizing | Can grow a mounted ext4 volume with resize2fs |
Creating an ext4 file system
# Create ext4 on a partition
sudo mkfs.ext4 /dev/sdb1
# Create with a label (useful for mounting by label)
sudo mkfs.ext4 -L data /dev/sdb1
# Create with custom inode ratio
# Default: 1 inode per 16KB — too few for directories with millions of small files
# Increase for mail servers, session stores, etc.
sudo mkfs.ext4 -i 4096 /dev/sdb1 # 1 inode per 4KB (4x more inodes)
# Create with specific block size (4096 is standard)
sudo mkfs.ext4 -b 4096 /dev/sdb1
# Verify the new file system
sudo tune2fs -l /dev/sdb1
Tuning ext4
# View current ext4 settings
sudo tune2fs -l /dev/sda1 | grep -E "Mount count|Check interval|Features|Block size|Inode"
# Set a volume label
sudo tune2fs -L mydata /dev/sdb1
# Disable automatic fsck on mount count (on servers with UPS/clean shutdowns)
sudo tune2fs -c 0 -i 0 /dev/sda1
# Set reserved blocks percentage (default is 5% reserved for root)
# Reduce to 1% on large data volumes to reclaim space
sudo tune2fs -m 1 /dev/sdb1
# Enable discard (TRIM) support for SSDs
# Either: mount with discard option (fstab), or run periodic fstrim
sudo fstrim / # Manual TRIM for SSD
# Or add to cron:
# 0 0 * * 0 root fstrim -av
# Check and set journaling mode
sudo tune2fs -O journal_data_ordered /dev/sda1 # Default (safe)
sudo tune2fs -O journal_data_writeback /dev/sda1 # Faster, less safe
Checking and repairing ext4
⚠️ WARNING: Never run
fsckon a mounted file system. It will corrupt data. Always unmount first, or use a live environment or rescue mode for the root partition. Boot into recovery mode to run fsck on/.
# Check a file system WITHOUT making changes (safe on mounted FS for diagnostics)
sudo fsck -n /dev/sdb1
# Full check and automatic repair (requires UNMOUNTED file system)
sudo umount /dev/sdb1
sudo fsck -y /dev/sdb1 # -y auto-answers yes to all repair prompts
# Force a check on next boot (for the root partition)
sudo touch /forcefsck
# or
sudo tune2fs -C 1000 /dev/sda1 # Set mount count high to trigger check
# View fsck history and when last check ran
sudo tune2fs -l /dev/sda1 | grep -E "Last checked|Mount count|Maximum mount"
Common ext4 issues
# Issue: "No space left on device" but df -h shows free space
# Cause: inode exhaustion
df -i / # Check inode usage
# Count files in a directory (to find which dir has millions of files)
find / -xdev -printf '%h
' | sort | uniq -c | sort -rn | head -10
# Issue: ext4 file system shows errors but disk seems OK
# Cause: journal corruption
sudo dmesg | grep -i "ext4\|error\|corrupt"
sudo tune2fs -l /dev/sda1 | grep "Filesystem state"
# Issue: File system read-only after crash
# Cause: journal replay failed, FS mounted read-only for safety
dmesg | grep "remounting filesystem read-only"
# Fix: unmount, run fsck, remount
sudo umount /data && sudo fsck -y /dev/sdb1 && sudo mount /data
Conclusion
ext4 works well for Ubuntu system partitions and most data storage without any special tuning. The main things to adjust on production systems: reduce reserved blocks from 5% to 1% on large data volumes (tune2fs -m 1), increase inode density (mkfs.ext4 -i 4096) for directories with millions of small files, and enable periodic TRIM (fstrim) for SSD volumes. Always unmount before running fsck.
FAQ
Why should administrators understand EXT4 Explained?+
Because this topic affects planning decisions, server lifecycle, compatibility, support expectations, or how you reason about Ubuntu systems before making operational changes.
Do I need a lab for this topic?+
A lab is useful for checking commands and seeing the concept on a real Ubuntu machine, but the main value is understanding the decision, tradeoff, or system behavior clearly.
How should I use this knowledge in production?+
Use it to make better choices, document why those choices were made, and avoid rushed changes that ignore support windows, compatibility, stability, or operational risk.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support