Wise people learn when they can; fools learn when they must - Arthur Wellesley

Saturday, 2 March 2019

LINUX-51 LVM REVIEW / RECAP

                                  LINUX-51  LVM REVIEW


                LINUX LVM REVIEW / RECAP:
                     
  1. What is LVM
  2. Why LVM is required
  3. What is the difference between LVM & RAID
  4. What is Physical Extent (PE) & Logical Extent (LE) 
  5. Define PV, LV, VG
  6. How to create PV
  7. How to create VG
  8. How to create LV
  9. What is difference between -L & -l while creating LV.
  10. What are various options we get with -l while creating LV
  11. What are Linear / Striped & Mirrored Volume.
  12. How to create Linear Volume.
  13. How to create Striped Volume.
  14. How to create 2-way mirrored volume
  15. How to create 3-way mirrored volume
  16. How to know the LV’s are linear/striped or mirrored.
  17. How to extend VG, write down the steps
  18. How to reduce VG, write down the steps
  19. How to extend LV, write down the steps
  20. How to reduce LV, write down the steps
  21. Can we extend VG & LV online
  22. Can we reduce VG & LV online.
  23. How to rename LV
  24. How to rename VG
  25. How to remove LV
  26. How to remove VG
  27. How to remove PV
  28. How to activate/deactivate VG & LV
  29. How to change the RW permission of LV
  30. How to force a resync of mirror.
  31. How to import & deport a VG
  32. What is LVM Metadata
  33. What is the lvm config backup location
  34. Name the lvm daemon
  35. Main configuration file for LVM
  36. How to take LVM backup
  37. How to take LVM backup at particular location
  38. How to restore LVM backup
  39. In what circumstances LVM will fail to restore
  40. How to know which disks are used for which vg/lv
  41. What is lvmdump
  42. How many volume groups can be created in Linux?
  43. How to re-create the device files for LVM volumes?




///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



1.      What is LVM
Form of storage virtualization, which is much more flexible in terms of management like create/resize/delete logical partitions.

2.      Why LVM is required

It depends on condition/situation, how much control we need on disk/storage management.
LVM can be dynamically reduced or expanded
LVM can exceed the size of a single physical disk
LVM can allow redundancy by mirroring
LVM can enhance performance by striping
LVM can allow to create snapshot
LVM can allow backup and restoration of lvm config

3.      What is the difference between LVM & RAID

RAID is basically solution for redundancy, it does not provide any data backup solution. RAID can be HW or SW based.
LVM is completely logical, gives micro control over disk partitions along with benefits of RAID, we can configure RAID on LVM. Side by side LVM also provide data backup facility and we can take config backup also.

4.      What is Physical Extent (PE) & Logical Extent (LE)

The physical extent (PE) size is the basic unit out of which logical volumes are created. It defines the minimum size of a volume and the possible increments (having a 4MB PE size would mean the minimum volume size is 4MB and you can grow it in 4MB increments).

Making the PE too small wouldn't be recommended, as the maximum volume size is 65,536 PEs, so if you reduce this to 1MB, you end up with volumes not larger than 64GB.

The extent size can impact tools performance, but won't impact I/O. If you're creating large logical volumes, then a larger PE size will result in fewer extents, so the tools be faster, but again the I/O performance is not impacted either way.

Each logical volume is split into chunks of data, known as logical extents. The extent size is the same for all logical volumes in the volume group.

5.      Define PV, LV, VG

Physical volume (PV): PV’s are the partitions on hard disk, or hard disk itself. PV’s are the base of LVM structure.

Volume Group (VG): VG’s are the combined physical volume into a single pool of storage. PV’s are grouped together to form VG.

VGs are made up of PVs, which in turn are made up of physical extents (PEs). The size of PE can differ in different VGs and is defined at the time of creating VG.
– The default size of PE is 4MB, but you can change it to the value you want at the time of VG creation.
– Generally, larger the PE size, better the performance (though less granular control of LV).

Logical volume (LV): LV’s are the actual partitions on system created from VG. LV’s are usable and we can create file system on that.

6.      How to create PV

pvcreate <disk name/s>

7.      How to create VG

vgcreate <vg-name> <disk-name/s>

8.      How to create LV

lvcreate -L 100M -n <LV-Name> <VG-Name>

9.      What is difference between -L & -l while creating LV.

-L is for size
-l is for PE/FREE size with %

10.  What are various options we get with -l while creating LV

