MARWAN docs NOC knowledge base
DocsGNU/Linux

Create and grow LVM volumes

Create an LVM volume on a new disk, and grow an existing one after enlarging the virtual disk in Proxmox VE.

Published Sami Ait Ali Oulahcen

LVM puts a flexible layer between disks and filesystems: physical volumes (PV) are grouped into a volume group (VG), which is cut into logical volumes (LV) that you can grow later without repartitioning. The examples use a second disk /dev/sdb; check yours with lsblk.

1. Create a partition for LVM (optional)#

You can use the whole disk as a physical volume, or create one partition of type LVM first:

fdisk /dev/sdb
n      # new partition
p      # primary
Enter  # partition number
Enter  # first sector
Enter  # last sector (whole disk)
t      # change type
8e     # Linux LVM
w      # write changes to disk

2. Create the volume#

pvcreate /dev/sdb1
vgcreate vg_data /dev/sdb1
lvcreate -n lv_data -l 100%FREE vg_data
mkfs.xfs /dev/vg_data/lv_data

Mount it and make the mount permanent:

mkdir -p /data
echo '/dev/vg_data/lv_data /data xfs defaults 0 0' >> /etc/fstab
systemctl daemon-reload
mount -a
df -h /data

3. Grow a volume after enlarging the disk in Proxmox#

First enlarge the disk in Proxmox VE (VM → Hardware → Disk Action → Resize, or qm disk resize <vmid> scsi1 +20G on the host). Then, inside the VM:

# let the kernel see the new size (no reboot needed)
echo 1 > /sys/class/block/sdb/device/rescan

# grow the partition, if the PV is on a partition (package cloud-utils-growpart)
growpart /dev/sdb 1

# grow the PV, then the LV and its filesystem in one step
pvresize /dev/sdb1
lvextend -r -l +100%FREE /dev/vg_data/lv_data

-r resizes the filesystem too (xfs_growfs for XFS, resize2fs for ext4). XFS can grow but never shrink.

4. Add a new disk to an existing volume group#

pvcreate /dev/sdc
vgextend vg_data /dev/sdc
lvextend -r -l +100%FREE /dev/vg_data/lv_data

Check the result with pvs, vgs and lvs.