LVM Common Commands - CodeSwordsman

Create, mount, grow and remove physical volumes, volume groups and logical volumes, with XFS and ext4 grow differences.

LVM2 (CentOS / Ubuntu)Updated 2026-10-2928 commands

Inspect

Show disks, partitions, filesystems and mount points

lsblk -f

List physical volumes in brief

pvs

List volume groups and free space

vgs

List logical volumes in brief

lvs

Show detailed information for PV / VG / LV

pvdisplay / vgdisplay / lvdisplay

Create Physical Volume

Risky

Initialize a whole disk as a PV (wipes existing partition info)

sudo pvcreate /dev/sdb
Risky

Alternatively initialize a single partition as a PV

sudo pvcreate /dev/sdb1

Verify PV size and free space

pvs -o pv_name,pv_size,pv_free

Create VG & LV

Create a volume group named data_vg

sudo vgcreate data_vg /dev/sdb

Create a 20G logical volume in the VG

sudo lvcreate -L 20G -n data_lv data_vg

Use all remaining VG space for the LV

sudo lvcreate -l 100%FREE -n data_lv data_vg

Create a mirrored LV (requires at least two PVs)

sudo lvcreate -L 10G -n log_lv -m 1 data_vg

Confirm LV names and sizes

lvs -o lv_name,lv_size,pool_lv

Format & Mount

Risky

Format as XFS; use mkfs.ext4 for ext4

sudo mkfs.xfs /dev/data_vg/data_lv

Create a mount point and mount it

sudo mkdir -p /data && sudo mount /dev/data_vg/data_lv /data

Get the UUID; prefer UUID entries in fstab

sudo blkid /dev/data_vg/data_lv

Append this line to /etc/fstab for mounting at boot

UUID=xxxx-xxxx /data xfs defaults 0 0

Run mount -a after editing fstab to avoid boot failures

Extend Online

Add 10G to the logical volume

sudo lvextend -L +10G /dev/data_vg/data_lv

Extend the LV by all remaining VG space

sudo lvextend -l +100%FREE /dev/data_vg/data_lv

Grow an XFS filesystem; argument is the mount point

sudo xfs_growfs /data

Grow an ext4 filesystem; argument is the device path

sudo resize2fs /dev/data_vg/data_lv

Add a new disk to the VG to expand capacity

sudo vgextend data_vg /dev/sdc

Refresh PV size after the underlying disk was enlarged

sudo pvresize /dev/sdb

Shrink & Remove (Risky)

Risky

ext4 shrink flow: unmount, check then resize; XFS cannot shrink

sudo umount /data && sudo e2fsck -f /dev/data_vg/data_lv && sudo resize2fs /dev/data_vg/data_lv 5G
Risky

Shrink an LV; shrink the filesystem first or data will corrupt

sudo lvreduce -L -5G /dev/data_vg/data_lv
Risky

Remove a logical volume; data cannot be recovered

sudo lvremove /dev/data_vg/data_lv
Risky

Remove a volume group

sudo vgremove data_vg
Risky

Remove the PV label

sudo pvremove /dev/sdb

Related tools

This website uses cookies to ensure you get the best experience on our website. Privacy Policy.