Sub topic 2
Reading the Current Layout Before Changing Anything
Assume you are comfortable using the Linux command line with sudo, understand block devices and mount points, and can read df and lsblk output. This chapter uses LVM, the Logical Volume Manager, on a mounted path such as /srv/data.
Before changing storage, build a complete picture of the current layout. LVM commands show how storage is allocated. lsblk shows how devices and partitions connect. df shows what the filesystem and applications can currently use. No single command gives you all of this information.
How LVM layers storage
LVM divides storage into three main layers:
- A physical volume, or PV, is a disk or partition prepared for LVM.
- A volume group, or VG, combines one or more physical volumes into a pool of storage.
- A logical volume, or LV, is a virtual block device allocated from the pool.
A filesystem such as ext4 or XFS is created inside an LV. The filesystem is usually mounted at a directory. To increase the usable space, you must understand which layer has available capacity.
A volume group can contain free space that has not yet been assigned to any logical volume. That free space is different from free space inside a filesystem. For example, vg_data might have 40 GiB available while the filesystem mounted at /srv/data has only 2 GiB free. The 40 GiB is unused LVM capacity. The 2 GiB is unused space for files.
Inspect the complete layout
Run the following commands before planning a resize:
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/dataUse the output together rather than reading one command in isolation.
| Command | Main question answered | Important fields |
|---|---|---|
| `pvs` | Which disks or partitions are LVM physical volumes? | `PV`, `VG`, `PSize`, `PFree` |
| `vgs` | How much capacity is in each volume group? | `VG`, `VSize`, `VFree` |
| `lvs` | Which logical volumes exist and how large are they? | `LV`, `VG`, `LSize` |
| `lsblk -f` | How are disks, partitions, filesystems, and mount points connected? | `NAME`, `FSTYPE`, `UUID`, `MOUNTPOINTS` |
| `df -hT /srv/data` | How much space can the mounted filesystem use? | `Filesystem`, `Type`, `Size`, `Used`, `Avail`, `Mounted on` |
The pvs, vgs, and lvs commands normally show abbreviated names. You can request more readable output when investigating a particular system:
sudo pvs -o pv_name,vg_name,pv_size,pv_free
sudo vgs -o vg_name,vg_size,vg_free
sudo lvs -o lv_name,vg_name,lv_size,lv_pathThe lv_path value is especially useful. It gives the device path that represents the logical volume, such as /dev/vg_data/lv_app.
Read the relationships correctly
Suppose the commands show information similar to this:
| Layer | Example value |
|---|---|
| Physical volume | `/dev/sda3` |
| Volume group | `vg_data` |
| Logical volume | `/dev/vg_data/lv_app` |
| Filesystem | `xfs` |
| Mount point | `/srv/data` |
This tells you that /dev/sda3 contributes capacity to vg_data. The volume group provides capacity to lv_app. The XFS filesystem inside that logical volume is mounted at /srv/data.
The lsblk -f output helps confirm that the device you plan to change is the one backing the intended mount point. The df output confirms the filesystem type and reports the space visible to applications.
A path such as /dev/mapper/vg_data-lv_app may appear instead of /dev/vg_data/lv_app. These are two device names for the same LVM logical volume. Compare the lvs and lsblk output before choosing a device path.
Find free space in the volume group
The VFree column from vgs is the key value when you want to extend an LV using capacity that LVM already controls.
For example:
VG VSize VFree
vg_data 100.00g 32.00gThis means vg_data has 32 GiB that is not assigned to logical volumes. You could potentially allocate some or all of that space to an LV.
If VFree is zero, the volume group has no unallocated extents. An extent is a fixed-size unit of space that LVM assigns to logical volumes. In that case, you must first provide more capacity, either by adding a new physical volume or by enlarging a disk and then updating its physical volume.
Do not confuse VFree with PFree. PFree reports unused capacity on each physical volume. The volume group’s free capacity is the total pool available for new or larger logical volumes.
Check for inconsistencies
Before continuing, verify these points:
- The intended mount point appears in
dfandlsblk. - The filesystem type is the one you expect, such as
ext4orxfs. - The filesystem device matches the logical volume shown by
lvs. - The volume group name is correct.
vgsreports enough free space for the planned increase.- The target filesystem is not already mounted from a different disk or logical volume.
If the outputs disagree, stop and investigate. Common causes include checking the wrong mount point, reading an old device path, or assuming that a disk belongs to a volume group when it does not.
Exercise
The df -hT /srv/data command reports /dev/mapper/vg_data-lv_app with filesystem type xfs. The vgs command reports vg_data with VFree equal to 0. What does this tell you before you attempt to increase /srv/data?
Show answer
The mount point uses the XFS filesystem inside the lv_app logical volume, but the volume group has no unallocated capacity. You must add capacity to the volume group before extending the logical volume.