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

Wednesday, 29 March 2017

RHEL6-14-LOGICAL VOLUME MANAGER (LVM)-1


RHEL6-14-LOGICAL VOLUME MANAGER (LVM)-1

CREATION:




Concept is as similar as other volume groups, club different disks or partitions to make a big group and again divide that group according to requirement.

PV è VG è LV

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.

Physical Extent (PE)
Each physical volume (PV) is divided into equal size blocks known as physical extents.
Logical Extent (LE)
Each logical volume (LV) is divided into equal size blocks called logical extents. Let's suppose we are creating a new volume group called VG01. This volume group needs physical disk space in order to function so we allocate three disk partitions /dev/sda1, /dev/sdb1 and /dev/sdb2. These become physical volumes in VG01. We would then create a logical volume called LV01 within the volume group made up of the three physical volumes. If we run out of space in LV01 we simply add more disk partitions as physical volumes and assign them to the volume group and logical volume.

Daemon: METADATA DAEMON (LVMETAD)


LVM can optionally use a central metadata cache, implemented through a daemon (lvmetad) and a udev rule. The metadata daemon has two main purposes: it improves performance of LVM commands and it allows udev to automatically activate logical volumes or entire volume groups as they become available to the system.

First select the disk/slice => create PV, then => VG, then => LV

[root@rhel6-client1 ~]# fdisk -l | grep /dev/sd
Disk /dev/sda: 21.5 GB, 21474836480 bytes
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              64         447     3072000   83  Linux
/dev/sda3             447         577     1048576   83  Linux
/dev/sda4             577        2611    16337920    5  Extended
/dev/sda5             577         708     1048576   82  Linux swap / Solaris
/dev/sda6             708        2611    15287296   83  Linux
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
/dev/sdb1               1         653     5242880   83  Linux
/dev/sdb2             653        1045     3145728   83  Linux
/dev/sdb3            1045        1306     2097152   83  Linux
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
Disk /dev/sdd: 21.5 GB, 21474836480 bytes

PHYSICAL VOLUME (PV):

[root@rhel6-client1 ~]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
  Physical volume "/dev/sdb1" successfully created
  Physical volume "/dev/sdb2" successfully created
  Physical volume "/dev/sdb3" successfully created

Does this make any sense…to make a physical volume of different partitions from same disk…….??

NO…

Instead we can do…

[root@rhel6-client1 ~]# pvcreate /dev/sdb

Anyways, going with the same configuration,

[root@rhel6-client1 ~]# pvdisplay
  "/dev/sdb1" is a new physical volume of "5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               5.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               XpORoj-lxhJ-NfNq-C1Vy-Xo3a-e1Di-L2HOft

  "/dev/sdb2" is a new physical volume of "3.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name
  PV Size               3.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               PvogJv-5OeO-XU2e-EWXK-e6jd-yweZ-FBtkTG

  "/dev/sdb3" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb3
  VG Name
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               wfqvlx-GvLJ-eTfA-hw5V-5xsA-qkS0-tW3zsB

[root@rhel6-client1 ~]# pvscan
  PV /dev/sdb1                      lvm2 [5.00 GiB]
  PV /dev/sdb2                      lvm2 [3.00 GiB]
  PV /dev/sdb3                      lvm2 [2.00 GiB]
  Total: 3 [10.00 GiB] / in use: 0 [0   ] / in no VG: 3 [10.00 GiB]

