Resizing in LVM

I have a linux lab machine, having 2 vmdisk. I have configured the 2 disk to participate in LVM.

If I want to increase the capacity either 1 or both disk, how can I detect this changes in LVM? running pvscan does not see the changes but if I ran lsblk it see that the disk increased.

admin@Portainer ~]$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0              11:0    1  7.9G  0 rom
xvda            202:0    0   40G  0 disk
├─xvda1         202:1    0    1M  0 part
├─xvda2         202:2    0  500M  0 part /boot
└─xvda3         202:3    0 27.8G  0 part
  ├─vg--01-root 253:0    0   20G  0 lvm  /
  └─vg--01-var  253:2    0   20G  0 lvm  /var
xvdb            202:16   0   40G  0 disk
└─xvdb1         202:17   0 28.2G  0 part
  ├─vg--01-root 253:0    0   20G  0 lvm  /
  └─vg--01-swap 253:1    0   16G  0 lvm  [SWAP]
admin@Portainer ~]$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/xvda3
  VG Name               vg-01
  PV Size               <27.76 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              7105
  Free PE               0
  Allocated PE          7105
  PV UUID               cidyAY-mSHk-vN2t-7CpV-0cYm-zDt2-pnoy3d

  --- Physical volume ---
  PV Name               /dev/xvdb1
  VG Name               vg-01
  PV Size               <28.25 GiB / not usable 0
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              7231
  Free PE               0
  Allocated PE          7231
  PV UUID               j4dPQH-s9DI-movi-85c1-DCLR-CEim-QBAEgc
1 Like

I hope you realize that if you lose 1 disk, you lose all your data (keep backups somewhere else). And reminder to take a backup before you begin.

There are different methods here:

  • create new partitions out of the empty space and add them to LVM (online operation)
  • resize the existing partitions (offline)

The first one is as easy as fdisk /dev/xdy create a partition, pvcreate /dev/xdy-new-partition, then vgextend and lvresize or lvextend.

The second one is preferable (less metadata in LVM), but the first one isn’t a huge deal (the above was the method I used, because it was online, but it only works well if you have a gpt partition table).

The second one involves shutting down the system, booting a rescue disk, if you have something that has a GUI and gparted, that’s a big help, you can just resize the partition in gparted. Then pvdisplay will show the correct size. Then you follow the same steps to vgextend and lvresize.

1 Like