Sub topic 1
How LVM Layers Storage: PVs, VGs, and LVs
Prerequisites
You should be comfortable using the Linux command line with sudo. You should also know that a block device is storage that Linux can read and write, such as /dev/sda, and that a mount point is a directory where a filesystem becomes available, such as /srv/data. This chapter assumes basic familiarity with partitions, filesystems such as ext4 and XFS, and commands such as lsblk and df.
The storage layers
Logical Volume Manager, or LVM, adds a flexible storage layer between disks and filesystems. Instead of putting a filesystem directly on one disk partition, you combine storage into a pool and create virtual block devices from that pool.
LVM uses three main objects:
- A physical volume (PV) is a disk or partition prepared for LVM.
- A volume group (VG) is a pool made from one or more physical volumes.
- A logical volume (LV) is a virtual block device allocated from a volume group.
A filesystem is created inside an LV. The filesystem then gets mounted at a directory. Applications use the mount point and usually do not need to know which physical disk provides the storage.
The layers have different jobs:
| Layer | Example | Main job |
|---|---|---|
| Physical volume | `/dev/sdc` or `/dev/sda3` | Supplies storage extents to LVM |
| Volume group | `vg_data` | Pools free storage from its physical volumes |
| Logical volume | `/dev/vg_data/lv_app` | Presents an adjustable block device |
| Filesystem and mount | XFS at `/srv/app` | Stores files and makes them available |
Physical volumes
A PV is the boundary where LVM begins managing storage. You can create a PV on an entire disk, such as /dev/sdc, or on a partition, such as /dev/sda3. The choice depends on the server's partitioning design and operational standards.
When LVM initializes a device as a PV, it writes LVM metadata to that device. The metadata identifies the PV and records which volume group can use it. The remaining space is divided into fixed-size allocation units called physical extents.
Do not treat a PV as a normal filesystem. You should not mount /dev/sdc after using pvcreate on it. The PV supplies raw capacity to a volume group. The filesystem belongs on an LV created later.
A disk can also contain a partition table, and one partition can be an LVM partition. In that design, the partition is the PV rather than the whole disk. Always check the device hierarchy before changing it. Choosing the wrong device for pvcreate can overwrite existing data.
Volume groups
A VG combines one or more PVs into one pool of free extents. For example, vg_data might contain 100 GiB from /dev/sda3 and 200 GiB from /dev/sdc. The volume group then has roughly 300 GiB available, minus metadata and any capacity already assigned to LVs.
The pool does not automatically belong to any filesystem. Free space in a VG is unallocated capacity. You can use it later to create a new LV or extend an existing one.
This separation is the main reason LVM is useful on servers. You can add a new PV to a VG without moving the files from existing LVs. You can also extend an LV when the VG has enough free extents. The filesystem still needs to be grown after the LV grows, because the filesystem has its own view of its device size.
A VG can span several disks, but that does not mean every file is stored on every disk. LVM allocates extents to each LV. Depending on allocation choices, an LV may use one PV or several PVs.
Logical volumes
An LV is a virtual block device with a path such as /dev/vg_data/lv_app. Linux commonly exposes the same device through a device-mapper path under /dev/mapper/. You normally use the stable LVM path or a filesystem label or UUID in configuration rather than relying on a changing disk name.
An LV has a size measured in extents. You can create one with a fixed size and later extend it into unused VG space. For example, a 20 GiB LV might contain an ext4 filesystem mounted at /srv/app.
The LV does not know whether its contents are ext4, XFS, swap, or another format. It only provides blocks. The filesystem interprets those blocks and manages directories, file metadata, and free space.
This distinction explains a common resizing issue. Extending an LV makes the block device larger, but it does not necessarily make the filesystem larger. A filesystem-specific growth operation must follow. For ext4, the usual tool is resize2fs. For XFS, the usual tool is xfs_growfs, which operates on a mounted filesystem.
Inspecting the model
Use several commands together to understand the complete layout:
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/dataThe LVM commands show the PV, VG, and LV layers. lsblk -f connects block devices with filesystem types, labels, UUIDs, and mount points. df -hT shows the capacity that the mounted filesystem currently exposes to applications.
A typical relationship might look like this:
/dev/sda3is a PV./dev/sda3belongs tovg_data.vg_datacontains/dev/vg_data/lv_app.lv_appcontains an XFS filesystem.- The XFS filesystem is mounted at
/srv/data.
The same inspection helps you decide where new capacity can come from. If the VG has free space, you may extend an LV directly. If the VG has no free space, you must first add capacity, either by adding another PV or by enlarging an existing disk and then updating its PV.
The working model
Think of LVM as a set of containers:
- A PV supplies raw storage.
- A VG pools storage from one or more PVs.
- An LV takes a portion of the pool.
- A filesystem organizes the LV's blocks into files.
- A mount point exposes those files to applications.
Each layer has its own size and state. A successful storage change must update every layer that needs to know about the new capacity. This layered model also helps isolate errors: a disk may be larger while its PV still has its old size, or an LV may be larger while its filesystem still reports the old size.
Exercise
An administrator extends /dev/vg_data/lv_app by 20 GiB, but df -hT /srv/app still shows the old capacity. Which layer has changed, and what operation is still needed?
Show answer
The logical-volume layer has changed. The filesystem inside the LV still needs to be grown with its filesystem-specific tool, such as resize2fs for ext4 or xfs_growfs for XFS.