Archive · Linux

LVM: Growing a Volume Without Downtime

Physical volumes, volume groups and logical volumes, and how to extend a full filesystem online.

1 min read

  • Ubuntu 18.04.3 LTS
  • LVM2 2.02
  • ext4

LVM puts a flexible layer between disks and filesystems.

flowchart TB
  D1[Disk sdb] --> PV1[Physical volume]
  D2[Disk sdc] --> PV2[Physical volume]
  PV1 --> VG[Volume group vg_data]
  PV2 --> VG
  VG --> LV[Logical volume lv_app]
  LV --> FS[ext4 mounted at srv app]

Add a disk and grow the volume while it stays mounted:

sudo pvcreate /dev/sdc
sudo vgextend vg_data /dev/sdc
sudo lvextend -r -L +20G /dev/vg_data/lv_app   # -r also resizes the filesystem
df -h /srv/app

-r calls the right resize tool (resize2fs for ext4, xfs_growfs for XFS) in one step. Growing is safe online; shrinking ext4 needs it unmounted, and XFS cannot shrink at all. Check free space in the group first with vgs.