[root@rhel6-client1 ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb1       lvm2 a--  5.00g 5.00g
  /dev/sdb2       lvm2 a--  3.00g 3.00g
  /dev/sdb3       lvm2 a--  2.00g 2.00g
[root@rhel6-client1 ~]#

VOLUME GROUP (VG):

[root@rhel6-client1 ~]# vgcreate vg01 /dev/sdb1 /dev/sdb2
  Volume group "vg01" successfully created

[root@rhel6-client1 ~]# vgcreate vg02 /dev/sdb3
  Volume group "vg02" successfully created

[root@rhel6-client1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg02
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.00 GiB
  PE Size               4.00 MiB
  Total PE              511
  Alloc PE / Size       0 / 0
  Free  PE / Size       511 / 2.00 GiB
  VG UUID               vyCCXS-34G4-QWhr-fGbY-nndY-L7DV-hfT5iI

  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               7.99 GiB
  PE Size               4.00 MiB
  Total PE              2046
  Alloc PE / Size       0 / 0
  Free  PE / Size       2046 / 7.99 GiB
  VG UUID               KDjPz1-kpSd-X9aQ-7pl4-A96d-0xff-9HfNSX

[root@rhel6-client1 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg02" using metadata type lvm2
  Found volume group "vg01" using metadata type lvm2

[root@rhel6-client1 ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg01   2   0   0 wz--n- 7.99g 7.99g
  vg02   1   0   0 wz--n- 2.00g 2.00g
[root@rhel6-client1 ~]#

[root@rhel6-client1 ~]# vgdisplay vg01
  --- Volume group ---
  VG Name               vg01
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               7.99 GiB
  PE Size               4.00 MiB
  Total PE              2046
  Alloc PE / Size       0 / 0
  Free  PE / Size       2046 / 7.99 GiB
  VG UUID               KDjPz1-kpSd-X9aQ-7pl4-A96d-0xff-9HfNSX

[root@rhel6-client1 ~]# vgdisplay vg02
  --- Volume group ---
  VG Name               vg02
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.00 GiB
  PE Size               4.00 MiB
  Total PE              511
  Alloc PE / Size       0 / 0
  Free  PE / Size       511 / 2.00 GiB
  VG UUID               vyCCXS-34G4-QWhr-fGbY-nndY-L7DV-hfT5iI

LOGICAL VOLUME (LV):

# lvcreate -L [size] [volume_group] -n [logical_volume]

-L for exact size
#lvcreate -L 1G vg01 (here we did not supplied the name of LV)
# lvcreate -L 2G -n lv02 vg01 (-n for name of LV after that from which VG)

-l for the size of the logical volume in extents. Can also use this argument
   To specify the percentage of the volume group to use for the logical volume.

#lvcreate -l 60%VG -n mylv vg01

You can also use the -l argument of the lvcreate command to specify the percentage of the remaining free space in a volume group as the size of the logical volume.

#lvcreate -l 100%FREE -n mylv vg01

ONE MORE WAY TO CREATE LV,

# lvcreate --name <name of lv> --size <size in MB/GB> <name of VG>
#lvcreate --name testlv01 --size 3G vg02

[root@rhel6-client1 ~]# lvcreate -L 1G vg01
  Logical volume "lvol0" created

[root@rhel6-client1 ~]# lvcreate -L 2G -n lv02 vg01
  Logical volume "lv02" created

[root@rhel6-client1 ~]# lvcreate -l 20%VG -n mylv vg01
  Logical volume "mylv" created

[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n mylv vg01
  Logical volume "mylv" already exists in volume group "vg01"

[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n mylv2 vg01
  Logical volume "mylv2" created

[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n mylv3 vg01
  Unable to create new logical volume with no extents


Let’s understand them one by one,

[root@rhel6-client1 ~]# lvcreate -L 1G vg01
  Logical volume "lvol0" created
1GB size of LV created with default name lvol#, because we did not supplied any name for our LV.

[root@rhel6-client1 ~]# lvcreate -L 2G -n lv02 vg01
  Logical volume "lv02" created
2GB size of LV created with name of “lv02”. This time we had specified the name of LV.

[root@rhel6-client1 ~]# lvcreate -l 20%VG -n mylv vg01
  Logical volume "mylv" created

Here we did not specified the size, instead we had requested to make a LV “mylv” of 20% size from remaining size of VG “vg01”.

Let’s check it in brief.

[root@rhel6-client1 ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg01   2   4   0 wz--n- 7.99g    0
  vg02   1   0   0 wz--n- 2.00g 2.00g

vg01 has 7.99 GB size. From which we had taken 3GB as “lvol0” of 1G and “lv02” of 2G.

7.99 – 3 = 4.99
4.99 * 20% = 0.998

Now it have to create “mylv” of 20% from 4.99GB, which would be approx. 1G.

So is the “mylv” is of 1G…?

[root@rhel6-client1 ~]# lvdisplay /dev/vg01/mylv |grep -i size
  LV Size                1.60 GiB

NO…

Why…?

Because it has taken 20% from the whole size of vg01.

7.99 * 20% = 1.598

Great, now move towards 100%FREE

[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n mylv2 vg01
  Logical volume "mylv2" created

This command does not need any intersection, because it will take all the remaining space whatever left on VG.

[root@rhel6-client1 ~]# lvdisplay /dev/vg01/mylv2 |grep -i size
  LV Size                3.39 GiB

Tried to create one more LV,

[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n mylv3 vg01
  Unable to create new logical volume with no extents

Obviously denied because all space was occupied by previous command.

[root@rhel6-client1 ~]# lvcreate --name testlv01 --size 200M vg02
  Logical volume "testlv01" created

[root@rhel6-client1 ~]# lvcreate --name testlv02 --size 3G vg02
  Volume group "vg02" has insufficient free space (461 extents): 768 required.

[root@rhel6-client1 ~]# lvcreate --name testlv01 --size 200M vg02
  Logical volume "testlv01" created

[root@rhel6-client1 ~]# lvcreate --name testlv02 --size 3G vg02
  Volume group "vg02" has insufficient free space (461 extents): 768 required.

[root@rhel6-client1 ~]# lvcreate --name testlv02 -l 300 vg02
  Logical volume "testlv02" created

 [root@rhel6-client1 ~]# lvcreate --name testlv03 --size 2G vg02
  Volume group "vg02" has insufficient free space (161 extents): 512 required.

[root@rhel6-client1 ~]# lvcreate --name testlv03 -l 161 vg02
  Logical volume "testlv03" created

[root@rhel6-client1 ~]# lvcreate -l 100%FREE -n testlv04 vg02
  Unable to create new logical volume with no extents

[root@rhel6-client1 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg02/testlv01
  LV Name                testlv01
  VG Name                vg02
  LV UUID                IbWRHx-gzsU-MViy-7ejW-uJR7-o4G2-luK0Qe
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 17:35:53 +0530
  LV Status              available
  # open                 0
  LV Size                200.00 MiB
  Current LE             50
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:4

  --- Logical volume ---
  LV Path                /dev/vg02/testlv02
  LV Name                testlv02
  VG Name                vg02
  LV UUID                Hbx9l8-Rxey-ocrc-ks3q-sIru-v3in-Iz0qRX
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 17:37:18 +0530
  LV Status              available
  # open                 0
  LV Size                1.17 GiB
  Current LE             300
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

  --- Logical volume ---
  LV Path                /dev/vg02/testlv03
  LV Name                testlv03
  VG Name                vg02
  LV UUID                5gtdIY-hmPX-1Vx4-4Z9d-R7yh-X9ec-gweGl2
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 17:38:39 +0530
  LV Status              available
  # open                 0
  LV Size                644.00 MiB
  Current LE             161
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:6

  --- Logical volume ---
  LV Path                /dev/vg01/lvol0
  LV Name                lvol0
  VG Name                vg01
  LV UUID                o5KMSw-3Ooq-SMWq-rAVh-DUqO-ioyd-zGh7Ue
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 16:43:10 +0530
  LV Status              available
  # open                 0
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg01/lv02
  LV Name                lv02
  VG Name                vg01
  LV UUID                73TPCB-03PS-vqI6-HplM-vyDb-oW4F-a1Le1L
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 16:44:46 +0530
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/vg01/mylv
  LV Name                mylv
  VG Name                vg01
  LV UUID                n0cX2z-mjkZ-v5en-mxN4-t0q3-OJ7p-yXJpBo
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 16:47:43 +0530
  LV Status              available
  # open                 1
  LV Size                1.60 GiB
  Current LE             409
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg01/mylv2
  LV Name                mylv2
  VG Name                vg01
  LV UUID                ncauN2-ycYp-MDsX-flYB-Pfdo-Wbmi-LKrexk
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 16:48:05 +0530
  LV Status              available
  # open                 0
  LV Size                3.39 GiB
  Current LE             869
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
[root@rhel6-client1 ~]# lvdisplay /dev/vg01/mylv
  --- Logical volume ---
  LV Path                /dev/vg01/mylv
  LV Name                mylv
  VG Name                vg01
  LV UUID                n0cX2z-mjkZ-v5en-mxN4-t0q3-OJ7p-yXJpBo
  LV Write Access        read/write
  LV Creation host, time rhel6-client1, 2017-03-28 16:47:43 +0530
  LV Status              available
  # open                 0
  LV Size                1.60 GiB
  Current LE             409
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

[root@rhel6-client1 ~]# lvdisplay /dev/vg01/mylv |grep -i size
  LV Size                1.60 GiB

[root@rhel6-client1 ~]# lvdisplay /dev/vg01/mylv2 |grep -i size
  LV Size                3.39 GiB

[root@rhel6-client1 ~]# lvscan
  ACTIVE            '/dev/vg02/testlv01' [200.00 MiB] inherit
  ACTIVE            '/dev/vg02/testlv02' [1.17 GiB] inherit
  ACTIVE            '/dev/vg02/testlv03' [644.00 MiB] inherit
  ACTIVE            '/dev/vg01/lvol0' [1.00 GiB] inherit
  ACTIVE            '/dev/vg01/lv02' [2.00 GiB] inherit
  ACTIVE            '/dev/vg01/mylv' [1.60 GiB] inherit
  ACTIVE            '/dev/vg01/mylv2' [3.39 GiB] inherit

[root@rhel6-client1 ~]# lvs
  LV       VG   Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv02     vg01 -wi-a----   2.00g
  lvol0    vg01 -wi-a----   1.00g
  mylv     vg01 -wi-ao---   1.60g
  mylv2    vg01 -wi-a----   3.39g
  testlv01 vg02 -wi-a---- 200.00m
  testlv02 vg02 -wi-a----   1.17g
  testlv03 vg02 -wi-a---- 644.00m

REFERENCES & GOOD READ:



1 comment: