LinuxCommandLibrary

lvresize

Resize logical volumes

TLDR

Change the size of a logical volume to 120 GB

$ lvresize [[-L|--size]] 120G [volume_group]/[logical_volume]
copy

Extend the size of a logical volume as well as the underlying filesystem by 120 GB
$ lvresize [[-L|--size]] +120G [[-r|--resizefs]] [volume_group]/[logical_volume]
copy

Extend the size of a logical volume to 100% of the free physical volume space
$ lvresize [[-l|--extents]] 100%FREE [volume_group]/[logical_volume]
copy

Reduce the size of a logical volume as well as the underlying filesystem by 120 GB
$ lvresize [[-L|--size]] -120G [[-r|--resizefs]] [volume_group]/[logical_volume]
copy

SYNOPSIS

lvresize [options] {LogicalVolumePath} [-L|--size [+|-]Size[bBsSkKmMgGtTpPeE]] [-l|--extents [+|-]Extents[%VG|%LV|%ORIGIN|%FREE|%PVS|%PVS_FREE]]

PARAMETERS

LogicalVolumePath
    The full path to the logical volume to be resized (e.g., /dev/vg_name/lv_name).

-L, --size Size
    Sets the new absolute or relative size of the logical volume. Size can be specified with units (e.g., 10G, 512M). Use + or - prefix for relative resizing.

-l, --extents Extents
    Sets the new absolute or relative size of the logical volume in logical extents. Can use percentages (e.g., 100%FREE, 50%VG).

-r, --resizefs
    Resize the filesystem on the logical volume as part of the lvresize operation. This is highly recommended for safety.

-f, --force
    Bypass confirmation prompts and potential warnings, proceeding with the operation immediately. Use with caution.

-t, --test
    Perform a dry run. Show what would be done without actually making any changes.

-i, --intervals ReportInterval
    Report progress at intervals during a resize operation.

-y, --yes
    Assume 'yes' to all prompts, effectively disabling interactive confirmation.

--fs FileSystemType
    Specify the filesystem type on the logical volume if it cannot be detected automatically (e.g., ext4, xfs).

DESCRIPTION

lvresize is a command-line utility used to change the size of a Logical Volume (LV) within the Linux Logical Volume Manager (LVM) framework. It allows administrators to either grow (expand) or shrink (reduce) an existing logical volume, providing significant flexibility in storage management. When growing an LV, lvresize extends it into available free space within its parent Volume Group (VG). Conversely, when shrinking, it reduces the LV's size, potentially freeing space back to the VG.

A critical feature of lvresize is its ability to integrate with the filesystem residing on the logical volume. With the --resizefs (or -r) option, lvresize can automatically resize a supported filesystem (like ext2/3/4, XFS, Btrfs) simultaneously with the LV. This ensures data integrity and prevents data loss. Careful consideration and backups are paramount when shrinking an LV, especially if the new size is smaller than the data stored on the filesystem, as it can lead to data corruption.

CAVEATS

  • Shrinking Data Loss Risk: Shrinking an LV without properly resizing the filesystem first, or shrinking it to a size smaller than the data stored on the filesystem, will lead to irreparable data loss. Always backup critical data before shrinking.
  • Filesystem Compatibility: While --resizefs is powerful, not all filesystems support online shrinking (e.g., XFS cannot be shrunk online). Always verify filesystem capabilities.
  • Insufficient Space: When growing an LV, ensure there is sufficient free space in the Volume Group to accommodate the new size.
  • Performance: Very large resize operations, especially when moving data, can be time-consuming and impact system performance.

FILESYSTEM RESIZING SPECIFICS

The behavior of --resizefs depends on the filesystem type:

  • For ext2/3/4 filesystems, lvresize -r can both grow and shrink the filesystem.
  • For XFS filesystems, lvresize -r will only grow the filesystem. Shrinking XFS online is generally not supported; it typically requires backing up data, reformatting, and restoring.
  • For Btrfs, it supports both grow and shrink operations with lvresize -r.
Always consult the filesystem's documentation for precise resizing capabilities and limitations.

SAFETY BEST PRACTICES

Before undertaking any significant resize operation, particularly when shrinking a logical volume:

  • Backup Data: Always ensure you have a complete and verified backup of all critical data on the logical volume.
  • Check Filesystem: It's good practice to run a filesystem check (e.g., e2fsck -f for ext2/3/4, or verify XFS integrity) before shrinking to ensure no underlying filesystem issues.
  • Monitor Progress: For long operations, use the -i option to monitor progress.

RELATIVE RESIZING

You can specify sizes relative to the current LV size, the Volume Group's free space, or other metrics:

  • +5G: Add 5 Gigabytes to the current LV size.
  • -100M: Remove 100 Megabytes from the current LV size.
  • 100%FREE: Extend the LV to consume all available free space in the Volume Group.
  • 50%VG: Set the LV size to 50% of the total Volume Group size.

HISTORY

lvresize is an integral command within the Logical Volume Manager (LVM) framework, which became a standard component of the Linux kernel in the early 2000s. Its development has mirrored the evolution of LVM, gaining new features like support for thin provisioning, snapshot resizing, and enhanced filesystem integration. The ability to dynamically adjust storage allocations provided by commands like lvresize has been fundamental to flexible and efficient server and storage management on Linux.

SEE ALSO

Copied to clipboard