Thursday, June 11, 2020

Some Important Facts about LVM





Suppose you have two volume groups like vg01 and vg02 and both sizes 5 GB. And vgo1 have no logical volumes but vg02 have two logical volumes.

[root@rhelnode1 /]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  rhel   1   2   0 wz--n- 15.63g 4.00m
  vg01   1   0   0 wz--n- 5.00g  4.99g
  vg02   2   2   0 wz--n-  5.00g 0.49g

So, you can split both vgs to utilize the space of vgo1.

[root@rhelnode1 /]# vgsplit vg01 vg02 /dev/sdb
  Existing volume group "vg02" successfully split from "vg01"

Here you have to specify device path of vg01 (/dev/sdb).

Now you can check vgo1 space splits into vg02.

[root@rhelnode1 /]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  rhel   1   2   0 wz--n- 15.63g 4.00m
  vg02   2   2   0 wz--n-  9.99g 5.49g

----------------------------------------------------------------

Extending filesystem in Linux 7


We have a volumegroup vg01 which have free space then and while creating logical volume we had taken less space.So now we can extend logical volume accordingly.


[root@rhelnode1 /]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  rhel   1   4   0 wz--n- 22.01g    4.00m
  vg01   1   1   0 wz--n-  2.00g 1020.00m
[root@rhelnode1 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vg01-backup 1014M   33M  982M   4% /backup

Here we can see vg01 have 1GB free space. So we can extend logical volume named backup by using below command-

[root@rhelnode1 /]# lvextend -L 1.5G /dev/vg01/backup
  Size of logical volume vg01/backup changed from 1.00 GiB (256 extents) to 1.50 GiB (384 extents).
  Logical volume vg01/backup successfully resized.

Now run below command to extand size of logical volume-

[root@rhelnode1 /]# xfs_growfs /dev/vg01/backup
meta-data=/dev/mapper/vg01-backup isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 262144 to 393216

After that, we can check our logical volume have updated space.

[root@rhelnode1 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vg01-backup  1.5G   33M  1.5G   3% /backup





----------------------------------------------------------------


Suppose you have 2 physical volumes in a volume group. But 1 physical volume is sufficient then you can remove another physical volume-

[root@rhelnode1 /]# pvs
  PV         VG   Fmt  Attr PSize  PFree  
  /dev/sda3  rhel lvm2 a--  15.63g   4.00m
  /dev/sdb   vg02 lvm2 a--   5.00g   5.00g
  /dev/sdc   vg02 lvm2 a--   5.00g 508.00m
[root@rhelnode1 /]# vgdisplay vg02
  --- Volume group ---
  VG Name               vg02
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               9.99 GiB
  PE Size               4.00 MiB
  Total PE              2558
  Alloc PE / Size       1152 / 4.50 GiB
  Free  PE / Size       1406 / 5.49 GiB
  VG UUID               vovDvR-WQUV-M0sE-OAZG-emAd-Vw77-Nzdkdv


Here you can see /dev/sdb pv is totally free.then you can reduce your vg by using below command -

[root@rhelnode1 /]# vgreduce  vg02 /dev/sdb
  Removed "/dev/sdb" from volume group "vg02"
[root@rhelnode1 /]# 


Rename of Logical volumes and volume groups -


First of all, you have to change request mode of volume group by using below command :-

[root@rhelnode1 /]# lvchange -a n vg02

[root@rhelnode1 /]# lvs
  LV     VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home   rhel -wi-ao---- 7.81g                                                    
  var    rhel -wi-ao---- 7.81g                                                    
  backup vg02 -wi------- 2.50g                                                    
  sync   vg02 -wi------- 2.00g 

[root@rhelnode1 /]# lvrename /dev/mapper/vg02/sync /dev/mapper/vg02-shared
  Renamed "sync" to "vg02-shared" in volume group "vg02"

Hint - current lvname with path  =    /dev/mapper/vg02/sync
          New lvname with path        =    /dev/mapper/vg02-shared


[root@rhelnode1 /]# vgrename /dev/mapper/vg02 /dev/mapper/vg00
  Volume group "vg02" successfully renamed to "vg00"

Hint-  Current vgname with path     =       /dev/mapper/vg02
          New vgname with path            =        /dev/mapper/vg00


[root@rhelnode1 /]# lvs
  LV          VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home        rhel -wi-ao---- 7.81g                                                    
  var         rhel -wi-ao---- 7.81g                                                    
  backup      vg00 -wi------- 2.50g                                                    
  vg02-shared vg00 -wi------- 2.00g                                                    
[root@rhelnode1 /]# 

Now you can change request mode by using below command : -


[root@rhelnode1 /]# vgchange -a y vg00
  Volume group "vg00" successfully changed.

Now you can mount your mount point and change also /etc/fstab entries.


How to check your volume group is clustered or non-clustered?


[root@rhelnode1 /]# vgdisplay vg00 --config 'global {locking_type=0}'
  WARNING: Locking disabled. Be careful! This could corrupt your metadata.
  --- Volume group ---
    Clustered                yes

If you want convert clustered volume into non clustered volume then use below command -

[root@rhelnode1 /]# vgchange -cn vg00 --config 'global {locking_type=0}'
  WARNING: Locking disabled. Be careful! This could corrupt your metadata.
  Volume group "vg00" is changed to not clustered.
[root@rhelnode1 /]# 

Now successfully changed.







No comments:

Post a Comment

Introduction to Linux Part 1

Introduction to Linux Part 1

Introduction to Linux Linux is an operating system that works just like Windows and Mac OS X. As an operating system, Linux is a very h...