Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

Administer an ext4 file system

By updated

Improve this page

ext4 is the default file system of Debian and Ubuntu: stable, mature and versatile. This guide shows how to format a partition with mkfs.ext4, tune its parameters with tune2fs (root reserve, label), resize with resize2fs and check with fsck. For beginner to intermediate administrators. All outputs come from an AlmaLinux test disk; nothing is made up. The choice between ext4, XFS and Btrfs is covered in the dedicated decision guide.

What you will learn

  • Format a partition as ext4 with mkfs.ext4 and its useful options
  • Read and tune the parameters with tune2fs (root reserve, label)
  • Resize an ext4 with resize2fs
  • Check and repair with fsck / e2fsck

Prerequisites

Why ext4

ext4 (fourth extended filesystem) is the evolution of ext3/ext2. It is a journaled file system: it records metadata in a journal before applying it, which lets it get back to a consistent state after a power cut. Its assets: stability, wide compatibility, mature tools (fsck, tune2fs, e2label). Its limits: no native snapshots or compression, unlike Btrfs. For most servers and workstations, it is the simplest and safest choice.

Create an ext4 file system

Formatting writes the ext4 structure onto the partition. The basic command is mkfs.ext4, here with a label (-L) and a root reserve reduced to 1% (-m 1, see below):

Terminal window
sudo mkfs.ext4 -L donnees -m 1 /dev/sda1
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: e1015b55-7926-4e71-820a-c1180d169587
Allocating group tables: done
Writing inode tables: done

The output shows the number of blocks (4 KiB each), the number of inodes (fixed at creation, it caps the number of files) and the UUID that will be used for mounting.

Check the result

tune2fs -l shows the parameters of the file system created. It is the immediate check after formatting:

Terminal window
sudo tune2fs -l /dev/sda1
Filesystem volume name: donnees
Filesystem UUID: e1015b55-7926-4e71-820a-c1180d169587
Default mount options: user_xattr acl
Filesystem state: clean
Inode count: 65536
Block size: 4096
Reserved block count: 2621
Reserved blocks uid: 0 (user root)

The Filesystem state: clean field confirms a healthy system. You find the label, the UUID, the block size (4096 bytes, the default) and the blocks reserved for root (here 2621 blocks, that is 1% of the volume).

Tune ext4 for a data disk

By default, ext4 reserves 5% of the space for the superuser. On /, this margin prevents a user from filling the disk and blocking the system. On a pure data disk, these 5% are wasted: on 4 TB, that makes 200 GB unused. Adjust with tune2fs -m (the change is immediate, without reformatting):

Terminal window
sudo tune2fs -m 1 /dev/sda1 # reserve at 1%
sudo tune2fs -m 0 /dev/sda1 # no reserve at all (data only)

Change the label at any time with e2label, without unmounting:

Terminal window
sudo e2label /dev/sda1 data-prod

Mount options (performance, security) are set in /etc/fstab. The most useful ones:

OptionEffectFor
noatimedoes not write the access date on each readvery busy volumes
nodev,nosuid,noexechardens the mount/home, /tmp, external disks
errors=remount-roremounts read-only on errorall critical volumes
discardcontinuous TRIM on SSDSSD (or prefer fstrim.timer)

The complete configuration of /etc/fstab and mounting by UUID is detailed in the mount and persistence guide.

Resize with resize2fs

resize2fs adjusts the size of the ext4 file system. Growing is done online (volume mounted); shrinking requires unmounting first.

Before any shrink, resize2fs requires a full check of the file system as soon as the volume has been mounted since its last check. Without it, it refuses to work and prints Please run 'e2fsck -f /dev/sda1' first; the same requirement applies to an unmounted grow, only the online grow is exempt. The sequence, system unmounted, therefore takes two steps:

Terminal window
sudo e2fsck -f /dev/sda1
sudo resize2fs /dev/sda1 512M
The filesystem on /dev/sda1 is now 131072 (4k) blocks long.

Without a size, resize2fs extends the file system to all the available space in its container:

Terminal window
sudo resize2fs /dev/sda1

Check and repair with fsck

fsck (which calls e2fsck for ext4) detects and fixes inconsistencies after a sudden power cut or a disk error. Absolute rule: the file system must be unmounted (or read-only). e2fsck enforces it itself: on a mounted volume, it stops with /dev/sda1 is mounted. and e2fsck: Cannot continue, aborting. (exit code 8, measured with e2fsprogs 1.47). Do not try to work around this refusal: repairing a volume being written to would corrupt it.

Terminal window
sudo e2fsck -f -y /dev/sda1

The -f option forces the check even if the journal looks clean, and -y answers "yes" to every repair (otherwise e2fsck demands an interactive terminal). To repair a system volume, boot from a live medium so that the partition is unmounted.

Troubleshooting

ext4 failures can almost always be read in the message of the tool that refuses to act. The four lines below cover the most frequent cases: a repair run without a terminal, a disk full of inodes, the root reserve that "eats" space, and a volume remounted read-only after an error.

SymptomProbable causeSolution
e2fsck: need terminal for interactive repairsfsck without -y or -prerun with -y (automatic repair)
Disk "full" while df shows spaceinodes exhausted (millions of small files)df -i, delete or recreate with more inodes
5% of space "missing" on a data diskdefault root reservesudo tune2fs -m 0 /dev/sdX1
Volume remounted read-onlyerror detected + errors=remount-roe2fsck unmounted, check smartctl

Key points

  • mkfs.ext4 formats; -L sets a label, -m sets the root reserve (0 or 1 on a data disk).
  • tune2fs -l reads the parameters; Filesystem state: clean confirms a healthy volume.
  • tune2fs -m and e2label adjust reserve and label without reformatting.
  • resize2fs resizes: grow online, shrink unmounted; always container first, FS next.
  • e2fsck -f -y repairs, only unmounted; for the system, go through a live medium.
  • ext4 has neither native snapshots nor compression: for that, look at Btrfs.

Knowledge check

Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer

Is this project useful to you?

The guides, courses, quizzes and labs stay free. If you use them regularly, you can contribute to their upkeep and development.

Become a supporting member (new tab) One-time support (new tab) Learn more

Follow the project on LinkedIn