lvreduce – Shrink Logical Volume Space

The lvreduce command is used to shrink the size of a logical volume (LV) in Linux. This can be useful when you need to reclaim disk space that is no longer needed or to create additional space for other partitions. The command reduces the size of an LV by reducing the size of its underlying physical volume (PV) and the file system that resides on it.

Overview

To use the lvreduce command, you must first unmount the file system that resides on the LV. Once unmounted, you can use the command to reduce the size of the LV. The syntax for the command is as follows:

lvreduce [OPTIONS] LV_PATH NEW_SIZE

Where OPTIONS are the various options that can be used with the command, LV_PATH is the path to the logical volume you want to shrink, and NEW_SIZE is the new size of the logical volume.

For example, to reduce the size of the /dev/vg01/lv01 logical volume to 10GB, you would use the following command:

lvreduce /dev/vg01/lv01 -L 10G

This command reduces the size of the logical volume to 10GB and updates the file system to reflect the new size.

Use cases

  • Reclaiming disk space that is no longer needed
  • Creating additional space for other partitions
  • Resizing logical volumes to better fit the needs of your system

Options

The following table lists the available options for the lvreduce command:

Option Description
-A, –autobackup {y n} Enable or disable automatic backup of metadata before the operation
-d, –debug Enable debug output
-h, –help Display help information
-r, –resizefs Resize the file system along with the logical volume
-t, –test Test mode. Do not make any changes
-v, –verbose Verbose output
-Z, –zero {y n} Enable or disable zeroing of the first 4KB of the LV

Troubleshooting tips

  • Make sure the logical volume you want to shrink is unmounted before running the lvreduce command.
  • Ensure that you have enough free space on the physical volume to shrink the logical volume.
  • If you encounter any errors during the shrinking process, use the --test option to run the command in test mode and see what changes would be made without actually making them.

Notes

  • Always backup your data before making any changes to your logical volumes.
  • If you are shrinking a logical volume that has a file system on it, make sure to use the --resizefs option to resize the file system along with the logical volume.