LinuxCommandLibrary

lvextend

Increase the size of a logical volume

TLDR

Increase a volume's size to 120 GB

$ sudo lvextend [[-L|--size]] [120G] [logical_volume]
copy

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

Increase a volume's size to 100% of the free physical volume space
$ sudo lvextend [[-l|--extents]] +[100]%FREE [logical_volume]
copy

Increase a volume's size to 100% of the free physical volume space and resize the underlying filesystem
$ sudo lvextend [[-l|--extents]] +[100]%FREE [[-r|--resizefs]] [logical_volume]
copy

SYNOPSIS

lvextend [options] LV [PV...]

PARAMETERS

LV
    The logical volume to extend. Specified as /dev/vgname/lvname.

-L|--size Size[bBsSkKmMgGtTpPeE]
    The amount to increase the logical volume's size by. A '+' prefix indicates an increase, without it represents the total size.

-l|--extents [+|-]Number[%{FREE|PVS|VG}]
    Extend the LV by the specified number of logical extents. '+' indicates an increase. %{FREE|PVS|VG} represents a percentage of free extents in the VG, PVS, or physical volume.

PV...
    Specifies the Physical Volumes to use for extending the LV. If not specified, the system will allocate from available PVs within the VG.

-r|--resizefs
    Resize the filesystem after extending the LV. This option is only supported for certain filesystem types.
NOTE: Ensure the filesystem is supported for online resizing.

--alloc AllocationPolicy
    Specifies the allocation policy (e.g., normal, contiguous, anywhere). Controls how extents are allocated when extending.

-n|--nofsck
    Do not perform fsck before resizing. Only relevant with -r/--resizefs.

-i|--stripes Number
    Number of stripes to use for the LV extension.

DESCRIPTION

The lvextend command is used to increase the size of an existing Logical Volume (LV). It does this by adding space from available Volume Groups (VG) or specific Physical Volumes (PVs) to the LV. This is a crucial step in dynamically resizing storage in a Linux system using the Logical Volume Manager (LVM). Before extending an LV, ensure there is enough free space within the VG. You can check free space with vgs or vgdisplay commands. After extending the LV, you'll typically need to resize the filesystem within the LV to utilize the new space. The filesystem resize command (e.g., resize2fs for ext4, xfs_growfs for XFS) depends on the filesystem type. Using lvextend allows non-disruptive storage management for databases, virtual machines, and other applications that may require additional space over time.

CAVEATS

  • Ensure sufficient free space in the Volume Group before extending.
  • Always back up critical data before performing LVM operations.
  • Filesystem resize is a separate operation and might require downtime.
  • Using -r/--resizefs will only work if the underlying fs implementation contains the needed logic for it.

EXAMPLES

  • Extend LV 'mylv' in VG 'myvg' by 10GB: lvextend -L +10G /dev/myvg/mylv
  • Extend LV 'mylv' to a total size of 50GB: lvextend -L 50G /dev/myvg/mylv
  • Extend LV 'mylv' using a specific PV: lvextend /dev/myvg/mylv /dev/sda3
  • Extend LV 'mylv' and automatically resize the filesystem: lvextend -r -L +20G /dev/myvg/mylv

HISTORY

The LVM tools, including lvextend, were developed to provide a flexible and dynamic storage management solution in Linux. Initially released around the late 1990s and early 2000s, LVM has become a standard component of most Linux distributions. lvextend plays a key role in adapting to evolving storage needs without requiring service interruptions, which is crucial for modern server environments. It evolved in conjunction with other LVM tools, adding support for more advanced features like striping, mirroring, and snapshots.

SEE ALSO

Copied to clipboard