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.ext4and 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
- A partition created and the right disk identified
- The
e2fsprogspackage (installed by default on every distribution)
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):
sudo mkfs.ext4 -L donnees -m 1 /dev/sda1Creating filesystem with 262144 4k blocks and 65536 inodesFilesystem UUID: e1015b55-7926-4e71-820a-c1180d169587Allocating group tables: doneWriting inode tables: doneThe 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:
sudo tune2fs -l /dev/sda1Filesystem volume name: donneesFilesystem UUID: e1015b55-7926-4e71-820a-c1180d169587Default mount options: user_xattr aclFilesystem state: cleanInode count: 65536Block size: 4096Reserved block count: 2621Reserved 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):
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:
sudo e2label /dev/sda1 data-prodMount options (performance, security) are set in /etc/fstab. The most useful ones:
| Option | Effect | For |
|---|---|---|
noatime | does not write the access date on each read | very busy volumes |
nodev,nosuid,noexec | hardens the mount | /home, /tmp, external disks |
errors=remount-ro | remounts read-only on error | all critical volumes |
discard | continuous TRIM on SSD | SSD (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:
sudo e2fsck -f /dev/sda1sudo resize2fs /dev/sda1 512MThe 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:
sudo resize2fs /dev/sda1Check 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.
sudo e2fsck -f -y /dev/sda1The -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.
| Symptom | Probable cause | Solution |
|---|---|---|
e2fsck: need terminal for interactive repairs | fsck without -y or -p | rerun with -y (automatic repair) |
Disk "full" while df shows space | inodes exhausted (millions of small files) | df -i, delete or recreate with more inodes |
| 5% of space "missing" on a data disk | default root reserve | sudo tune2fs -m 0 /dev/sdX1 |
| Volume remounted read-only | error detected + errors=remount-ro | e2fsck unmounted, check smartctl |
Key points
mkfs.ext4formats;-Lsets a label,-msets the root reserve (0 or 1 on a data disk).tune2fs -lreads the parameters;Filesystem state: cleanconfirms a healthy volume.tune2fs -mande2labeladjust reserve and label without reformatting.resize2fsresizes: grow online, shrink unmounted; always container first, FS next.e2fsck -f -yrepairs, 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
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
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Administer an XFS file system
A new full quiz with random questions
Work again only on the questions you missed