Sub topic 3
Doing both steps at once with lvextend -r
This chapter assumes you can use the Linux command line with sudo, that you know what a logical volume (LV) and a volume group (VG) are, and that you can read df and lvs output. You should already know how much free space your VG has.
Extending the volume and filesystem together
Growing a volume takes two steps. First, you extend the logical volume. Second, you grow the filesystem inside it. The -r (--resizefs) option of lvextend runs the matching resize tool after the extension, so one command does both steps:
sudo lvextend -r -L +20G /dev/vg_data/lv_appThis adds 20 GiB to lv_app and grows its ext4 or XFS filesystem. To use all remaining free space instead, replace -L +20G with -l +100%FREE.
Verifying the result
Check each layer from the bottom up:
| Layer | Command | What to check |
|---|---|---|
| Volume group | `sudo vgs vg_data` | VFree drops by the amount you added |
| Logical volume | `sudo lvs /dev/vg_data/lv_app` | LSize shows the new size |
| Filesystem | `df -hT /srv/data` | Size matches the new capacity |
If df still shows the old size, the filesystem was not resized. Run sudo resize2fs /dev/vg_data/lv_app for ext4 or sudo xfs_growfs /srv/data for XFS.
Backups, shrinking limits, and common mistakes
Keep these limits in mind:
- XFS cannot be shrunk. You can only grow it.
- ext4 can shrink, but only while unmounted, and only after
e2fsck -f. Shrink the filesystem first, then the LV. Shrinking the LV below the filesystem size destroys data. - Check
sudo vgsbefore extending. If VFree is smaller than the amount you request,lvextendfails.
Common mistakes:
- Extending the LV but not the filesystem, so
dfshows no change. - Using the mount point instead of the LV path (
/dev/vg_data/lv_app). - Growing an enlarged disk without running
pvresizefirst, so the new space never reaches VFree.
Exercise
Your VG has 10 GiB free. You want the ext4 filesystem on lv_app, mounted at /srv/data, to use all of it in one command. What command do you run, and how do you confirm the result?
Show answer
Run sudo lvextend -r -l +100%FREE /dev/vg_data/lv_app. Then confirm with sudo lvs /dev/vg_data/lv_app for the new LSize and df -hT /srv/data for the new filesystem size.