Creating filesystems: ext4, XFS and Btrfs

Intermediate · 10 min

What mkfs writes, how ext4, XFS and Btrfs differ in ways that matter on a server, inodes and reserved blocks, and when fsck actually runs.

Before thisBlock devices and partitions

Red Hat Enterprise Linux · 10 min

Creating filesystems: ext4, XFS and Btrfs

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Red Hat Enterprise LinuxReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • mkfs writes a filesystem's metadata onto a block device: a superblock describing it, a journal, and tables for inodes and free space. It destroys whatever was there.
  • ext4 is the conservative default on Debian and Ubuntu. It can grow online and shrink offline, but its number of inodes is fixed when it is created.
  • XFS allocates inodes as needed and scales well with large files and parallel writes. It can grow online but cannot, in practice, be shrunk.
  • Btrfs is copy-on-write, with checksums on data, subvolumes, snapshots and compression built in. Its RAID5 and RAID6 modes are still marked unstable.
  • ext4 reserves 5% of blocks for root by default. On a large data volume that can be lowered with tune2fs -m.
  • Journaling filesystems recover at mount. ext4's full fsck is not run by mount count on modern defaults, and fsck.xfs does nothing at all. Repairs are done by hand, unmounted.

From blocks to files

The previous lesson ended with a partition: a numbered row of blocks with no structure. A filesystem is the bookkeeping that turns it into named files in directories. It has to record which blocks are free, which blocks belong to which file, who owns each file, and what the directory tree looks like. And it has to keep all of that consistent when the power goes out halfway through a write.

mkfs writes that bookkeeping onto an empty device. Think of it as ruling a blank ledger into columns before the first entry. It also means mkfs on the wrong device erases the old ledger, and with it everything the old filesystem knew. The computer science lesson on file systems covers inodes and journaling in general. This one is the three filesystems you will choose between on Linux.

A real ext4, from the inside

To see what mkfs leaves behind I read a real one. Debian’s official cloud image for Debian 13, debian-13-generic-amd64.raw, has an ext4 root partition starting at sector 262144. I fetched the 1,024 bytes of its superblock with an HTTP range request and decoded them with a Python script I wrote from the kernel’s ext4 on-disk format documentation, on this Mac:

magic: 0xef53
block size: 4096
blocks: 753408  inodes: 188416  free blocks: 548987  free inodes: 159366
blocks per group: 32768  inodes per group: 8192  inode size: 256
bytes of space per inode: 16378
reserved blocks: 37670 (5.0%)
UUID: fe1e0f01-84a0-404e-8a68-d010777f80a3
volume name: 
max mount count: -1  mount count: 1  check interval: 0
features: has_journal ext_attr resize_inode dir_index orphan_file filetype extent 64bit flex_bg metadata_csum_seed sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
mkfs time: 2026-11-23 04:36 UTC

What that says:

  • Inodes are fixed at creation. One inode for roughly every 16 KiB of space, 188,416 in total. An inode describes one file, so this filesystem can never hold more than 188,416 files, however much space is free. mke2fs(8) warns that the ratio cannot be changed afterwards. A mail spool or cache with millions of tiny files can run out of inodes with the disk half empty, which df -i shows.
  • 5% is reserved for root. The man page says this lets root-owned daemons keep working after ordinary users fill the disk. On a 4 TB data volume that is 200 GB, and tune2fs -m 1 can lower it.
  • The UUID is what /etc/fstab should refer to, the topic of the next lesson.
  • has_journal means metadata changes are written to a journal first, so after a crash the filesystem replays the journal instead of scanning everything. metadata_csum adds checksums to metadata. extent stores files as ranges of blocks rather than lists. 64bit allows very large volumes.
  • max mount count -1 means the old “full check every N mounts” is off.

ext4, XFS, Btrfs

ext4 XFS Btrfs
Inodes Fixed at mkfs Allocated as needed Allocated as needed
Grow Online Online, must be mounted Online
Shrink Offline only Not in practice Online
Checksums Metadata Metadata Metadata and data
Snapshots No, use LVM No, use LVM Built in
Default on Debian, Ubuntu RHEL family Fedora desktop, openSUSE

ext4 is the mature default. Its tools are tune2fs -l to read the superblock, as above, resize2fs, which resize2fs(8) says can enlarge a mounted ext4 but shrink only an unmounted one, and e2fsck.

