LVM - noyage/redhat GitHub Wiki

Adding a disk to LVM

List available disks

  • # lsblk
  • # fdisk -l
  • # parted --> print

Create a PV, VG, LV and filesystem on the LV

# pvcreate /dev/sdb
# vgcreate myvg /dev/sdb
# lvcreate -L 30G -n mylv myvg

# mkfs.xfs /dev/mapper/myvg-mylv   <--- xfs filesystem
# mkfs.ext4 /dev/mapper/myvg-mylv   <--- ext4 filesystem

Example add sdb to LVM

# pvcreate /dev/sdb
# vgextend (vg-name) /dev/sdb

# vgs

Grow a filesystem

# lvextend -L +10G /dev/mapper/(lv_name)

resize2fs /dev/mapper/(lv_name)    <-- if ext4

Background Info

Logical Volume Manager

  • LVM is used to manage disk storage
  • allows filesystems to be resized, span across multiple physical disks, use random disk space, etc.
  • Allows us to accumulate spaces from one or many partitions or disks(physical volume) to form a logical container(volume group) which is then divided to logical partitions

Components of LVM

  • Physical Volumes (PV) - disk devices

    • created when a block storage device such as a partition or entire disk is brought under LVM control after going through initialization process.
  • Volume Groups (VG) - typically use just one VG

    • space from all physical volumes in a volume group is aggregated to form one large pool of storage, which is then used to build one or more logical volumes
  • Logical Volumes (LV) - one LV for each filesystem

    • A volume group consists of a pool of storage taken from one or more physical volumes. This volume group space is divided into one or more logical partitions called logical volumes

LVM commands

  • check available space
    • # vgs
  • list physical devices available to LVM
    • # pvdisplay
  • list volume groups
    • # vgdisplay
  • list logical volumes
    • # lvdisplay

Grow EXT4 filesystem

# lvextend -L +8G /dev/mapper/xyz
# resize2fs /dev/mapper/xyz

Grow XFS filesystem

# lvextend -L +8G /dev/mapper/xyz
# xfs_growfs /dev/mapper/xyz

Fdisk vs Gdisk

  • Both use different disk partition table schemes
  • Fdisk uses MBR(Master Boot Record)
  • Gdisk uses GPT(Globally Unique Disk Identifier Partition Table) used by UEFI (Unified Extensible Firmware Interface)