Sub topic 1
How LVM layers storage: PVs, VGs, and LVs
Prerequisites
This chapter assumes you can run commands with sudo, know what a block device and a partition are, and can read df and lsblk output.
LVM (Logical Volume Manager) sits between your disks and your filesystems. It pools several disks and divides the pool into volumes that you can resize while the server runs.
LVM has three layers:
- Physical volume (PV): a disk or partition that LVM manages, such as
/dev/sdb. - Volume group (VG): a pool built from one or more PVs, such as
vg_data. - Logical volume (LV): a slice of the pool that you format and mount, such as
/dev/vg_data/lv_app.
A filesystem sits on an LV. To grow a filesystem, you add space to the VG, extend the LV, and then grow the filesystem.
Reading the current layout before changing anything
Run these commands first. They change nothing.
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/data| Command | What it shows |
|---|---|
| `pvs` | Physical volumes and the VG each one belongs to |
| `vgs` | Volume groups, their total size, and their free space |
| `lvs` | Logical volumes and their sizes |
| `lsblk -f` | The block device tree and filesystem types |
| `df -hT /srv/data` | The filesystem type, size, and usage at the mount point |
Finding out how much free space the volume group has
Run sudo vgs. The VFree column shows the unallocated space in each VG. If VFree is zero, you must add a disk or enlarge an existing one before you can extend any LV.
Exercise
Which command shows how much unallocated space remains in the volume group vg_data?
Show answer
sudo vgs vg_data. Read the VFree column.