[root@rhel6-client1 ~]# lvcreate -l 20%VG -n mylv vg01
[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n mylv2 vg01
[root@rhel6-client1 ~]# lvcreate -l 130 -n mylv3 vg01 (130x4=520MB) 130 is PE size (1PE=4MB)

11.  What are Linear / Striped & Mirrored Volume.

Linear is normal volume we create without any argument
Stripe is for large sequential reads and writes, can improve the efficiency of the data I/O.
Mirror maintains identical copies of data on different devices. When data is written to one device, it is written to a second device as well. This provides protection for device failures.

12.  How to create Linear Volume.

[root@rhel6-server ~]# lvcreate -L 100M -n mylv01 vg01

13.  How to create Striped Volume.

[root@rhel6-server ~]# lvcreate -L 100M -i2 -I64 -n mystripevol01 vg01

-i is the no of stripes
-I is the stripe size (tuned to a power of 2 between 4kB and 512kB)

14.  How to create 2-way mirrored volume

[root@rhel6-server ~]# lvcreate -L 100M -m1 -n mymirrorvol01 vg01
-m1 creates one mirror, which yields two copies of the file system: a linear logical volume plus one copy. Similarly, specifying -m2 creates two mirrors, yielding three copies of the file system.

15.  How to create 3-way mirrored volume

[root@rhel6-server ~]# lvcreate -L 100M -m2 -n mymirrorvol02 vg01

16.  How to know the LV’s are linear/striped or mirrored.

[root@rhel6-server ~]# lvs -a -o segtype,devices,lv_name,vg_name

17.  How to extend VG, write down the steps

[root@rhel6-server ~]# vgextend vg01 /dev/sdc

18.  How to reduce VG, write down the steps

[root@rhel6-server ~]# vgreduce new-vg01 /dev/sdd
  Physical volume "/dev/sdd" still in use

First check VG’s having how many disks and which disk contain which LV. Remove/Move that LV and free the disk then remove it.

[root@rhel6-server ~]# lvs -a -o segtype,devices,lv_name,vg_name
[root@rhel6-server ~]# lvremove /dev/new-vg01/mirroredvol01
[root@rhel6-server ~]# vgreduce new-vg01 /dev/sdd

[root@rhel6-server ~]# vgs -o +devices
[root@rhel6-server ~]# lvs -o +devices

19.  How to extend LV, write down the steps

[root@rhel6-server ~]# lvextend -L +300M /dev/vg01/mystripevol01
[root@rhel6-server ~]# resize2fs /dev/vg01/mystripevol01

20.  How to reduce LV, write down the steps

unmount the file system for reducing.
[root@rhel6-server ~]# umount /stest/

Check the file system after unmount.
[root@rhel6-server ~]# e2fsck /dev/mapper/vg01-mystripevol01

Reduce the file system.
[root@rhel6-server ~]# resize2fs /dev/vg01/mystripevol01 150M

Reduce the Logical Volume size than Current size.
[root@rhel6-server ~]# lvreduce -L 150M /dev/vg01/mystripevol01

Recheck the file system for error.
[root@rhel6-server ~]# e2fsck -f /dev/vg01/mystripevol01

Remount the file-system back to stage.
[root@rhel6-server ~]# mount /dev/vg01/mystripevol01 /stest

21.  Can we extend VG & LV online
              Yes
22.  Can we reduce VG & LV online.
               NO
23.  How to rename LV

[root@rhel6-server ~]# lvrename /dev/vg01/mystripevol01 test-sripe01
[root@rhel6-server ~]# umount /stest/
[root@rhel6-server ~]# mount /dev/vg01/test-sripe01 /stest/

Change the names in fstab

24.  How to rename VG

[root@rhel6-server ~]# vgrename vg01 new-vg01
[root@rhel6-server ~]# umount /stest
[root@rhel6-server ~]# mount /dev/new-vg01/test-sripe01 /stest/

Change the names in fstab

25.  How to remove LV

umount the FS and do lvremove
[root@rhel6-server ~]# umount /stest/
[root@rhel6-server ~]# lvremove /dev/new-vg01/test-sripe01

26.  How to remove VG

Check any LV is using that disk or not,
[root@rhel6-server ~]# lvs -a -o segtype,devices,lv_name,vg_name

[root@rhel6-server ~]# vgremove new-vg01

27.  How to remove PV
[root@rhel6-server ~]# pvremove /dev/sdd

28.  How to activate/deactivate VG & LV

VG: DEACTIVATE
Umount all mounted FS,

#vgchange –a (available) y (yes) or n (no) vgname
[root@rhel6-server ~]# vgchange -an new-vg01
  Can't deactivate volume group "new-vg01" with 1 open logical volume(s)
[root@rhel6-server ~]# umount /stest/
[root@rhel6-server ~]# vgchange -an new-vg01
[root@rhel6-server ~]# lvdisplay /dev/new-vg01/mylv01
LV Status              NOT available ç

VG:ACTIVATE
[root@rhel6-server ~]# vgchange -ay new-vg01
  3 logical volume(s) in volume group "new-vg01" now active
[root@rhel6-server ~]# lvdisplay /dev/new-vg01/mylv01
LV Status              available ç

LV: DEACTIVATE

[root@rhel6-server ~]# lvchange -an /dev/new-vg01/mylv01
  Logical volume new-vg01/mylv01 contains a filesystem in use.
[root@rhel6-server ~]# umount /stest/
[root@rhel6-server ~]# lvchange -an /dev/new-vg01/mylv01
[root@rhel6-server ~]# lvs
  mylv01  new-vg01       -wi------ 200.00m  ç

LV:ACTIVATE

[root@rhel6-server ~]# lvchange -ay /dev/new-vg01/mylv01
[root@rhel6-server ~]# lvs |grep mylv01
  mylv01  new-vg01       -wi-a---- 200.00m

29.  How to change the RW permission of LV

[root@rhel6-server ~]# lvchange -pr /dev/new-vg01/mylv01
  Logical volume "mylv01" changed
[root@rhel6-server ~]# lvdisplay /dev/new-vg01/mylv01 |grep -i write
  LV Write Access        read only

[root@rhel6-server ~]# lvchange -prw /dev/new-vg01/mylv01
  Logical volume "mylv01" changed
[root@rhel6-server ~]# lvdisplay /dev/new-vg01/mylv01 |grep -i write
  LV Write Access        read/write

30.  How to force a resync of mirror.

[root@rhel6-server ~]# lvchange --resync /dev/new-vg01/mylv01

31.  How to import & deport a VG

Suitable in Cluster environment which uses shared storage.
Umount all FS
Deactivate VG
Export VG
[root@rhel6-server ~]# umount /stest/
[root@rhel6-server ~]# vgchange -an new-vg01
  0 logical volume(s) in volume group "new-vg01" now active
[root@rhel6-server ~]# vgexport new-vg01
  Volume group "new-vg01" successfully exported
[root@rhel6-server ~]# vgdisplay new-vg01 |grep -i export
  Volume group new-vg01 is exported
  VG Status             exported/resizable

Check pvscan on other system to see the disks
[root@rhel6-server ~]# pvscan
  PV /dev/sdb     is in exported VG new-vg01 [20.00 GiB / 14.28 GiB free]
  PV /dev/sdc     is in exported VG new-vg01 [20.00 GiB / 20.00 GiB free]

Check lvscan/lvs on other system to see the VG
[root@rhel6-server ~]# lvs
  Volume group new-vg01 is exported

[root@rhel6-server ~]# vgimport new-vg01
  Volume group "new-vg01" successfully imported
[root@rhel6-server ~]# vgchange -ay new-vg01
  3 logical volume(s) in volume group "new-vg01" now active

Mount all partitions

32.  What is LVM Metadata
The configuration details of a volume group are referred to as the metadata. By default, an identical copy of the metadata is maintained in every metadata area in every physical volume within the volume group. LVM volume group metadata is stored as ASCII.


33.  What is the lvm config backup location

[root@rhel6-server ~]# ls -l /etc/lvm/backup/
total 8
-rw-------. 1 root root 2345 Mar  2 17:05 new-vg01
-rw-------. 1 root root 1782 Jan 27 22:38 vg_rhel6server
Also see following location,

[root@rhel6-server ~]# ls -l /etc/lvm/archive/

34.  Name the lvm daemon

lvmetad

[root@rhel6-server ~]# service lvm2-lvmetad status
lvmetad (pid  5932) is running...

35.  Main configuration file for LVM

[root@rhel6-server ~]# cat /etc/lvm/lvm.conf

36.  How to take LVM backup

[root@rhel6-server ~]# vgcfgbackup
[root@rhel6-server ~]# ls -l /etc/lvm/backup/
-rw-------. 1 root root 2339 Mar  2 17:43 new-vg01
-rw-------. 1 root root 1717 Mar  2 17:43 vg_rhel6server

37.  How to take LVM backup at particular location

[root@rhel6-server ~]# vgcfgbackup -f /tmp/new-vg01-bkp new-vg01
[root@rhel6-server ~]# ls -l /tmp/new*
-rw-------. 1 root root 2337 Mar  2 17:46 /tmp/new-vg01
-rw-------. 1 root root 2341 Mar  2 17:47 /tmp/new-vg01-bkp

38.  How to restore LVM backup

[root@rhel6-server ~]# vgcfgrestore -f /tmp/new-vg01-bkp new-vg01

39.  In what circumstances LVM will fail to restore

PV must be intact

40.  How to know which disks are used for which vg/lv

[root@rhel6-server ~]# lvs -a -o segtype,devices,lv_name,vg_name
[root@rhel6-server ~]# lvs -o +devices
[root@rhel6-server ~]# vgs -o +device

41.  What is lvmdump

lvmdump is tool to collect diagnostic info which further used to troubleshoot.

42.  How many volume groups can be created in Linux?
256

43.  How to re-create the device files for LVM volumes?
[root@rhel6-server ~]# vgmknodes



1 comment: