Tuesday, 29 October 2019

LVM - extending volume groups and logical volumes

🔖  Note 1: How to create Physical Volumes, Volume Groups and Logical Volumes you can read here.

🔖 Note 2: In the example below I assume that we are using linear volumes.


Extend existing Logical Volume

Each of logical volumes divided on LEs (logical extents), and each volume groups have PEs (physical extents).

To extend Logical Volume we have to have enough free PE on the volume group.

1.1 Lets check what disks do we have:

[root@rifle ~]# lvmdiskscan
  /dev/centos_rifle/root   [      <6.20 GiB]
  /dev/sda1                [       1.00 GiB]
  /dev/centos_rifle/swap   [     820.00 MiB]
  /dev/sda2                [      <7.00 GiB] LVM physical volume
  /dev/vg_mydata/lv_mydata [       1.00 GiB]
  /dev/sdb                 [      <1.04 GiB] LVM physical volume
  /dev/sdc                 [     519.34 MiB]
  3 disks
  1 partition
  2 LVM physical volume whole disks
  1 LVM physical volume

So we have free disk /dev/sdc

1.2 Check how many free PEs are on the /dev/sdc:

[root@rifle ~]# pvdisplay /dev/sdc
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               vg_mydata
  PV Size               519.34 MiB / not usable 3.34 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              129
  Free PE               129
  Allocated PE          0
  PV UUID               SQEy8B-b3df-rIF2-1dgu-67FV-dM3a-UuarFu

There are 129 free PEs.

1.3 Adding disk  /dev/sdc to the volume group vg_mydata

Creating Physical Volume from /dev/sdc:
[root@rifle ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.

Adding Physical Volume /dev/sdc to the Volume Group vg_mydata:
[root@rifle ~]# vgextend vg_mydata /dev/sdc
  Physical volume "/dev/sdc" successfully created.
  Volume group "vg_mydata" successfully extended

Check how many free space do we have on the Volume Group now:
[root@rifle ~]# vgs
  VG           #PV #LV #SN Attr   VSize  VFree
  vg_mydata      2   1   0 wz--n- <1.54g 548.00m

[root@rifle ~]# pvs
  PV         VG           Fmt  Attr PSize   PFree
  /dev/sda2  centos_rifle lvm2 a--   <7.00g      0
  /dev/sdb   vg_mydata    lvm2 a--    1.03g  32.00m
  /dev/sdc   vg_mydata    lvm2 a--  516.00m 516.00m

Now we have 2 Physical Volumes and 516Mb (there are two figures: 548M and 516M      516 = 129 PE multiply 4K PE sizefree space on our Volume Group vg_mydata

File system space before expansion:
[root@rifle ~]# df -h /mydata/
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_mydata-lv_mydata  976M  2.6M  907M   1% /mydata

1.4 Extend Logical Volume and resize the file system

[root@rifle ~]# lvextend -L +516M  -r  /dev/vg_mydata/lv_mydata
  Size of logical volume vg_mydata/lv_mydata changed from 1.00 GiB (256 extents) to 1.50 GiB (385 extents).
  Logical volume vg_mydata/lv_mydata successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg_mydata-lv_mydata is mounted on /mydata; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vg_mydata-lv_mydata is now 394240 blocks long.

🔖  Note 3: Parameter -r means also resize file system.

What size do we have now:
[root@rifle ~]# df -h /mydata/
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg_mydata-lv_mydata  1.5G  3.0M  1.4G   1% /mydata

Lets check the map of LV:
[root@rifle ~]# lvdisplay /dev/vg_mydata/lv_mydata -m
  --- Logical volume ---
  LV Path                /dev/vg_mydata/lv_mydata
  LV Name                lv_mydata
  VG Name                vg_mydata
  LV UUID                23DwLN-jLgw-cbbr-vaXw-Pgc2-VGQV-V43H9G
  LV Write Access        read/write
  LV Creation host, time rifle, 2019-10-28 13:01:27 +0300
  LV Status              available
  # open                 1
  LV Size                1.50 GiB
  Current LE             385
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

  --- Segments ---
  Logical extents 0 to 263:
    Type                linear
    Physical volume     /dev/sdb
    Physical extents    0 to 263

  Logical extents 264 to 384:
    Type                linear
    Physical volume     /dev/sdc
    Physical extents    0 to 120

Logical Extents from 0 to 263 are on disk /dev/sdb and LEs from 264 to 384 are on /dev/sdc   

No comments: