lvreduce
Reduce the size of a logical volume
TLDR
Reduce a volume's size to 120 GB
Reduce a volume's size by 40 GB as well as the underlying filesystem
SYNOPSIS
lvreduce [options] {Size|Percent} {LogicalVolume}
PARAMETERS
-L|--size Size[b|B|s|S|k|K|m|M|g|G|t|T|p|P|e|E]
Reduces the size of the LV to Size. Size can be specified in bytes (b), sectors (s), kilobytes (k), megabytes (m), gigabytes (g), terabytes (t), petabytes (p), or exabytes (e). Append 'B', 'S', 'K', 'M', 'G', 'T', 'P', or 'E' for powers of 1024 rather than the default 1000.
-l|--extents [-|+]Number[PERCENT]
Reduces or Increases the logical volume size by given number of logical extents. The '+' indicates to increment the size, the '-' indicates to decrement the size.
-r|--resizefs
Resizes the filesystem after reducing the LV (if the filesystem supports it). Use this option with extreme caution.
-f|--force
Forces the operation without confirmation. Use with caution.
--test
Simulates the command without actually making any changes.
-v|--verbose
Provides verbose output for debugging purposes.
--dry-run
Simulates the command without making changes (alias for --test).
DESCRIPTION
The lvreduce command in Linux is used to reduce the size of an existing logical volume (LV). This is a potentially dangerous operation that can result in data loss if not performed correctly. Before using lvreduce, it's crucial to back up any important data residing on the LV. The command modifies the LV metadata, which affects the size reported by the operating system and the amount of physical storage allocated to it. The command can reduce the LV size by a specific amount or to a specific size.
Reducing the size of a volume may require moving data off the physical extents at the end of the volume, which can take some time. The command attempts to reduce the size of the file system. You should resize the filesystem before reducing the LV and reduce the file system to fit the size after LV reduction. It can be useful to resize an over-allocated LV to reclaim the excess space and allocate it to other LVs or physical volumes. Before using the command, you should inspect the lv using `lvdisplay` to know the available size and location of physical extents. Also, you should use `df` to check how much space is actually used in the file system.
CAVEATS
Reducing an LV can lead to data loss if not done correctly. Always back up your data before performing this operation. Ensure the filesystem is smaller than the intended new LV size. It is recommended to resize the filesystem *before* the LV.
BEFORE YOU START
1. Backup Data: Crucially, back up your data before using lvreduce. Data loss is possible.
2. Filesystem Resize: Use a filesystem tool (like resize2fs for ext4) to shrink the filesystem on the LV before you run lvreduce. Shrink the filesystem to a size smaller than you intend to reduce the LV to. You can expand the file system again to maximum size when the LV reduction is done.
REDUCING WITH PERCENTAGES
You can also use percentage values to specify the size reduction relative to the current LV size. For example, `lvreduce -l -20%FREE /dev/vg0/lv0` reduces the LV by 20% of the remaining free space in the volume group. This is useful for dynamic resizing.
HISTORY
lvreduce is part of the LVM2 (Logical Volume Manager 2) suite. LVM2 was developed to provide a more flexible and advanced approach to managing storage compared to traditional partitioning. It evolved from the original LVM and offers features like online resizing, snapshots, and thin provisioning. It has become a standard tool for managing storage in many Linux distributions, offering administrators the ability to dynamically allocate and resize storage volumes without needing to reboot the system or interrupt services. The usage has gradually increased as enterprise storage became more virtualized.