Sub topic 3
Finding out how much free space the volume group has
Assume you are comfortable with sudo, block devices, mount points, and filesystems such as ext4 or XFS. This chapter uses LVM commands on a server where the storage layout already exists. Inspect the layout before changing it. Do not extend a logical volume until you know which filesystem and mount point it contains.
How LVM represents free space
Logical Volume Manager (LVM) adds a storage layer between disks and filesystems. It divides storage into three main objects:
- A physical volume (PV) is a disk or partition prepared for LVM.
- A volume group (VG) combines one or more physical volumes into a storage pool.
- A logical volume (LV) is a virtual block device allocated from that pool.
A filesystem, such as ext4 or XFS, is usually created inside an LV. The filesystem does not automatically use every byte that might be available in the volume group. Free space can exist at several different layers.
For example, a volume group might contain 100 GiB of capacity. It could allocate 70 GiB to logical volumes and leave 30 GiB free. An LV might be 70 GiB while its filesystem uses only 40 GiB. The operating system would then show free space in both places, but those spaces have different meanings:
| Location of free space | What it means | How you use it |
|---|---|---|
| Inside the filesystem | The LV already has capacity, but files do not use it | Applications can usually use it immediately |
| Inside the volume group | The VG has unallocated extents | Extend an LV with `lvextend` |
| Outside the PV | A disk has capacity that LVM does not yet know about | Resize the PV or add another PV |
The value that matters before extending an existing LV is the free space in its volume group.
Inspect the complete layout
Run these commands first:
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/dataEach command answers a different question:
pvsshows physical volumes, their volume groups, sizes, and unused capacity.vgssummarizes each volume group, including total size and free space.lvsshows logical volumes and their allocated sizes.lsblk -fdisplays the block-device tree, filesystem types, labels, UUIDs, and mount points.df -hT /srv/datashows the filesystem size, used space, available space, and type for/srv/data.
The df command reports filesystem capacity. It does not report unused capacity in the volume group. The vgs command reports volume-group capacity. You normally need both views to decide whether a filesystem can be expanded.
Read `pvs` output
A typical pvs result might look like this:
PV VG Fmt Attr PSize PFree
/dev/sda3 vg_data lvm2 a-- <80.00g 12.00g
/dev/sdb vg_data lvm2 a-- <40.00g 0Here, /dev/sda3 and /dev/sdb are physical volumes in vg_data. The PFree column says how much capacity is not assigned to logical volumes on each PV. The total free capacity is about 12 GiB.
A tilde before a size, such as <80.00g, means the usable value is slightly less than the displayed round number. LVM reserves space for its metadata and measures allocation in extents. Treat displayed values as approximate until you plan the exact allocation.
Read `vgs` output
The volume-group summary is usually the quickest check:
VG #PV #LV #SN Attr VSize VFree
vg_data 2 2 0 wz--n- <120.00g 12.00gThe important columns are:
VSize: total capacity available to the volume group.VFree: capacity not assigned to any logical volume.#PV: number of physical volumes in the group.#LV: number of logical volumes in the group.#SN: number of LVM snapshots.
If VFree is zero, the volume group cannot provide more space without adding capacity or enlarging an existing physical volume. If VFree is large enough, you can usually extend an LV directly.
Read `lvs` and `lsblk` together
Suppose lvs shows:
LV VG Attr LSize
lv_app vg_data -wi-ao---- 60.00g
lv_logs vg_data -wi-ao---- 48.00gThis identifies the logical volumes but does not tell you which one is mounted at /srv/data. Use lsblk -f to trace the relationship:
NAME FSTYPE SIZE MOUNTPOINT
sda 100G
└─sda3 LVM2_member 80G
├─vg_data-lv_app
│ ext4 60G /srv/data
└─vg_data-lv_logs
xfs 20G /var/log
sdb LVM2_member 40G
└─vg_data-lv_appDevice names and formatting vary by distribution. The essential check is that the target mount point maps to the expected LV, VG, and filesystem type.
Compare free space with the planned change
Before extending /srv/data, answer these questions:
- Which LV provides the filesystem mounted at
/srv/data? - Is that LV in
vg_data, or in another volume group? - How much free space does
vg_datahave according tovgs? - How much space does the filesystem currently have according to
df? - Is the requested increase smaller than the VG's
VFreevalue?
If vgs reports 12 GiB of free space and you need 20 GiB, the volume group cannot satisfy the request as it stands. Do not use lvextend -l +100%FREE merely because free space exists. That option assigns all remaining free extents to the selected LV, leaving no reserve for other LVs or future snapshots.
A repeatable inspection workflow
Use this sequence before every LVM expansion:
- Run
df -hTfor the affected mount point. - Run
lsblk -fand identify the backing LV and filesystem. - Run
lvsto confirm the LV and VG names. - Run
vgsto checkVFree. - Run
pvsto see which physical volumes hold the free extents. - Record the output before making changes.
Free extents may be distributed across several physical volumes. LVM can normally allocate them without requiring them to be physically adjacent, but disk redundancy, performance, and failure-domain policies may affect where new extents should go.
Exercise
df -hT /srv/data shows 8 GiB available, while vgs vg_data shows 25 GiB in VFree. Can you extend the filesystem by 10 GiB immediately, and what does each number represent?
Show answer
Usually yes, if /srv/data is backed by an LV in vg_data and no other safety policy prevents the change. The 8 GiB is unused space inside the existing filesystem. The 25 GiB is unallocated capacity in the volume group that can first be assigned to the LV. The filesystem must then be grown separately.