lvextend
The lvextend
command in Linux is used to increase the size of a logical volume (LV) in a Logical Volume Manager (LVM) setup. Extending the size of a logical volume can be done dynamically, and after extension, the underlying filesystem may also need to be resized to utilize the newly added space.
Syntax
Where:
<logical-volume>
is the path to the logical volume you want to extend (e.g.,/dev/vgname/lvname
).
Common Options
-L
or--size <size>
: Specifies the new size of the logical volume. This is used when increasing the size to a fixed size.Example: Resize the LV to 100GB:
-l
or--extents <extents>
: Specifies the number of extents to increase the logical volume by. An extent is a unit of space in the volume group.Example: Extend the LV by 50% of the free space available in the volume group:
--resizefs
: Automatically resizes the filesystem to match the new size of the logical volume. This option is particularly useful when extending the size of the LV and its filesystem simultaneously.Example:
-f
or--force
: Forces the extension even if there are warnings or minor issues (use with caution).Example:
-d
or--debug
: Displays debugging information during the execution of the command.Example:
How to Use lvextend
lvextend
When you extend a logical volume, it’s crucial that:
Free Space in the Volume Group: Ensure there is enough free space in the volume group to extend the logical volume.
Resize the Filesystem: After extending the logical volume, you may need to resize the filesystem to take advantage of the newly added space.
Steps to Extend the Size of a Logical Volume
1. Check Available Space in the Volume Group
Before you extend the logical volume, verify how much free space is available in the volume group. Use the following command:
Look at the VFree
column to see how much free space is available.
2. Extend the Logical Volume
Once you have enough free space, you can extend the logical volume.
Extend the logical volume to a specific size (e.g., extend to 100GB):
Extend the logical volume by a specific number of extents:
Extend the logical volume by all available free space:
Extend the logical volume by 10GB:
3. Resize the Filesystem
Once the logical volume has been extended, you may need to resize the filesystem to use the newly added space. The filesystem type determines the command you use:
For ext4 filesystems:
For XFS filesystems: XFS filesystems can be resized online after extending the logical volume:
4. Verify the Extension
Once the extension is complete, verify the new size of the logical volume and filesystem.
To check the size of the logical volume:
To check the size of the filesystem:
Example of Extending Logical Volume
Let's say you have a logical volume /dev/vgname/lvname
with 50GB of space, and you want to extend it by an additional 30GB.
Extend the logical volume by 30GB:
Resize the filesystem (for ext4):
Verify the extension:
Important Notes:
Filesystem Resizing: After extending the logical volume, remember to resize the filesystem so it can use the new space. Some filesystems (like XFS) can be resized while mounted, while others (like ext4) may require the filesystem to be unmounted before resizing.
Monitor Usage: After extending the logical volume and filesystem, ensure that the new space is being used appropriately by checking your system's disk usage regularly.
Free Space: Ensure the volume group has enough free space to extend the logical volume. If not, you may need to add additional physical volumes to the volume group.
Conclusion
lvextend
is a simple and effective command to increase the size of a logical volume in LVM. It’s crucial to verify that the underlying filesystem is resized correctly to take advantage of the new space. Always ensure there is sufficient free space in the volume group before attempting to extend the LV.
Last updated