0

We want to increase the space in a Volume Group in our VM centOS server

For example

from pvs we see

pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/sda2  VLwol lvm2 a--  <100.00g <5.09g

the main target is to have under PFree the value - 300g

example

pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/sda2  VLwol lvm2 a--  <400.00g <305g

so first we increase from Vsphaere client the OS disk by + 300g

then we rescan the disk as

 echo 1>/sys/class/block/sda/device/rescan

from this point what is the best suggested approach in order to increase the free space in a Volume Group?

sheffadmin
  • 49
  • 1
  • 3
  • 11

1 Answers1

0

Here is an example doing it with an iSCSI drive on a KVM virtual machine because this procedure applies to any modern Linux OS that runs LVM2, not just CentOS on VMware. I did this on a test virtual machine, starting with /dev/sda and /dev/sda1 both at 64G in size:

root@xi:~# lsblk /dev/sda
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   64G  0 disk 
+-sda1        8:1    0   64G  0 part 
  +-vg-root 254:0    0 22.4G  0 lvm  /
  +-vg-swap 254:1    0  952M  0 lvm  [SWAP]
  +-vg-tmp  254:2    0  952M  0 lvm  /tmp
  +-vg-var  254:3    0  7.5G  0 lvm  /var

root@xi:~# pvs
  PV         VG Fmt  Attr PSize   PFree  
  /dev/sda1  vg lvm2 a--  <63.99g <32.33g

I went to my storage subsystem and expanded the disk by 8GB. Now we can tell the kernel to rescan the device as you mentioned (though my device was found under /sys/class/scsi_disk instead).

root@xi:~# echo 1 > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan

root@xi:~# lsblk /dev/sda
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   72G  0 disk 
+-sda1        8:1    0   64G  0 part 
  +-vg-root 254:0    0 22.4G  0 lvm  /
  +-vg-swap 254:1    0  952M  0 lvm  [SWAP]
  +-vg-tmp  254:2    0  952M  0 lvm  /tmp
  +-vg-var  254:3    0  7.5G  0 lvm  /var

We can now see that lsblk now shows a larger drive, but the partition is still the original size. We need to resize the partition to fill the expanded space using a partitioning tool. To do this with fdisk, you have to erase the partition and create a new one starting at the same block, but that is kind of scary to do. An easier way is to use parted resizepart, like this:

root@xi:~# parted /dev/sda resizepart 1 100%                                  
Information: You may need to update /etc/fstab.

root@xi:~# lsblk /dev/sda
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   72G  0 disk 
+-sda1        8:1    0   72G  0 part 
  +-vg-root 254:0    0 22.4G  0 lvm  /
  +-vg-swap 254:1    0  952M  0 lvm  [SWAP]
  +-vg-tmp  254:2    0  952M  0 lvm  /tmp
  +-vg-var  254:3    0  7.5G  0 lvm  /var

The parted program resized the partition on the disk, but the kernel may not know about the change yet. Run partprobe to make sure the kernel updates its table in memory:

root@xi:~# partprobe /dev/sda

After we know the partition has been resized and the kernel knows about it, we can finally extend the physical volume. The pvresize command automatically extends the physical volume to fill all of the free space:

root@xi:~# pvresize /dev/sda1
  Physical volume "/dev/sda1" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

root@xi:~# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sda1  vg lvm2 a--  71.99g 40.33g
Troy
  • 26
  • 3
  • about Information: You may need to update /etc/fstab. , what is need to insert in fstab? – sheffadmin Nov 15 '20 at 19:25
  • That is just a generic message from `parted` because you modified the partition table. In this case, we are not adding, removing, nor shifting partitions. The partition that was expanded should still be the same index, so it should not matter. If your `fstab` uses UUIDs and the UUID changed, you may need to fix that, but a resize shouldn't change the UUID. If you used `fdisk` to delete and create a partition starting at the same block, it will probably get a new UUID. – Troy Nov 16 '20 at 23:45