This is a personal quick-reference for working with LVM (Logical Volume Manager) on Linux. It covers the full lifecycle from creating Physical Volumes through extending Logical Volumes, and finally growing the filesystem on top.
LVM Concepts at a Glance
LVM introduces three abstraction layers between physical disks and mounted filesystems:
- Physical Volume (PV) — a whole disk initialized for LVM use.
- Volume Group (VG) — a storage pool made up of one or more PVs.
- Logical Volume (LV) — a virtual partition carved out of a VG, on which you create a filesystem.
The general workflow is always: PV → VG → LV → Filesystem.
Creating Physical Volumes
Before a disk can be used by LVM, it needs to be initialized as a Physical Volume.
Verify with:
Tip: You can increase the metadata area size with
--metadatasizeif you plan to use many snapshots. A too-small metadata area can cause issues later. Example:pvcreate --metadatasize 512k /dev/sdb
Creating a Volume Group
Combine one or more PVs into a Volume Group:
| |
This creates a VG named vg_data spanning both PVs. The default Physical Extent (PE) size is 4 MiB, which is fine for most use cases.
Verify with:
Creating Logical Volumes
Logical Volumes are carved from a VG. There are multiple ways to specify the size.
Example 1: Fixed size in GiB
| |
Creates a 50 GiB Logical Volume named lv_www in vg_data.
Example 2: Fixed size in MiB
| |
Creates a 512 MiB Logical Volume named lv_logs.
Example 3: Percentage of free VG space
| |
Uses all remaining free space in vg_data. Other useful percentage variants:
-l 50%FREE— use 50% of the remaining free space-l 80%VG— use 80% of the total VG size
After creation, format the LV and mount it:
Verify with:
Extending LVM: PV, VG, and LV
Adding a new PV and extending the VG
When you attach new storage, initialize it and add it to an existing VG:
Check the updated free space:
| |
Extending a Logical Volume
With free space available in the VG, extend the LV. There are several ways to specify the new size:
Shortcut: extend LV and resize filesystem in one step
Modern LVM supports the -r (--resizefs) flag, which automatically grows the filesystem after extending the LV:
| |
This works for both XFS and ext3/ext4 and is the recommended approach for most cases. If you prefer (or need) to do it manually, read on.
Growing Filesystems After LV Extension
After extending a Logical Volume, the filesystem still has its original size. You need to grow it separately (unless you used --resizefs above).
XFS
XFS filesystems must be mounted to be grown. The xfs_growfs command takes the mount point as its argument:
To preview without making changes, use the -n (dry-run) flag:
| |
Important: XFS can only be grown, never shrunk. Plan your layout accordingly.
ext3 / ext4
ext3 and ext4 filesystems are grown with resize2fs. Unlike XFS, this command takes the device path (not the mount point):
ext4 supports online (mounted) resizing. For ext3 this also works in most cases, but if you encounter issues, unmount first and optionally run a filesystem check:
Verifying the result
After resizing, confirm the new size:
Cheat Sheet
| Task | Command |
|---|---|
| Create PV | pvcreate /dev/sdX |
| Create VG | vgcreate vg_name /dev/sdX [/dev/sdY ...] |
| Create LV (fixed size) | lvcreate -L 50G -n lv_name vg_name |
| Create LV (% of free) | lvcreate -l 100%FREE -n lv_name vg_name |
| Extend VG with new PV | pvcreate /dev/sdZ && vgextend vg_name /dev/sdZ |
| Extend LV | lvextend -L +20G /dev/vg_name/lv_name |
| Extend LV + filesystem | lvextend --resizefs -L +20G /dev/vg_name/lv_name |
| Grow XFS | xfs_growfs /mountpoint |
| Grow ext3/ext4 | resize2fs /dev/vg_name/lv_name |
| Show PVs / VGs / LVs | pvs / vgs / lvs |
| Detailed info | pvdisplay / vgdisplay / lvdisplay |