XFS came from SGI for large files and parallel I/O, and allocates inodes dynamically, so it does not run out of them the way ext4 can. xfs_info shows its layout. xfs_growfs(8) grows a mounted filesystem. Shrinking is the catch: the man page notes only shrinking the last allocation group is implemented, which in practice means you cannot shrink XFS. Size it with that in mind, or put it on LVM and only ever grow.

Btrfs is copy-on-write: it never overwrites a block in place, it writes a new one and updates pointers. That makes snapshots nearly free and lets it checksum file data, so a btrfs scrub can find a silently corrupted block and repair it from a mirror. It has subvolumes, compression and its own RAID1 and RAID10. Fedora made it the default for desktop variants in Fedora 33. The Btrfs project’s own status page still lists RAID56 as unstable, so do not use its RAID5 or RAID6 for data you need.

Choose by need. A general server: whatever your distribution defaults to. Large files and heavy parallel writes: XFS. Snapshots and checksums without LVM: Btrfs.

Making one

From the man pages, not run here:

mkfs.ext4 -L data /dev/sdb1               # -i or -N to change the inode count
mkfs.xfs -L data /dev/sdb1
mkfs.btrfs -L data /dev/sdb1
tune2fs -l /dev/sdb1                       # ext4 superblock, like the output above
xfs_info /mnt/data                         # XFS geometry, on a mounted fs

mkfs refuses to overwrite an existing filesystem without -f in some tools and asks in others. Do not rely on it. Check with lsblk -f first.

When fsck runs

All three are journaling or copy-on-write, so the normal recovery after a crash is automatic at mount: replay the journal, done. A full check is for real corruption. At boot, systemd runs fsck for filesystems whose sixth field in /etc/fstab is non-zero. For XFS that does nothing: fsck.xfs(8) is literally described as “do nothing, successfully”, because XFS recovers at mount. To check XFS, unmount it and run xfs_repair -n to look, or xfs_repair to fix. For ext4, unmount and run e2fsck -f. Never run a repair on a mounted filesystem.

About the video

The embed is all of the Red Hat Enterprise Linux channel’s “XFS versus ext4 and which filesystem you should actually use”, December 2025, ten minutes, with manual English captions. Its description says XFS has been RHEL’s default since RHEL 7, explains why Red Hat switched, and covers checking block sizes, inode counts and reserved blocks with xfs_info, tune2fs and dumpe2fs, which matches the superblock reading above. It has no chapters, so I judged it from that description. It is Red Hat’s view of its own default, so weigh the conclusion with that in mind. It does not cover Btrfs, so the lesson does, with the Btrfs project’s own status page as the source. Chris Titus’s comparison in deeper includes Btrfs.

What was run: fetching the ext4 superblock from Debian’s official cloud image and decoding it with my own script, on macOS. Feature names were matched against the kernel’s ext4 superblock documentation. Everything else is from e2fsprogs and xfsprogs man pages on man7.org, the Btrfs status page and Fedora’s BtrfsByDefault change, checked 2026-11-28. The RHEL default of XFS is from the video’s own description.

Where this fits

A filesystem on a partition is still invisible until it is attached to the directory tree: mounting and fstab.

Check yourself

  1. 01`df -h` shows 40% free on an ext4 volume, yet creating files fails with 'No space left on device'. What do you check?

    `df -i`. The filesystem has run out of inodes, usually from millions of small files. ext4 cannot add inodes later, so the fix is cleaning up or recreating it with a lower bytes-per-inode ratio, or using XFS.

  2. 02You need to shrink a 2 TB volume to 1 TB. Which of ext4 and XFS allows it?

    ext4, unmounted, with resize2fs. XFS can only be grown, so it would have to be backed up, recreated smaller and restored.

  3. 03Why does an XFS root filesystem never get fsck'd at boot, and how do you check it?

    fsck.xfs deliberately does nothing, because XFS replays its log at mount. To check or repair, unmount it and run xfs_repair, or xfs_repair -n to only check.

  4. 04What does the 'metadata_csum' feature on an ext4 filesystem give you, and what does Btrfs add beyond it?

    Checksums on ext4's metadata, so corruption of its structures is detected. Btrfs checksums file data as well, so it can detect a silently corrupted block and, with a redundant copy, repair it.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark