linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/File system/ext4

kb/filesystem ── File system ── intermediate

ext4: the Linux filesystem workhorse

ext4 is the default filesystem on most distributions: journaling, extents, a fixed inode count set at mkfs time. The main tunes are the data mode, noatime, and lazy init. Stable for 15+ years. Does not scale like XFS.

view as markdownaka: ext4-fs, ext4-journaling, ext4-tuning

Why ext4 specifically

ext4 is the default on Debian, Ubuntu, Linux Mint, Arch-based distributions, and many others. It is well understood, the tooling matured over 15 years, and it has the largest body of recovery cases. Compared to its predecessors:

VersionWhat it added
ext2 (1993)the base filesystem
ext3 (2001)journaling
ext4 (2008)extents, 1 EiB filesystem, 16 TiB files, online defrag, multi-block alloc

If the goal is "put any filesystem on it and forget about it", use ext4. If you have millions of small files or a single file in the terabyte range, look at xfs or btrfs.

Journaling

The main difference from ext2 is the journal. When metadata changes (inode, directories, bitmaps), the plan of changes is written to a circular journal first, then the changes themselves. A crash before the journal commit rolls back; a crash after it replays the journal and applies the changes.

Three modes, selected with mount -o data=...:

ModeWhat is journaledWhen
data=writebackmetadata only; data can hit the disk BEFORE or AFTER the metadatamaximum speed, with the risk that "a file points at someone else's blocks" after a crash
data=ordered (default)metadata after the data is flusheda compromise: metadata stays consistent with the data
data=journalboth metadata and data go through the journalmaximum safety, 2x slower

For a database it is sometimes worth using data=writeback, where the application WAL takes on crash-safety. For a container host, use the default.

The journal lives on the same filesystem in a special inode (8). You can move it to a separate fast disk:

bash
mke2fs -O journal_dev /dev/nvme0n1
mke2fs -t ext4 -J device=/dev/nvme0n1 /dev/sda1

Inode density is a fixed characteristic

At mkfs.ext4 time, the inode count is set to filesystem_size / bytes-per-inode. The default is 1 inode per 16 KiB. On a 1 TiB filesystem that is about 67M inodes by default.

What matters: you cannot add inodes after mkfs. df -i shows the usage. If you hit 100% inodes while gigabytes are still free, the only option is to recreate the filesystem.

For systems with millions of small files (a mail spool, a cache), raise the density:

bash
# 1 inode per 4 KiB - four times as many
mkfs.ext4 -i 4096 /dev/sdb1
# Or via a profile from /etc/mke2fs.conf
mkfs.ext4 -T news /dev/sdb1

For huge files (video, backups), lower it (-i 65536). You save space and speed up fsck.

Block size

The default is 4 KiB on x86. Sizes of 1, 2, and 4 KiB are supported. Do not change it without a reason:

  • 4K is the optimum for the kernel page size
  • <4K spends more overhead
  • 4K is not supported on x86 (on ARM/POWER you can use 16K, 64K)

noatime, relatime, lazytime

Under POSIX every read has to update atime (inode). That is a write on every read, which is lethal for performance.

OptionWhat it does
atime (default)atime on every read
relatimeatime updates if the previous value is < mtime/ctime, or older than a day
noatimenever touch atime
lazytimetimestamps live in cache only, flushed to disk once a day

For production, use noatime or lazytime. Modern distributions set relatime by default.

fstab
UUID=...  /  ext4  defaults,noatime,lazytime,errors=remount-ro  0 1

Useful mkfs/tune2fs options

bash
# Creation
mkfs.ext4 -L data -m 1 -E lazy_itable_init=1,lazy_journal_init=1 /dev/sdb1
  • -L LABEL sets the label
  • -m N sets the reserve for root (default 5%, which is 500GB on a 10TB disk!)
  • -E lazy_itable_init=1 does not zero the inode table at creation (much faster on large disks; a background process zeroes it later)
  • -O ^has_journal means no journal (only if you know why, for example: an external journal_dev is already set, or the partition is temporary)
  • -T usage_type accepts news, largefile, largefile4

Tuning an existing filesystem:

