LFCS 86 ๐ง LVM โ Extending Volumes
Extending an LVM volume is the operation that justifies the entire abstraction. A partition cannot grow while mounted; an LVM Logical Volume can. The workflow is two commands in the simple case and three when the Volume Group has no free space. The critical detail is that lvextend changes the block device’s size, not the filesystem’s, and the filesystem must be grown separatelyโunless the -r flag is used, which performs both steps in one command .
This chapter covers the extension workflow: checking free space, extending the LV, growing the filesystem, and the -r shortcut. It assumes the PV and VG operations from LFCS 83 and 84, and the LV creation from LFCS 85. The focus is on the online extension that makes LVM operationally valuable: no unmount, no reboot, no maintenance window .
Key point: lvextend -r is the recommended form. The -r flag detects the filesystem type and invokes the correct resize tool automatically. Without it, the LV is larger but the filesystem still believes it has the old size.
Why extension is the core LVM operation
The online growth requirement. The LFCS Storage Management domain includes “Manage and configure LVM storage” . The operational test of that competency is whether the candidate can grow a volume while it is in use. A filesystem that must be unmounted for every resize is a filesystem that requires downtime; the LVM extension workflow is the procedure that avoids it.
The two-step separation. lvextend modifies the extent mapping. The LV gains Logical Extents, and the block device reports a larger size. The filesystem on the LV does not automatically detect the change. resize2fs for ext4 and xfs_growfs for XFS are the commands that update the filesystem’s internal metadata to use the new space . The separation exists because the filesystem is a layer above the block device, and it has no way to observe a size change without being told.
The -r shortcut. The -r flag on lvextend performs the filesystem resize as part of the same command. It detects the filesystem type from the LV’s content and calls the appropriate tool . This is the recommended practice because it removes the most common mistake: forgetting the second step and leaving the filesystem at its old size.
The VG capacity check. lvextend can only allocate extents that the VG has free. If vgs reports VFree as zero, the extension fails. The solution is to add a Physical Volume to the VG with pvcreate and vgextend, which increases the VG’s free space, and then retry the extension .
a. Checking free space before extending
The first command is vgs, which shows the VG’s total size and free space. The VFree column is the amount available for new allocations.
# Check the VG's free space.
sudo vgs
# Example output:
# VG #PV #LV #SN Attr VSize VFree
# vg_data 2 1 0 wz--n- 19.99g 9.99g
If VFree is sufficient, the extension can proceed. If it is zero or smaller than the requested amount, the VG needs a new PV. vgdisplay provides the same information in detailed form, including the PE size and the free PE count.
# Detailed view of the VG.
sudo vgdisplay vg_data
The LV’s current size is confirmed with lvs or df -h. lvs shows the block device size; df -h shows the filesystem size. The two should match before the extension begins, and they should match again after it completes.
# Confirm the LV and filesystem sizes before extending.
sudo lvs /dev/vg_data/lv_app
df -h /mnt/app
b. Extending the LV and growing the filesystem
The lvextend command takes the LV path and a size specification. The -L option uses absolute units (G, M, T), and the -l option uses extents or percentages. The + prefix means “add this amount”; without it, the value is the target total size.
# Add 2 GB to the LV.
sudo lvextend -L +2G /dev/vg_data/lv_app
# Extend to a total of 10 GB.
sudo lvextend -L 10G /dev/vg_data/lv_app
# Use all remaining free space in the VG.
sudo lvextend -l +100%FREE /dev/vg_data/lv_app
After the LV is extended, the filesystem must be grown. The command depends on the filesystem type.
# ext4: grow online.
sudo resize2fs /dev/vg_data/lv_app
# XFS: grow online (the argument is the mount point, not the device).
sudo xfs_growfs /mnt/app
The XFS detail is a common exam trap. xfs_growfs takes the mount point, not the device path, because XFS can only be grown while mounted . resize2fs takes the device path and works on both mounted and unmounted ext4 filesystems.
The single-command form uses -r:
# Extend the LV and resize the filesystem in one step.
sudo lvextend -r -L +2G /dev/vg_data/lv_app
The -r flag is equivalent to running lvextend followed by the correct filesystem resize tool. It is the recommended form for the LFCS exam because it is simpler and less error-prone .
c. Extending when the VG has no free space
If vgs reports no free space, the VG must be extended before the LV can be. The sequence is: initialize the new disk as a PV, add it to the VG, then extend the LV and filesystem.
# Initialize the new disk as a PV.
sudo pvcreate /dev/sdd
# Add the PV to the existing VG.
sudo vgextend vg_data /dev/sdd
# Verify the new free space.
sudo vgs vg_data
# Now extend the LV and filesystem.
sudo lvextend -r -L +10G /dev/vg_data/lv_app
The new PV’s capacity becomes available in the VG immediately after vgextend. The lvextend command then allocates from the expanded pool. No unmount, no service restart, and no data migration are required .
Complete Example Session
# ============================================
# PART 1: CHECK THE CURRENT STATE
# ============================================
# Confirm the LV size and the filesystem size match.
sudo lvs /dev/vg_data/lv_app
df -h /mnt/app
# ============================================
# PART 2: CHECK VG FREE SPACE
# ============================================
# If VFree is sufficient, proceed to extend.
sudo vgs vg_data
# ============================================
# PART 3: EXTEND THE LV
# ============================================
# Add 2 GB of extents to the LV.
sudo lvextend -L +2G /dev/vg_data/lv_app
# ============================================
# PART 4: GROW THE FILESYSTEM
# ============================================
# The filesystem must be told about the new space.
# For ext4:
sudo resize2fs /dev/vg_data/lv_app
# For XFS:
# sudo xfs_growfs /mnt/app
# ============================================
# PART 5: THE ONE-STEP FORM
# ============================================
# The -r flag performs both steps.
sudo lvextend -r -L +2G /dev/vg_data/lv_app
# ============================================
# PART 6: EXTEND WITH ALL FREE SPACE
# ============================================
# Allocate the entire remaining VG capacity.
sudo lvextend -r -l +100%FREE /dev/vg_data/lv_app
# ============================================
# PART 7: THE VG IS FULL CASE
# ============================================
# If vgs shows VFree 0, add a new PV first.
sudo pvcreate /dev/sdd
sudo vgextend vg_data /dev/sdd
sudo vgs vg_data
# ============================================
# PART 8: EXTEND AFTER VG EXPANSION
# ============================================
# The new extents are now available.
sudo lvextend -r -L +10G /dev/vg_data/lv_app
# ============================================
# PART 9: VERIFY
# ============================================
# Both the LV and the filesystem must show the new size.
sudo lvs /dev/vg_data/lv_app
df -h /mnt/app
# ============================================
# PART 10: THE FULL PICTURE
# ============================================
# lvextend changes the block device.
# resize2fs / xfs_growfs changes the filesystem.
# -r combines both steps.
echo "Extension workflow complete."
The ten parts walk through the extension from the space check to the verification. The sequence is the same whether the filesystem is ext4 or XFS; only the resize command differs, and -r eliminates the difference.
Quick Reference
Extension Commands
| Command | Effect |
|---|---|
lvextend -L +2G /dev/vg/lv | Add 2 GB to the LV |
lvextend -L 10G /dev/vg/lv | Set total size to 10 GB |
lvextend -l +100%FREE /dev/vg/lv | Use all free VG space |
lvextend -r -L +2G /dev/vg/lv | Extend and resize filesystem |
Filesystem Resize Commands
| Filesystem | Command | Mounted? |
|---|---|---|
| ext4 | resize2fs /dev/vg/lv | Yes or no |
| XFS | xfs_growfs /mountpoint | Must be mounted |
VG Expansion Sequence
| Step | Command | Effect |
|---|---|---|
| 1 | pvcreate /dev/sdX | Initialize new PV |
| 2 | vgextend vg_name /dev/sdX | Add PV to VG |
| 3 | lvextend -r -L +size /dev/vg/lv | Extend LV and filesystem |
Verification
| Check | Command | Expected |
|---|---|---|
| LV size | lvs /dev/vg/lv | New size |
| Filesystem size | df -h /mountpoint | New size |
| VG free space | vgs vg_name | Reduced VFree |
Best Practices
โ Do This:
# Check VG free space first.
sudo vgs vg_data // โ
# Use -r to extend and resize in one step.
sudo lvextend -r -L +2G /dev/vg_data/lv_app // โ
# Use xfs_growfs with the mount point for XFS.
sudo xfs_growfs /mnt/app // โ
# Verify both LV and filesystem after extending.
sudo lvs /dev/vg_data/lv_app && df -h /mnt/app // โ
โ Don’t Do This:
# Don't run lvextend without the filesystem resize.
sudo lvextend -L +2G /dev/vg_data/lv_app # filesystem unchanged // โ
# Don't use xfs_growfs on an unmounted XFS filesystem.
sudo umount /mnt/app && sudo xfs_growfs /mnt/app # fails // โ
# Don't extend when VFree is 0.
sudo lvextend -L +2G /dev/vg_data/lv_app # fails: no space // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| LV larger, filesystem unchanged | Forgot the resize step | Run resize2fs / xfs_growfs, or use -r |
lvextend fails | VG has no free extents | pvcreate + vgextend first |
xfs_growfs fails | Filesystem not mounted | Mount, then run xfs_growfs /mountpoint |
| Extension succeeds but app sees old size | App cached the size | Restart the app or re-check with df |
Real-World Examples
1. Check Free Space
sudo vgs
2. Extend by Amount
sudo lvextend -L +5G /dev/vg_data/lv_app
3. Extend to Total
sudo lvextend -L 20G /dev/vg_data/lv_app
4. Use All Free
sudo lvextend -l +100%FREE /dev/vg_data/lv_app
5. Grow ext4
sudo resize2fs /dev/vg_data/lv_app
6. Grow XFS
sudo xfs_growfs /mnt/app
7. One-Step Extend
sudo lvextend -r -L +2G /dev/vg_data/lv_app
8. Add PV to VG
sudo pvcreate /dev/sdd && sudo vgextend vg_data /dev/sdd
9. Extend After VG Growth
sudo lvextend -r -L +10G /dev/vg_data/lv_app
10. Verify Both
sudo lvs /dev/vg_data/lv_app && df -h /mnt/app
Visual
The Extension Workflow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. vgs โ check VFree โ
โ โ โ
โ โโโโโโดโโโโโ โ
โ โผ โผ โ
โ SUFFICIENT ZERO โ
โ โ โ โ
โ โ โผ โ
โ โ pvcreate /dev/sdX โ
โ โ vgextend vg /dev/sdX โ
โ โ โ โ
โ โโโโโโฌโโโโโ โ
โ โผ โ
โ 2. lvextend -r -L +size /dev/vg/lv โ
โ โ โ
โ โผ โ
โ 3. lvs + df -h โ verify โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Two-Step vs One-Step
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TWO-STEP โ
โ lvextend -L +2G /dev/vg/lv โ
โ resize2fs /dev/vg/lv โ
โ โ
โ ONE-STEP โ
โ lvextend -r -L +2G /dev/vg/lv โ
โ โ โ
โ โผ detects filesystem, calls resize tool โ
โ (ext4 โ resize2fs, XFS โ xfs_growfs) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The XFS Detail
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ext4: resize2fs /dev/vg/lv โ
โ โ device path โ
โ โ works mounted or unmounted โ
โ โ
โ XFS: xfs_growfs /mountpoint โ
โ โ mount point, not device path โ
โ โ must be mounted โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The VG Full Case
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ vgs โ VFree 0 โ
โ โ โ
โ โผ โ
โ pvcreate /dev/sdd โ
โ โ โ
โ โผ โ
โ vgextend vg_data /dev/sdd โ
โ โ โ
โ โผ VFree increases โ
โ lvextend -r -L +10G /dev/vg_data/lv_app โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Check free space | vgs (VFree column) |
| Extend LV | lvextend -L +size /dev/vg/lv |
| Resize ext4 | resize2fs /dev/vg/lv |
| Resize XFS | xfs_growfs /mountpoint |
| One-step | lvextend -r -L +size /dev/vg/lv |
| VG full | pvcreate + vgextend first |
| Verify | lvs and df -h |
Key takeaways:
lvextendchanges the block device, not the filesystem. The filesystem must be resized separately withresize2fsorxfs_growfs, unless the-rflag is used .lvextend -ris the recommended form. It detects the filesystem type and invokes the correct resize tool, eliminating the most common mistake .- XFS uses the mount point, not the device path.
xfs_growfs /mnt/appis the correct form; the filesystem must be mounted . - If the VG is full, add a PV first.
pvcreateinitializes the disk,vgextendadds it to the VG, and thenlvextendcan allocate from the expanded pool . - Verify both layers after extending.
lvsshows the LV size,df -hshows the filesystem size, and the two should match. - Extension is online. The LV and filesystem can be grown while the application is running and writing data. This is the operational advantage that justifies LVM .
Remember: Extending an LVM volume is two operations that look like one. The LV is a block device; the filesystem is a layer above it. lvextend changes the block device, and the resize command changes the filesystem. The -r flag combines them, and the combination is the correct practice. When the VG has no free space, the sequence starts one layer lower: pvcreate, vgextend, then lvextend -r. The commands are simple; the discipline is checking the VG first and verifying both layers after.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!