Where to start First steps track · 15 stages
Linux Labs

resize2fs / xfs_growfs — growing a filesystem

4 min e2fsprogs · xfsprogs

Grow ext4/xfs after a volume grows — online growth, shrinking only on ext4 offline.

Cheat sheet

6 commands Printable version
  • sudo lvextend -L +10G /dev/labvg/data grow the volume first (see lvm)
  • sudo resize2fs /dev/labvg/data ext4: fill all free space in the volume
  • sudo resize2fs /dev/labvg/data 20G ext4: to a specific size
  • sudo xfs_growfs -d /data xfs: mountpoint, not the device!
  • sudo lvextend -r -L +10G /dev/labvg/data volume + filesystem in one command
  • df -h /data check the result

Overview

After lvextend (or growing a cloud disk's partition), the block device has more free space, but the filesystem on it doesn't — not until you grow it with a separate command:

  • ext4/ext3/ext2 → resize2fs, grows online (on a mounted filesystem).
  • xfs → xfs_growfs, also online, but it takes the mountpoint, not the device name.

lvextend -r does both steps in one command (see lvm) — but it's worth knowing them separately: a cloud disk grows the same way, and so does a filesystem that isn't on LVM at all.

Options

6

Below are the main flags of resize2fs and xfs_growfs; the full list is in man resize2fs/man xfs_growfs.

Option What it does Example
-d SIZE Grow the data section (the part of XFS you can never shrink back). xfs_growfs -d /data
-p Show progress while resizing. resize2fs -p /dev/labvg/data
SIZE SIZE Target size (K/M/G/T); with no argument, grow to fill the partition/LV. resize2fs /dev/labvg/data 20G
-n Report the current filesystem geometry without changing anything. xfs_growfs -n /data
-M Shrink the filesystem to the smallest size it can be (before shrinking the volume). dangerous resize2fs -M /dev/labvg/data
-f Force the resize even if the filesystem was not unmounted cleanly. dangerous resize2fs -f /dev/labvg/data

Nothing found. Try a shorter query.

Recipes

3

ext4: resize2fs

bash
sudo lvextend -L +10G /dev/labvg/data
sudo resize2fs /dev/labvg/data              # no size — fill all free space
df -h /data

xfs: xfs_growfs

bash
sudo lvextend -L +10G /dev/labvg/data
sudo xfs_growfs -d /data                    # mountpoint, not /dev/labvg/data!
df -h /data

Both steps at once

bash
sudo lvextend -r -L +10G /dev/labvg/data    # grow the volume and resize2fs/xfs_growfs right away

Troubleshooting

4

xfs_growfs: "specified file is not on device"

You passed the device name (/dev/labvg/data) instead of the mountpoint. xfs_growfs takes the mount path (/data), unlike resize2fs.

df -h doesn't show the new size after lvextend

The volume grew, but the filesystem didn't yet: the separate resize2fs/ xfs_growfs step (or lvextend -r) is missing.

resize2fs: "New size smaller than minimum"

The target size is smaller than the data already on the filesystem. Find the minimum: sudo resize2fs -P /dev/labvg/data (in filesystem blocks).

The resize hangs or complains about space

Free space is needed at the volume group level, not just the logical volume: sudo vgs (free space in the VG) and sudo lvs — if the VG is empty, vgextend/add a disk first (see lvm).

Danger zone

2

XFS can only grow, never shrink

xfs_growfs has no reverse operation: shrinking XFS is not possible with standard tools at all. To reduce a partition holding XFS, create a smaller filesystem and migrate the data (back up, mkfs.xfs, restore) — there's no shortcut.

Shrinking ext4 — offline, and with margin

resize2fs can shrink ext4, but only on an unmounted filesystem and before shrinking the volume itself (lvreduce), never after — otherwise it truncates live data. Run e2fsck -f first (see filesystems) and back up beforehand: a wrong size calculation corrupts the filesystem irreversibly.

See also

  • lvm — PV → VG → LV; flexible disk management, extending and snapshots.
  • mount — Mounting and fstab — mountpoints, UUIDs, bind mounts and tmpfs.
  • disk-usage — Where did the space and inodes go — df, du, finding large files.
Loading…