LVM – Cheatsheat

Published on Author gryzli

Some useful LVM commands to me … 

 

 

Logical Volume Operations

Extending logical volume size: 

 

# Change size of logical_volume to 100G 

lvextend -L 100G /dev/volume_group/logical_volume 

 

# Change the size of logical_volume to 100% free space in the Volume Group

lvextend -l +100%FREE  /dev/volume_group/logical_volume 

 

Volume Group Operations

Add physical volume to a Volume Group

vgextend volume_group /dev/sda3

 

Physical Volumes Operations

 

Moving physical volume extents from one partition to another.

Let say you have added new partition, and want to move all lvm extents from old partition to the new one, then delete the old one.

Here is what you must do:

# Move contents of old physical volume to the new one
[root@server ~]# pvmove /dev/sda4  /dev/sda3 
  /dev/sda4: Moved: 0.00%
  /dev/sda4: Moved: 1.09%
  /dev/sda4: Moved: 100%

# Remove old physical volume from volume group
[root@server ~]# vgreduce volume_group /dev/sda4

 

 

Informational / Status printing commands

 

Display physical volumes and their mappings 

[root@server /]# pvdisplay  -m 


  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               39.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10114
  Free PE               0
  Allocated PE          10114
  PV UUID               sp1bAp-2EVX-UY8n-iSqv-Rvr3-7MLR-mM0Sfu
   
  --- Physical Segments ---
  Physical extent 0 to 9849:
    Logical volume      /dev/centos/root
    Logical extents     0 to 9849
  Physical extent 9850 to 10113:
    Logical volume      /dev/centos/swap
    Logical extents     0 to 263

 

Report information about physical volumes 

[root@server]# pvs 
 PV         VG     Fmt  Attr PSize   PFree   
 /dev/sda2  centos lvm2 a--   39.51g      0  
 /dev/sda3  centos lvm2 a--  193.76g 193.76g 
 /dev/sda4  centos lvm2 a--  185.33g   5.33g

 

Display logical volumes

[root@server ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                UaqJOA-WwhM-sjw2-ZfWQ-uSWy-lyT2-WgfmZo
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-07-01 10:53:10 +0100
  LV Status              available
  # open                 1
  LV Size                218.48 GiB
  Current LE             55930
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

 

 

 

Resources

Centos LVM Documentation

 

sssss