Skip to content

4.3 Logical Volume Management (LVM)

LVM allows you to abstract physical storage. You can combine multiple disks into one pool and resize volumes on the fly.

graph TD
    Disk1[Physical Disk 1 /dev/sdb] --> PV1[Physical Volume]
    Disk2[Physical Disk 2 /dev/sdc] --> PV2[Physical Volume]
    PV1 --> VG[Volume Group 'my_vg']
    PV2 --> VG
    VG --> LV1[Logical Volume 'db_vol']
    VG --> LV2[Logical Volume 'web_vol']
    LV1 --> FS1[Ext4 Filesystem]
    LV2 --> FS2[XFS Filesystem]

Mark the raw disks for LVM use.

sudo pvcreate /dev/sdb /dev/sdc

Create a pool called data_vg.

sudo vgcreate data_vg /dev/sdb /dev/sdc

Carve out a chunk.

# Create a 10GB volume named 'backups'
sudo lvcreate -n backups -L 10G data_vg

It is accessed at /dev/data_vg/backups.

Treat it like a normal partition.

sudo mkfs.ext4 /dev/data_vg/backups
sudo mount /dev/data_vg/backups /mnt/backups

If you run out of space in backups, and data_vg has free space:

# Extend the LV and the Filesystem in one go (-r)
sudo lvextend -L +5G -r /dev/data_vg/backups