LVM basics: create and extend volume groups

Topic: Servers linux

Summary

Create physical volumes, volume groups, and logical volumes with pvcreate, vgcreate, lvcreate; extend an LV when you add disk or need more space. Use this when you want flexible storage that can grow or span disks.

Intent: How-to

Quick answer

  • Create PV: pvcreate /dev/sdb1; VG: vgcreate vg0 /dev/sdb1; LV: lvcreate -L 10G -n lv_data vg0; format and mount the LV at /dev/vg0/lv_data.
  • Extend: add new PV (pvcreate, vgextend vg0 /dev/sdc1); extend LV (lvextend -L +5G /dev/vg0/lv_data); then resize fs (resize2fs or xfs_growfs).
  • List: pvs, vgs, lvs; use the LV device (e.g. /dev/vg0/lv_data) in fstab, not the underlying partition.

Prerequisites

Steps

  1. Create PV, VG, and LV

    pvcreate /dev/sdb1; vgcreate vg0 /dev/sdb1; lvcreate -L 10G -n lv_data vg0; mkfs.ext4 /dev/vg0/lv_data; mount /dev/vg0/lv_data /data.

  2. Add to fstab

    blkid /dev/vg0/lv_data; add UUID=... /data ext4 defaults 0 2 to fstab; use nofail if optional; mount -a.

  3. Extend when needed

    vgextend vg0 /dev/sdc1 (new PV); lvextend -L +5G /dev/vg0/lv_data; resize2fs /dev/vg0/lv_data (ext4) or xfs_growfs /data (xfs).

  4. Verify

    pvs; vgs; lvs; df -h /data; ensure fstab uses the LV or UUID so mount survives reboot.

Summary

You will create LVM physical volumes, volume groups, and logical volumes, format and mount them, and extend an LV when you add space. Use this for flexible, resizable storage.

Prerequisites

  • Root; one or more disks or partitions to use for LVM (not in use).

Steps

Step 1: Create PV, VG, and LV

sudo pvcreate /dev/sdb1
sudo vgcreate vg0 /dev/sdb1
sudo lvcreate -L 10G -n lv_data vg0
sudo mkfs.ext4 /dev/vg0/lv_data
sudo mount /dev/vg0/lv_data /data

Step 2: Add to fstab

Use blkid to get UUID; add line to /etc/fstab; mount -a.

Step 3: Extend when needed

sudo pvcreate /dev/sdc1
sudo vgextend vg0 /dev/sdc1
sudo lvextend -L +5G /dev/vg0/lv_data
sudo resize2fs /dev/vg0/lv_data

Step 4: Verify

pvs, vgs, lvs; df -h; reboot test.

Verification

  • LV exists and is mounted; after extend, df shows larger size; fstab correct.

Troubleshooting

Cannot extend — No free space in VG; add a new PV and vgextend first.

Resize failed — Ensure fs is not mounted or use online resize if supported; backup before resize.

Next steps

Continue to