Lvextend Command
Extend Logical Volume Size
The lvextend command is a powerful utility in Linux's
Logical Volume Management (LVM) system used to increase the size of
an existing logical volume (LV). This is crucial for managing disk
space dynamically without repartitioning physical disks. This guide
provides examples of how to use lvextend to expand your
storage.
Common Lvextend Usage Examples
Here are several ways to utilize the lvextend command:
Extend by a Specific Size
To increase the size of a logical volume by a specific amount, use
the -L option followed by a plus sign and the desired
size (e.g., 10 Gigabytes).
# Extend a logical volume by a specific size (e.g., 10GB)
lvextend -L +10G /dev/vg_name/lv_name
Extend to a Specific Total Size
You can also extend a logical volume to a precise total size. This will set the LV to the specified size, potentially consuming space from the volume group.
# Extend a logical volume to a specific size (e.g., 50GB)
lvextend -L 50G /dev/vg_name/lv_name
Extend Using Available Free Space
To utilize all the remaining unallocated space within the volume
group for a specific logical volume, use the
-l +100%FREE option.
# Extend a logical volume using all the available space in the volume group
lvextend -l +100%FREE /dev/vg_name/lv_name
Extend on a Specific Physical Volume
In some advanced scenarios, you might want to extend a logical volume by allocating space from a particular physical volume (PV).
# Extend a logical volume on a specific physical volume
lvextend -L +5G /dev/vg_name/lv_name /dev/sdX
Resizing Filesystems After Extending
After extending a logical volume, you typically need to resize the
filesystem residing on it to recognize the new space. The
-r flag with lvextend can often do this
automatically for supported filesystems.
Automatic Filesystem Resize
For common Linux filesystems like ext2, ext3, ext4, XFS, and Btrfs,
the -r option attempts to resize the filesystem on the
fly.
# Extend a logical volume and resize the filesystem on the fly (for ext2/ext3/ext4 file systems)
lvextend -r -L +10G /dev/vg_name/lv_name
# Extend a logical volume to use all the remaining unallocated space in the group and resize the filesystem
lvextend -r -l +100%FREE /dev/vg_name/lv_name
Manual Filesystem Resize Commands
If automatic resizing fails or is not supported for your filesystem, you can manually resize it using specific commands:
Ext4 Filesystem Resize
Use ext2resize for ext2, ext3, and ext4 filesystems.
Note that ext2resize is a wrapper and often calls
resize2fs.
# Extend ext4 filesystem after changing a logical volume
# (takes volume path as parameter):
ext2resize /dev/vg0/mylv
Btrfs Filesystem Resize
For Btrfs, use the btrfs filesystem resize command,
specifying the mount point.
# Extend btrfs filesystem after changing a logical volume
# (takes the mount point as parameter, not the volume path):
btrfs filesystem resize max /mylv
XFS Filesystem Resize
Use xfs_growfs for XFS filesystems, also specifying the
mount point.
# Extend xfs filesystem after changing a logical volume
# (takes the mount point as parameter, not the volume path):
xfs_growfs /mylv
JFS Filesystem Resize
For JFS, remounting with the resize option is typically
sufficient.
# Extend jfs filesystem after changing a logical volume
# (takes the mount point as parameter, not the volume path);
# Just remount:
mount -o remount,resize /home