Kahibaro
Discord Login Register

Filesystems (EXT4, XFS, Btrfs)

Overview: Why Multiple Filesystems?

On Linux you can choose from several mature local filesystems. For general-purpose servers and desktops today, the most common are:

They all store files and directories, but differ in:

This chapter focuses on what makes each of these three distinctive and how to choose and work with them at a basic administration level.


ext4

ext4 (“Fourth Extended Filesystem”) is the evolution of ext2 and ext3. It’s the “boring and reliable” choice, which is often desirable.

Key Characteristics

Features (high level):

What ext4 does not natively provide:

Creating and Checking ext4

Create a new ext4 filesystem:

mkfs.ext4 /dev/sdX1

Optionally label it:

mkfs.ext4 -L mydata /dev/sdX1

Check and repair:

fsck.ext4 /dev/sdX1
# or the generic:
fsck /dev/sdX1

Filesystem tuning (example: disable last access time updates to reduce writes):

tune2fs -o noatime /dev/sdX1

View basic information:

tune2fs -l /dev/sdX1

When ext4 Is a Good Choice

XFS

XFS is a high-performance, 64-bit journaling filesystem originally developed by SGI. It’s tuned for scalability and parallelism.

Many enterprise-focused distributions (e.g., RHEL) use XFS as their default filesystem for general use.

Key Characteristics

Limitations and caveats:

Creating and Checking XFS

Create an XFS filesystem:

mkfs.xfs /dev/sdX1

Label (during creation):

mkfs.xfs -L mydata /dev/sdX1

Check and repair:

xfs_repair /dev/sdX1

You typically do not run xfs_repair on a mounted filesystem. It’s often run from a rescue environment or after the filesystem has been force-unmounted.

Get information about the filesystem:

xfs_info /mount/point

Growing XFS

XFS supports online growth when the underlying block device has been expanded (e.g., you extended an LVM logical volume).

Example:

  1. Extend the block device (done with other tools, such as LVM).
  2. Grow the filesystem:
   xfs_growfs /mount/point

The filesystem grows to use the extra space.

When XFS Is a Good Choice

Btrfs

Btrfs (“B-tree filesystem”) is a modern, copy-on-write filesystem designed to bring advanced features directly into the filesystem layer.

It is feature-rich and flexible but also more complex to understand and administer correctly.

Key Characteristics

Core ideas:

This allows advanced workflows without additional layers like LVM for many use cases.

Copy-on-Write and Checksums

With CoW:

Btrfs calculates checksums (e.g., CRC32C) for data and metadata:

Subvolumes and Mounting

A Btrfs filesystem can contain multiple subvolumes. Conceptually:

Example creation:

# Create a Btrfs filesystem on a device
mkfs.btrfs -L mybtrfs /dev/sdX1
# Mount it
mount /dev/sdX1 /mnt
# Create subvolumes
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home

You might then mount them separately:

mount -o subvol=@ /dev/sdX1 /         # root filesystem
mount -o subvol=@home /dev/sdX1 /home

Many modern Btrfs-based distros use this scheme by default for easier snapshotting and system rollbacks.

List subvolumes:

btrfs subvolume list /mnt

Snapshots

Snapshots in Btrfs are:

Create a snapshot (read-only):

btrfs subvolume snapshot -r /mnt/@ /mnt/@_snap_before_upgrade

Create a read-write snapshot:

btrfs subvolume snapshot /mnt/@ /mnt/@_test

You can mount a snapshot as you would any other subvolume, enabling you to:

Snapshot management strategy is often combined with package managers and bootloader entries, but that integration is handled by other tools and is beyond this chapter.

Transparent Compression

Btrfs allows on-the-fly compression, which can:

Common algorithms: zstd, lzo, zlib.

Mount with compression (example):

mount -o compress=zstd /dev/sdX1 /mnt

You can check per-file compression using btrfs filesystem df and other tools.

Multi-Device and RAID

Btrfs can manage multiple devices directly, providing RAID-like functionality:

Add a device:

btrfs device add /dev/sdY1 /mnt

Change data/metadata profile (e.g., to RAID1 for redundancy):

btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt

Balance re-distributes data/metadata across devices according to the selected profile.

Because these features are powerful and potentially dangerous if misused, you should consult up-to-date documentation and understand the implications before configuring Btrfs RAID in production.

Scrubbing and Self-Healing

A scrub walks the filesystem, reading data and metadata, checking checksums, and trying to repair corrupted blocks using redundant copies when available.

Run a scrub:

btrfs scrub start -Bd /mnt

Options:

This is an important maintenance operation on Btrfs, especially when using multiple devices and relying on its data integrity features.

Creating and Checking Btrfs

Create:

mkfs.btrfs /dev/sdX1

Check:

Basic info:

btrfs filesystem df /mnt
btrfs filesystem usage /mnt

When Btrfs Is a Good Choice

Btrfs is more complex than ext4, so it’s helpful to start with non-critical data or distributions that ship good defaults and tooling around it.


Comparing ext4, XFS, and Btrfs (High-Level)

This is not an exhaustive performance comparison, but a practical “feel” for when each is appropriate:

Practical Tips for Choosing

In many real-world scenarios:

Regardless of the filesystem:

Views: 22

Comments

Please login to add a comment.

Don't have an account? Register now!