resize2fs Command

The resize2fs command is a utility for resizing ext2, ext3, or ext4 filesystems. It can be used to enlarge or shrink a filesystem, either online (while mounted) or offline (unmounted). This is particularly useful for managing disk space on Linux systems.

Syntax

resize2fs [OPTION]... <device> [SIZE]

Description

resize2fs works on the filesystem level, not the partition level. This means you typically need to resize the underlying partition first (using tools like fdisk, parted, or gparted) and then use resize2fs to adjust the filesystem to match the new partition size. It supports both growing and shrinking filesystems, though shrinking requires the filesystem to be unmounted and checked for errors first.

Common uses include:

  • Extending a filesystem after increasing the size of its partition.
  • Shrinking a filesystem to reduce the size of a partition.
  • Optimizing disk space usage.

Common Options

Option Description
-f Force the resize operation, even if errors are detected.
-F Flush the filesystem device before beginning.
-M Shrink the filesystem to the minimum possible size.
-p Print a percentage completion bar during the resize operation.
<device> The path to the device containing the filesystem (e.g., /dev/sda1).
[SIZE] The desired new size of the filesystem. Can be specified in blocks or with units (e.g., 10G, 500M).

Examples

Extend an ext4 filesystem to fill the partition

sudo resize2fs /dev/sda1

Extends the filesystem on /dev/sda1 to fill the entire partition. This is typically done after the partition itself has been enlarged.

Shrink an ext4 filesystem to a specific size

sudo umount /dev/sdb1 sudo e2fsck -f /dev/sdb1 sudo resize2fs /dev/sdb1 10G

Shrinks the filesystem on /dev/sdb1 to 10 Gigabytes. The filesystem must be unmounted and checked for errors before shrinking.

Extend an ext4 filesystem online (while mounted)

sudo resize2fs /dev/sdc1

If the kernel and filesystem support it, resize2fs can extend a mounted filesystem. Shrinking usually requires unmounting.

Shrink filesystem to minimum possible size

sudo umount /dev/sdd1 sudo e2fsck -f /dev/sdd1 sudo resize2fs -M /dev/sdd1

Shrinks the filesystem on /dev/sdd1 to its minimum possible size, freeing up unused space.

See also