Skip to content

LVM Maintain

1. LVM Creation

  • 1.1 Check the disk location

Check disk name and location

lsblk   # check new disk name
fdisk -l    # check new disk location
  • 1.2 Create PV

PV: Physical Volum

pvcreate /dev/sdb
  • 1.3 Create VG

VG: Volum Group

vgcreate -s 256M vgdata /dev/sdb
  • 1.4 Check the number of available PEs in the VG

PE:

vgdisplay |grep "Free"
  • 1.5 Create LV and assign PEs

LV: Logical Volum

lvcreate -l 4095 -n lvdata vgdata
  • 1.6 Format LVM partition
mkfs.xfs /dev/vgdata/lvdata
  • 1.7 Mount LVM partition

Create mount point

mkdir /data

Mount LVM to /data

mount /dev/vgdata/lvdata /data

Add mount point to /etc/fstab (for automatically mount on startup)

grep -Fxq "/dev/vgdata/lvdata      /data   xfs     defaults        0 0" /etc/fstab || echo "/dev/vgdata/lvdata      /data   xfs     defaults        0 0" | sudo tee -a /etc/fstab
  • 1.8 Check VG/LV
vgdisplay
lvdisplay

2. LVM Expansion

  • 2.1 Add new disk and check the disk location

Check disk name and location

lsblk   # check new disk name
fdisk -l    # check new disk location
  • 2.2 Create PV
pvcreate /dev/sdb
  • 2.3 Extend VG

Check VG/LV name, and LV location

lvdisplay

image-20260123090649700

Add new disk(PV) to existing VG

vgextend vgdata /dev/sdb
  • 2.4 Extend LV

Confirm the remaining available space in the VG

vgdisplay |grep "Free"

image-20260123090948281

Add the remaining available space to the LV

lvextend -l +2559 /dev/vgdata/lvdata
    # parameter descrption:
    # -l : add the specified number of PE
    # -L : add the specified amount of space
  • 2.5 Refresh LVM

Refresh the LVM partition

xfs_growfs /dev/vgdata/lvdata

If the file system is ext, please use the following command to refresh the partition.

resize2fs /dev/vgdata/lvdata

3. LVM Deletion

  • 3.1 Check LVM and disk status
df -h
lsblk
  • 3.2 Umount the LVM file system
umount /dev/vgdata/lvdata
  • 3.3 Remove the LV (you can view all LVs using lvscan or lvdisplay)
lvremove /dev/vgdata/lvdata
  • 3.4 Remove the "Active" lable of VG
vgchange -a n vgdata
  • 3.5 Remove VG (you can view all VGs using vgscan or vgdisplay)
vgremove vgdata
  • 3.6 Remove PG
pvremove /dev/sdb