Common LVM Procedures

From V.S.V., Inc.
Jump to navigation Jump to search
  • rough notes, will clean up*

Common Commands:

pvdisplay pvscan pvs vgdisplay vgscan vgs lvdisplay lvscan vgs

- Creating a new Logical Volume:

    -Find Volume Group name, and make sure there is enough free space to create a new logical volume:
      [root@devapp101 ~]# vgdisplay
       --- Volume group --- 
       VG Name               VolGroup00
       Alloc PE / Size       480 / 15.00 GB
       Free  PE / Size       3891 / 121.59 GB
     -Create new volume, specifying the size, logical volume name and the Volume Group you will create it in:
       lvcreate -L 15G -n lv_u01 VolGroup00
     -Format new volume:
       mke2fs -j /dev/VolGroup00/lv_u01 -m1 -L /u01
     -Mount the new volume:

-Extending an existing volume

   This example extends the /home/bea volume 20G
   Verify there is enough space by doing a vgdisplay
   df -h to find volume name
   lvresize -L +20G /dev/VolGroup00/lv_home_bea
   resize2fs /dev/VolGroup00/lv_home_bea 
   df -h to verify the extended file system
      • If the system cannot use resize2fs use ext2online
   ext2online -C /dev/mapper/VolGroup00/lv_home_bea /home/bea

-Extending an existing SWAP volume

vgdisplay /dev/VolGroup00 to check for free space swapoff -v /dev/VolGroup00/lv_swap lvextend -L +23G /dev/VolGroup00/lv_swap mkswap /dev/VolGroup00/lv_swap swapon -va /dev/VolGroup00/lv_swap cat /proc/swaps and or free

- Adding more disk to a VM and using disk and pvcreate to allocate the new space. - NO REBOOT REQUIRED

The following steps were used to give more space to /var on ossec201, a VM

  1. Check things out

fdisk -l vgdisplay ls -l /dev/sd*

  1. Let OS see added space (reboot or)

echo 1 > /sys/block/sdX/device/rescan

  1. Create partition from added space

fdisk /dev/sda #(adding new primary partition #3) fdisk -l # confirm new space is present partprobe # probe for new partition

  1. Add new PV to VG

pvcreate /dev/sda3 vgdisplay vgextend VolGroup00 /dev/sda3 vgdisplay

  1. Resize the LV

lvresize -L +15G /dev/VolGroup00/lv_var resize2fs /dev/VolGroup00/lv_var resize4fs /dev/VolGroup00/lv_var # for ext4 filesystems

  1. Verify

ls -l /dev/sd* df -h vgdisplay

  1. If the file system is XFS, then add the space to the LVM by one of the methods above then issue the command:
xfs_growfs -d /dev/mapper/<Volume Name>


xfs_growfs -d /dev/mapper/VolGroup01-lv_storage

Main Page