Difference between revisions of "LVM"

From Alessandro's Wiki
(Created page with ' = fast command line = pvdisplay lvremove lvdisplay')
 
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:


= Info =


*; Phisical Volumes
pvs


*; Volume Groups
vgs
*; Logical Volumes
lvs


= fast command line =
= Phisical Volumes (PV) =
pvs
  PV        VG        Fmt  Attr PSize  PFree 
  /dev/sda  vg_1 lvm2 a--  930.82g      0
  /dev/sdb  vg_1 lvm2 a--  931.31g 931.31g
* Phisical to Virtual
  lvs -a -o +devices
* Segmentation
pvs -v --segments /dev/sdb1
  PV        VG          Fmt  Attr PSize  PFree  Start SSize LV  Start Type  PE Ranges     
  /dev/sdb1  server03-vg lvm2 a--  58.35g 40.35g    0  4608 root    0 linear /dev/sdb1:0-4607
  /dev/sdb1  server03-vg lvm2 a--  58.35g 40.35g  4608 10330          0 free                 


pvdisplay


lvremove
== add a disk to a PV ==
  vgextend vg_1 /dev/sdb
  Volume group "vg_1" successfully extended


  lvdisplay
== remove a disk from PV ==
  vgreduce vg_1 /dev/sdb
  Removed "/dev/sdb" from volume group "vg_1"
 
== delete a PV ==
vgremove vg_1
Volume group "vg_1" successfully removed
 
== xx is using an old PV header, modify the VG to update. ==
appears when moving/updating from RHEL5 to 6 then RHEL6 to 7 and to 8
* update PV header version
vgck --updatemetadata xx
* check PV header version
pvck --dump headers /dev/<device
 
= Resizing out from Disk->PV->LV->Partition =
* After resizing a physical drive this commands will claim the space gained to the file system.
*resizing LVM linux partition to the new disk boundaries
pvresize /dev/md1
 
pvresize --setphysicalvolumesize (size here) /dev/sda5
 
* adding 100G
lvextend -L+100G /dev/mapper/vg0-var
* ext4 resizing command
resize2fs /dev/mapper/vg0-var
 
df -hT
 
= Logical Volumes =
== create a mirror volume ==
 
lvcreate -L 931g vg_1 -m 1 vg_1
 
== create a mirror from existing and mounted volume ==
 
lvconvert -m1 vg_1/lv_home
 
* then we check the result:
# pvs;echo;vgs;echo;lvs
  PV        VG        Fmt  Attr PSize  PFree
  /dev/sda2  vg_1 lvm2 a--  930.82g    0
  /dev/sdb  vg_1 lvm2 a--  931.31g 56.33g
 
  VG        #PV #LV #SN Attr  VSize VFree
  vg_1  2  3  0 wz--n- 1.82t 56.33g
 
  LV      VG        Attr    LSize  Pool Origin Data%  Move Log          Copy%  Convert
  lv_home vg_1 mwi-aom- 874.98g                        lv_home_mlog 100.00       
  lv_root vg_1 -wi-ao--  50.00g                                                   
  lv_swap vg_1 -wi-ao--  5.84g

Latest revision as of 20:42, 20 January 2025

Info

  • Phisical Volumes
pvs
  • Volume Groups
vgs
  • Logical Volumes
lvs

Phisical Volumes (PV)

pvs
 PV         VG         Fmt  Attr PSize   PFree  
 /dev/sda  vg_1 lvm2 a--  930.82g      0 
 /dev/sdb  vg_1 lvm2 a--  931.31g 931.31g
  • Phisical to Virtual
 lvs -a -o +devices
  • Segmentation
pvs -v --segments /dev/sdb1
 PV         VG          Fmt  Attr PSize  PFree  Start SSize LV   Start Type   PE Ranges       
 /dev/sdb1  server03-vg lvm2 a--  58.35g 40.35g     0  4608 root     0 linear /dev/sdb1:0-4607
 /dev/sdb1  server03-vg lvm2 a--  58.35g 40.35g  4608 10330          0 free                   


add a disk to a PV

 vgextend vg_1 /dev/sdb
 Volume group "vg_1" successfully extended

remove a disk from PV

vgreduce vg_1 /dev/sdb
 Removed "/dev/sdb" from volume group "vg_1"

delete a PV

vgremove vg_1
Volume group "vg_1" successfully removed

xx is using an old PV header, modify the VG to update.

appears when moving/updating from RHEL5 to 6 then RHEL6 to 7 and to 8

  • update PV header version
vgck --updatemetadata xx
  • check PV header version
pvck --dump headers /dev/<device

Resizing out from Disk->PV->LV->Partition

  • After resizing a physical drive this commands will claim the space gained to the file system.
  • resizing LVM linux partition to the new disk boundaries
pvresize /dev/md1
pvresize --setphysicalvolumesize (size here) /dev/sda5
  • adding 100G
lvextend -L+100G /dev/mapper/vg0-var
  • ext4 resizing command
resize2fs /dev/mapper/vg0-var
df -hT

Logical Volumes

create a mirror volume

lvcreate -L 931g vg_1 -m 1 vg_1

create a mirror from existing and mounted volume

lvconvert -m1 vg_1/lv_home
  • then we check the result:
# pvs;echo;vgs;echo;lvs
 PV         VG         Fmt  Attr PSize   PFree 
 /dev/sda2  vg_1 lvm2 a--  930.82g     0 
 /dev/sdb   vg_1 lvm2 a--  931.31g 56.33g
 VG         #PV #LV #SN Attr   VSize VFree 
 vg_1  2   3   0 wz--n- 1.82t 56.33g
 LV      VG         Attr     LSize   Pool Origin Data%  Move Log          Copy%  Convert
 lv_home vg_1 mwi-aom- 874.98g                         lv_home_mlog 100.00        
 lv_root vg_1 -wi-ao--  50.00g                                                    
 lv_swap vg_1 -wi-ao--   5.84g