bash
tune2fs -l /dev/sda1                  # filesystem parameters
tune2fs -m 1 /dev/sda1                # lower reserved to 1%
tune2fs -L data /dev/sda1             # change the label
tune2fs -O ^has_journal /dev/sda1     # disable the journal (dangerous)
tune2fs -c 0 -i 0 /dev/sda1           # disable mount-count and time-based fsck

Online resize and shrink

ext4 supports grow and shrink on an unmounted filesystem:

bash
# Grow (online or offline)
resize2fs /dev/sda1                   # to the full partition size
resize2fs /dev/sda1 100G              # to 100 GiB
# Shrink (offline only)
umount /dev/sda1
e2fsck -f /dev/sda1                   # a mandatory check
resize2fs /dev/sda1 50G

Unlike xfs, which can only grow, this is a plus for ext4.

fsck

Only on an unmounted filesystem:

bash
umount /mnt/data
e2fsck -f /dev/sda1                   # -f forces it even on a "clean" filesystem
e2fsck -y /dev/sda1                   # -y answers "yes to everything" (for scripts)

For the root partition there is errors=remount-ro in fstab. On a filesystem error it remounts the volume read-only automatically. More in fsck-and-recovery.

When something goes wrong

  • No space left with free GB: you ran out of inodes (df -i). Delete small files or recreate the filesystem with -i 4096.
  • Read-only file system: errors=remount-ro triggered. Check dmesg | grep EXT4-fs for the cause. Often a bad sector.
  • Files gone after a crash: data=writeback without an [[mount-and-fstab|fsync]] from the application. Lessons: fsync(), O_DSYNC for critical data.
  • Very slow after mkfs on a large disk: lazy_itable_init=1 is still working in the background. dmesg | grep ext4 shows it.
  • tune2fs: Filesystem has unsupported feature(s): an old distribution does not know the feature. Check dumpe2fs -h /dev/sdX | grep features and update e2fsprogs.
  • 5% reserved bytes: on large disks use -m 1 or -m 0. The reserve is needed only on a root filesystem so that the system can keep running once it fills up.

Checking the state

bash
dumpe2fs -h /dev/sda1                 # the superblock without group details
debugfs -R 'stat <inode>' /dev/sda1   # details for a specific inode
filefrag -v /path/to/file             # fragmentation of a specific file
e4defrag /path                        # online defrag (rarely needed)

§ команды

bash
sudo mkfs.ext4 -L data -m 1 -E lazy_itable_init=1 /dev/sdb1

Create ext4 with a label, reserved=1%, without blocking on the zero-init of the tables

bash
sudo tune2fs -l /dev/sda1

All filesystem parameters: block size, mount count, last fsck, features

bash
df -i /

Inode usage (not GB), which often runs out before the space does

bash
sudo resize2fs /dev/sda1

Grow the filesystem to the full partition size (after a parted resize)

bash
sudo mount -o remount,noatime,lazytime /

Apply noatime+lazytime without a reboot, to test before editing fstab

bash
sudo e2fsck -f /dev/sdb1

Force-check an unmounted filesystem, mandatory before a resize

bash
sudo dumpe2fs -h /dev/sda1 | grep -i feature

List the enabled features, to check compatibility with older kernels

§ см. также

  • filesystemsFilesystems: ext4, xfs, btrfs, zfsext4 is the reliable default. xfs handles large files and parallel I/O. btrfs and zfs give you snapshots, checksums, and built-in RAID, but they are more complex.
  • inodeInodeAn inode is a filesystem record that holds metadata and pointers to a file's data blocks. The filename lives separately, in a directory, and simply points to the inode.
  • mount-and-fstabmount and /etc/fstab: attaching filesystems`mount` attaches a block device or filesystem to a mount point in the tree. `/etc/fstab` is the list of what to mount at boot.
  • fsck-and-recoveryfsck and recovery: checking and repairing a filesystemfsck, a check of an unmounted filesystem. e2fsck (ext), xfs_repair (XFS), btrfs check (btrfs). Journal replay at mount handles 90% of problems after a crash.
  • lvmLVM: Logical Volume ManagerLVM is a layer between [[block-devices]] and the filesystem: it pools disks and carves out logical volumes of any size that you can grow, snapshot, and migrate live.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies