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 {-L|--size [+|-]Size[B|S|K|M|G|T|P|E]} | {-l|--extents [+|-]Extents[%{VG|LV|PVS|FREE|ORIGIN}]} [-r|--resizefs] [-n|--nofsck] [-t|--test] LogicalVolumePath [PhysicalVolumePath...]

PARAMETERS

LogicalVolumePath
    The path to the logical volume to extend, typically in the format /dev/vgname/lvname.

-L, --size [+|-]Size[B|S|K|M|G|T|P|E]
    Specifies the new absolute size or the amount to add/subtract from the logical volume. Units include B (bytes), S (sectors), K (kilobytes), M (megabytes), G (gigabytes), T (terabytes), P (petabytes), and E (exabytes).

-l, --extents [+|-]Extents[%{VG|LV|PVS|FREE|ORIGIN}]
    Specifies the new absolute or relative number of logical extents. Can be a percentage of the volume group's free space (%VG), logical volume's size (%LV), or other options.

-r, --resizefs
    Extends the underlying filesystem to the new logical volume size. This option supports ext2, ext3, ext4, and xfs filesystems, automating the filesystem resize after the LV is extended.

-n, --nofsck
    Prevents fsck from being run before resizing the filesystem. Use with caution, as it skips a consistency check that can prevent data corruption.

-t, --test
    Runs the command in test mode. All checks are performed, and actions are displayed, but no actual changes are committed to disk.

-f, --force
    Forces the operation, overriding certain warnings or prompts.

-v, --verbose
    Increases the verbosity of the output, providing more detailed information about the operation.

DESCRIPTION

The lvextend command is a crucial utility within the Logical Volume Manager (LVM) framework, used to increase the size of an existing logical volume (LV). LVM provides a flexible way to manage storage by abstracting physical storage into logical volumes, allowing for dynamic resizing.

When executed, lvextend allocates additional free physical extents from the volume group (VG) to the specified logical volume. It can extend an LV by a specific increment (e.g., +10GB) or to an absolute total size (e.g., 50GB). A key distinction is that lvextend primarily modifies the size of the logical volume container itself. To make the increased space usable, the filesystem residing on that logical volume must also be resized. For convenience, the -r (or --resizefs) option automates the filesystem resizing for common filesystems like ext2/3/4 and xfs.

CAVEATS

Filesystem Resizing: While lvextend increases the logical volume's size, the filesystem on it will not automatically recognize the new space unless the -r option is used. If -r is not used (or for unsupported filesystems), you must manually resize the filesystem using commands like resize2fs (for ext2/3/4) or xfs_growfs (for xfs). Failing to do so will result in the filesystem still reporting its original size.

Data Loss: Although lvextend is generally safe for expansion, always back up critical data before performing any disk or volume management operations to prevent potential data loss in case of unexpected errors.

Shrinking LVs: lvextend is exclusively for increasing logical volume size. To reduce an LV's size, you must use the lvreduce command, ensuring the filesystem is shrunk first to avoid data corruption.

ONLINE RESIZING

For most modern filesystems (like ext4 and xfs) and kernels, lvextend with the -r option can extend both the logical volume and its filesystem while the filesystem is mounted and actively in use. This capability significantly minimizes downtime for critical services. However, if -r is not used or not supported for your specific filesystem/LVM version, you will need to manually invoke the filesystem resizing tool (e.g., xfs_growfs) after lvextend has completed.

INSUFFICIENT FREE SPACE

lvextend requires sufficient free physical extents within the associated volume group (VG) to perform the extension. If the volume group does not have enough free space, the operation will fail. In such cases, you must first extend the volume group by adding new physical volumes (e.g., using the vgextend command) before attempting to extend the logical volume.

HISTORY

The Logical Volume Manager (LVM) was introduced in Linux to provide a more flexible and dynamic way to manage disk space compared to traditional static partitioning. lvextend is a fundamental utility within the LVM framework, designed from its inception to enable the dynamic resizing of logical volumes—a key feature distinguishing LVM from older disk management paradigms. Its functionality has continuously evolved alongside LVM itself, with improvements in online resizing capabilities and deeper filesystem integration (e.g., the -r option introduced later to simplify the process).

SEE ALSO

lvreduce(8), lvdisplay(8), vgextend(8), pvs(8), vgs(8), lvs(8), resize2fs(8), xfs_growfs(8), fsck(8)

Copied to clipboard