LinuxCommandLibrary

resize2fs

Resize ext2/3/4 file systems

TLDR

Automatically resize a filesystem to its maximum possible size

$ resize2fs [/dev/sdXN]
copy

Resize the filesystem to a size of 40G, displaying a progress bar
$ resize2fs -p [/dev/sdXN] [40G]
copy

Shrink the filesystem to its minimum possible size
$ resize2fs -M [/dev/sdXN]
copy

SYNOPSIS

resize2fs [ -fFpPMqQvS ] [ -b block-size ] [ -e errors_behavior ] [ -L label ] [ -l lazy_itable_init ] [ -I inode-size ] [ -s [ R ] ] [ -z number_of_blocks ] [ -U UUID ] device [ size ]

PARAMETERS

-f
    Forces the resize operation to proceed, even if resize2fs detects errors that would normally prevent it.

-F
    Flushes the filesystem device before beginning the resize operation.

-p
    Prints a progress bar during the operation, showing completion percentage.

-M
    Shrinks the file system to the minimum possible size, based on the amount of data stored.

-P
    Prints the minimum size (in filesystem blocks) to which the filesystem can be shrunk, and then exits.

-q
    Quiet execution. Suppresses some informational output.

-Q
    Very quiet execution. Suppresses almost all output.

-v
    Verbose execution. Provides more detailed output during the operation.

-b block-size
    Sets the block size of the file system. This option is rarely used and can be dangerous if not understood.

-e errors_behavior
    Sets the behavior when file system errors are detected. Similar to tune2fs.

-L label
    Sets the volume label of the file system after resizing.

-l lazy_itable_init
    Turns on or off lazy inode table initialization. '0' for off, '1' for on.

-I inode-size
    Changes the inode size. This operation can be very slow.

-s
    Causes resize2fs to attempt to shrink the filesystem.

-S R
    Attempts to spread the free blocks evenly across the filesystem after shrinking. 'R' is a ratio.

-z number_of_blocks
    Zeros out the unused blocks after shrinking the filesystem. This is typically used for security reasons.

-U UUID
    Sets the UUID of the file system after resizing.

device
    The path to the block device containing the ext2/ext3/ext4 file system (e.g., /dev/sda1, /dev/mapper/vg0-lv_data).

size
    The desired new size of the file system. Can be specified in blocks, or with suffixes like 'K', 'M', 'G', 'T' for KiB, MiB, GiB, TiB. If omitted, the file system will be expanded to fill the entire underlying partition/device.

DESCRIPTION

resize2fs is a utility that allows users to resize ext2, ext3, or ext4 file systems. It can be used to expand a file system to fill a larger underlying block device, or to shrink a file system to a smaller size.

When expanding, resize2fs can often be performed online (while the file system is mounted), which is a significant advantage for servers requiring high availability. The underlying block device (e.g., a partition or Logical Volume Manager (LVM) volume) must be expanded first to accommodate the larger file system.

When shrinking, the file system must first be unmounted to ensure data integrity, and it cannot be shrunk to a size smaller than the amount of data it currently holds. For shrinking, the underlying block device must be shrunk after the file system is shrunk.

This tool operates at the file system level and is frequently used in conjunction with disk partitioning tools like fdisk or parted, or logical volume managers like LVM (lvresize, pvresize) which manage the block device itself.

CAVEATS

Shrinking Requirements: When shrinking a file system, it must be unmounted first. Attempting to shrink a mounted file system will result in an error and potential data corruption. Ensure the target size is larger than the actual data used.

Underlying Device Management: resize2fs only modifies the file system itself. The underlying partition or logical volume must be resized separately using tools like fdisk, parted, lvresize, or pvresize. For expansion, resize the block device first, then the filesystem. For shrinking, resize the filesystem first (unmounted), then the block device.

Data Integrity: Although robust, any interruption (e.g., power loss, system crash) during a resize operation can lead to file system corruption. Always back up critical data before performing resize operations.

COMMON USAGE PATTERN WITH LVM

When using Logical Volume Management (LVM), the typical workflow for resizing involves two steps:

Expanding:
1. Expand the Logical Volume: lvresize -L + /dev/vg_name/lv_name
2. Expand the Filesystem: resize2fs /dev/vg_name/lv_name (can often be done online)

Shrinking:
1. Unmount the Filesystem: umount /mount/point
2. Shrink the Filesystem: resize2fs /dev/vg_name/lv_name
3. Shrink the Logical Volume: lvresize -L /dev/vg_name/lv_name
4. Mount the Filesystem: mount /dev/vg_name/lv_name /mount/point

HISTORY

resize2fs is a fundamental component of the e2fsprogs package, a collection of utilities for managing ext2, ext3, and ext4 file systems on Linux. Its development has closely paralleled the evolution of these file systems, gaining support for journaling (ext3) and later features like extents (ext4). A significant milestone was the introduction of online resizing capabilities (specifically, online expansion), which greatly improved its utility for mission-critical systems by minimizing downtime. It has been a standard and indispensable tool for Linux system administrators for decades.

SEE ALSO

e2fsck(8), mke2fs(8), tune2fs(8), fdisk(8), parted(8), lvresize(8)

Copied to clipboard