LinuxCommandLibrary

lvreduce

Reduce the size of a logical volume

TLDR

Reduce a volume's size to 120 GB

$ lvreduce [[-L|--size]] [120G] [logical_volume]
copy

Reduce a volume's size by 40 GB as well as the underlying filesystem
$ lvreduce [[-L|--size]] -[40G] [[-r|--resizefs]] [logical_volume]
copy

SYNOPSIS

lvreduce { -L | --size [+]Size[bBsSkKmMgGtTpPeE] | -l | --extents [+]LogicalExtents[%{VG|LV}] } [ --poolmetadatasize Size[bBsSkKmMgGtTpPeE] | --poolmetadatapercent Percent ] [ -r | --resizefs ] [ -f | --force ] [ -t | --test ] [ -y | --yes ] LogicalVolumePath

PARAMETERS

-L, --size Size[bBsSkKmMgGtTpPeE]
    Specify the new exact size for the logical volume, or the amount to reduce by if preceded by '+'. Suffixes like 'm' (MB) or 'g' (GB) are supported.

-l, --extents LogicalExtents[%{VG|LV}]
    Specify the new size in logical extents, or the number of extents to reduce by if preceded by '+'.

-r, --resizefs
    Attempt to resize the filesystem on the logical volume before reducing the logical volume. Caution: This only works for filesystems that support shrinking (e.g., ext2/3/4) and might fail or lead to data loss if the filesystem is in use or corrupted. XFS cannot be shrunk.

-f, --force
    Reduce the logical volume without requiring confirmation. Use with extreme caution, as this can lead to data loss if not combined with prior filesystem resizing.

-t, --test
    Run in test mode. Do not make any real changes, just show what would happen. Useful for verifying commands.

-y, --yes
    Assume yes to all questions; do not prompt for confirmation.

DESCRIPTION

lvreduce is a command-line utility used to decrease the size of an existing Logical Volume (LV) within a Logical Volume Manager (LVM) setup. This operation is critical for optimizing disk space, especially when a volume was over-provisioned or data has been migrated elsewhere.

Before reducing an LV, it is paramount to first shrink the filesystem residing on that LV. Failing to do so will almost certainly result in irreversible data loss, as lvreduce does not inspect the filesystem content and will truncate the volume regardless. Tools like resize2fs (for ext2/3/4) or xfs_growfs (XFS can only grow, not shrink) are used for filesystem resizing. After the filesystem is safely reduced, lvreduce can then be used to cut the underlying LV to the new, smaller size. The command supports specifying the absolute new size or the amount to reduce by. It also offers an option to attempt automatic filesystem resizing, though manual resizing is often preferred for control and safety, particularly for filesystems that do not support shrinking (like XFS).

Always back up critical data before performing any LV resizing operations.

CAVEATS

  • Data Loss Risk: Reducing a logical volume before shrinking the filesystem on it will almost certainly lead to severe and unrecoverable data loss. The lvreduce command operates on the block device level and does not understand the filesystem's structure.
  • Filesystem Support: Not all filesystems can be shrunk. For instance, XFS filesystems can only be grown, not reduced. Other filesystems like ext2/3/4 require explicit unmounting or online resizing tools (e.g., resize2fs).
  • Unmounting: It is generally safest to unmount the filesystem before reducing the LV, especially if not using the -r option with an online-resizable filesystem.
  • Backup: Always back up critical data before performing any LVM resizing operations.

<B>ONLINE VS. OFFLINE RESIZING</B>

While some filesystems (like ext4) support online resizing (shrinking while mounted), it is generally safer and recommended to unmount the filesystem before shrinking the logical volume to prevent data corruption, especially if you are not using the -r option or are unsure about your filesystem's online shrinking capabilities.

<B>PHYSICAL EXTENTS</B>

LVM manages storage in units called Physical Extents (PEs). When you reduce an LV, lvreduce reclaims these PEs from the end of the logical volume, making them available back to the volume group for other logical volumes.

HISTORY

lvreduce is an integral part of the Logical Volume Manager (LVM) suite, which has been a standard feature in Linux distributions for managing disk space more flexibly than traditional partitioning. LVM was initially developed by Joe Thornber and first integrated into the Linux kernel in 1998. The ability to dynamically resize volumes, both to extend and reduce them, has been a core capability of LVM from its early days, making it a crucial tool for system administrators managing storage resources. Its usage has evolved with improvements in online filesystem resizing, but the fundamental principle of careful pre-resizing of the filesystem remains unchanged.

SEE ALSO

Copied to clipboard