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.

1
2
3
# Initialize whole disks as PVs
pvcreate /dev/sdb
pvcreate /dev/sdc

Verify with:

1
2
3
pvs
# or for detailed output:
pvdisplay

Tip: You can increase the metadata area size with --metadatasize if 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:

1
vgcreate vg_data /dev/sdb /dev/sdc

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:

1
2
3
vgs
# or for detailed output:
vgdisplay vg_data

Creating Logical Volumes

Logical Volumes are carved from a VG. There are multiple ways to specify the size.

Example 1: Fixed size in GiB

1
lvcreate -L 50G -n lv_www vg_data

Creates a 50 GiB Logical Volume named lv_www in vg_data.

Example 2: Fixed size in MiB

1
lvcreate -L 512M -n lv_logs vg_data

Creates a 512 MiB Logical Volume named lv_logs.

Example 3: Percentage of free VG space

1
lvcreate -l 100%FREE -n lv_backup vg_data

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:

1
2
3
4
5
6
mkfs.xfs /dev/vg_data/lv_www
# or
mkfs.ext4 /dev/vg_data/lv_logs

mkdir -p /srv/www
mount /dev/vg_data/lv_www /srv/www

Verify with:

1
2
3
lvs
# or
lvdisplay /dev/vg_data/lv_www

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:

1
2
3
4
5
# Initialize the new disk
pvcreate /dev/sdd

# Add it to the existing VG
vgextend vg_data /dev/sdd

Check the updated free space:

1
vgs

Extending a Logical Volume

With free space available in the VG, extend the LV. There are several ways to specify the new size:

1
2
3
4
5
6
7
8
# Add 20 GiB to the LV
lvextend -L +20G /dev/vg_data/lv_www

# Grow the LV to an absolute size of 100 GiB
lvextend -L 100G /dev/vg_data/lv_www

# Use all remaining free space in the VG
lvextend -l +100%FREE /dev/vg_data/lv_www

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:

1
lvextend --resizefs -L +20G /dev/vg_data/lv_www

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:

1
2
3
4
5
# Grow to fill all available space on the LV
xfs_growfs /mountpoint

# Example
xfs_growfs /srv/www

To preview without making changes, use the -n (dry-run) flag:

1
xfs_growfs -n /srv/www

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):

1
2
3
4
5
# Grow to fill all available space on the LV
resize2fs /dev/vg_data/lv_logs

# Or grow to a specific size
resize2fs /dev/vg_data/lv_logs 80G

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:

1
2
3
4
umount /mnt/logs
e2fsck -f /dev/vg_data/lv_logs
resize2fs /dev/vg_data/lv_logs
mount /mnt/logs

Verifying the result

After resizing, confirm the new size:

1
2
df -hT /srv/www
df -hT /mnt/logs

Cheat Sheet

TaskCommand
Create PVpvcreate /dev/sdX
Create VGvgcreate 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 PVpvcreate /dev/sdZ && vgextend vg_name /dev/sdZ
Extend LVlvextend -L +20G /dev/vg_name/lv_name
Extend LV + filesystemlvextend --resizefs -L +20G /dev/vg_name/lv_name
Grow XFSxfs_growfs /mountpoint
Grow ext3/ext4resize2fs /dev/vg_name/lv_name
Show PVs / VGs / LVspvs / vgs / lvs
Detailed infopvdisplay / vgdisplay / lvdisplay

References