This will serve you as a quick reference to LVM commands. This is mostly what one will need to manage Logical Volumes in Linux since this covers commands ranging from LVM creation and extension to LVM snapshots and LVM metadata recovery.


pvcreate /dev/sda1 /dev/sdb1
vgcreate vg_apps /dev/sda1 /dev/sdb1

#create LV with all available space from vg_apps
lvcreate -n lv_apps -l 100%FREE vg_apps

#create LV with specific size 
lvcreate -L 108G -n lv_apps vg_apps
mkfs.ext4 /dev/vg_apps/lv_apps

Other FS-TYPES: ext2,ext3,ext4,xfs,btrfs,cramfs,minix

Display PV,VG,LV details



#Extends VG with a new Disk (after pvcreate command has been run the disk eg: pvcreate /dev/sdj1)
vgextend vg_apps /dev/sdj1

#Extends LV by 100GB
lvextend -L +100G /dev/mapper/vg_apps-lv_apps

#Extends LV with all available space in vg_apps
lvextend -l +100%FREE /dev/mapper/vg_apps-lv_apps


#create a snapshot of LV: lv_apps with size 1G 
lvcreate -L 1GB -s -n my_apps_backup /dev/vg_apps/lv_apps /dev/vg_apps/lv_apps_backup

#restore a snapsot
lvconvert --merge /dev/vg_apps/lv_apps_backup

#remove a snapsot
lvremove /dev/vg_apps/lv_apps_backup

NOTE: how to choose snapshot size ?. Snapshots are used to store changes in an LVM from the point it was created. So, let's say that you have a 30GB volume and you take a snapshot. Initially, no space is required. But after a week you see that the snapshot is using 4GB of storage. This means that Size or amount of changes since the point of snapshot creation is is 4G.

To restore the snapshot, we need to un-mount the file system first. And, after the merge is completed, snapshot volume will be removed automatically.


Dealing with “Couldn’t find device with uuid ‘FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'” errors.

This can be a case of an actual missing disk or If the volume group metadata area of a physical volume is accidentally overwritten or otherwise destroyed, you will get an error message indicating that the metadata area is incorrect, or that the system was unable to find a physical volume with a particular UUID. You may be able to recover the data the physical volume by writing a new metadata area on the physical volume specifying the same UUID as the lost metadata.

LVM related files and directories:
/etc/lvm/                - default lvm directory location 
/etc/lvm/backup/         - Contains last backup of metadata for VG
/etc/lvm/archive/        - Contains backup of metadata for VG before something changed
/etc/lvm/lvm.conf        - main lvm configuration file 

Check for failed volumes

vgs -a -o +devices -P
lvs -a -o +devices -P

Couldn't find device with uuid 'DDGRh3-zhok-iVI8-7qTD-S5BI-GAEN-NYM5Sk'.
  Couldn't find all physical volumes for volume group vg_apps.
  Couldn't find device with uuid 'DDGRh3-zhok-iVI8-7qTD-S5BI-GAEN-NYM5Sk'.
  Couldn't find all physical volumes for volume group vg_apps.

Restore Metadata from backup

pvcreate --uuid "DDGRh3-zhok-iVI8-7qTD-S5BI-GAEN-NYM5Sk" --restorefile /etc/lvm/archive/ /dev/sdh1
vgcfgrestore vg_apps
lvchange -ay /dev/vg_apps/lv_apps  

This site uses Akismet to reduce spam. Learn how your comment data is processed.