-1

i got the homework from Devops school and one of LVM question below , i am confused with extents , teacher said that it should be calculated like this : 20x25 = 500 mb --> so the partition supposed to be made about 600 mb with extra space ! But from my google researches i found that 1 extent = 4 MB , 25x4 = 100 LVM=80MB ???

Create logical volume "datashare" inside volume group called "datagroup"

Create volume group "datagroup" from partition using 25M extents

Create logical volume with 20 extents /dev/datagroup/datashare

mike543
  • 1
  • 1

1 Answers1

0

The disk I am using is 20GB in total size.

[root@centos7 ~]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb    8:16   0  20G  0 disk 

I create my first Physical Volume.

[root@centos7 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.

I create my first Volume Group setting 32MG as the Physical Extentsize (PE) size, default 4MB, this defines how the space is being allocated (chunks of PE size).

[root@centos7 ~]# vgcreate -s 32M myvg /dev/sdb
  Volume group "myvg" successfully created

So my /dev/sdb disk size is 20GB, then I created the PV pvcreate, after this I created a new Volume Group with the Physical Extentsize (PE) size of 32MB.

Then I confirm this by the PE Size column.

[root@centos7 ~]# vgdisplay myvg
  --- Volume group ---
  VG Name               myvg
  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               <19.97 GiB
  PE Size               32.00 MiB
  Total PE              639
  Alloc PE / Size       0 / 0   
  Free  PE / Size       639 / <19.97 GiB
  VG UUID               m3wDvh-i0aH-5Zr2-0ya7-1GaA-mLb2-Umd9x3

SO here is the math disk 20GB to MB (20 * 1024 = 20480).

Then 20480 MB (Total disk 20GB) / 32 MB (The size I wanted my PE) = 640 (vgdisplay shows Total PE 639 because rounded values probably we did not have exactly 32 MB to have the last PE to have exactly 640 as expected.)

So if you need to create a new Logical Volume (LV):

  • You can use PE (which is 32MG and we have 639 available to use), so let say I want a new LV with 50 PE, 50 * 32 MB (PE size) = 1600 MB / 1.6 GB. (Please note Current LE 50 from PE it changes to Logical Extent)
   [root@centos7 ~]# lvcreate -l 50 -n mylv1 myvg
     Logical volume "mylv1" created.

   [root@centos7 ~]# lvdisplay /dev/myvg/mylv1
     --- Logical volume ---
     LV Path                /dev/myvg/mylv1
     LV Name                mylv1
     VG Name                myvg
     LV UUID                BuQsPK-UKWL-tdVv-bFkR-X2md-zG3o-xzQIKk
     LV Write Access        read/write
     LV Creation host, time centos7, 2021-10-10 20:38:33 +0000
     LV Status              available
     # open                 0
     LV Size                1.56 GiB
     Current LE             50
     Segments               1
     Allocation             inherit
     Read ahead sectors     auto
     - currently set to     8192
     Block device           253:0

or

  • You can ask LVM to create an LV with a specific size like 950 MB so 950 / 32 MB (PE) = 29.6875 but it can not use 29.6875 PE because it needs to be rounded up to use 30 PE (Current LE 30).
[root@centos7 ~]# lvcreate -L 950MB -n mylv2 myvg
  Rounding up size to full physical extent 960.00 MiB
  Logical volume "mylv2" created.

[root@centos7 ~]# lvdisplay /dev/myvg/mylv2
  --- Logical volume ---
  LV Path                /dev/myvg/mylv2
  LV Name                mylv2
  VG Name                myvg
  LV UUID                eJrAY2-Pb1x-VBbq-k8cI-vIlq-Tg3s-CsRFsB
  LV Write Access        read/write
  LV Creation host, time centos7, 2021-10-10 20:40:33 +0000
  LV Status              available
  # open                 0
  LV Size                960.00 MiB
  Current LE             30
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
Reynaldo Aceves
  • 436
  • 2
  • 10