February 8, 2023

Resize LVM Space

Use Space from Extended Physical (or Virtual) Disk

ubuntu@ubuntu:~$ lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 55.6M  1 loop /snap/core18/2654
loop1                       7:1    0 63.2M  1 loop /snap/core20/1695
loop2                       7:2    0 63.2M  1 loop /snap/core20/1738
loop3                       7:3    0 91.8M  1 loop /snap/lxd/23991
loop4                       7:4    0 55.6M  1 loop /snap/core18/2632
loop5                       7:5    0 49.6M  1 loop /snap/snapd/17883
loop6                       7:6    0 91.9M  1 loop /snap/lxd/24061
sda                         8:0    0   70G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0    1G  0 part /boot
└─sda3                      8:3    0   69G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0   69G  0 lvm  /
sr0                        11:0    1 1024M  0 rom
ubuntu@ubuntu:~$

On this case, LVM partition it is under sda3 and let’s start with extended or resize disk.

sudo cfdisk

Select your /dev/sda3 partition from the list and then select “Resize” from the bottom menu. Hit ENTER and it will prompt you to confirm the new size. Hit ENTER again and you will now see the /dev/sda3 partition with a new larger size.

Select “Write” from the bottom menu, type yes to confirm, and hit ENTER. Then use “q” to exit the program.

Now that the LVM partition backing the /dev/sda3 Physical Volume (PV) has been extended, we need to extend the PV itself. Run pvresize /dev/sda3 to do this and then use pvdisplay to check the new size.

sudo pvresize /dev/sda3

Now let’s check the Volume Group (VG) free space with vgdisplay.

Then let’s check the size of our upstream Logical Volume (LV) using lvdisplay, extend the LV to use up all the VG’s free space with lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv, and then check the LV one more time with lvdisplay to make sure it has been extended.

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

At this point, the block volume underpinning our root filesystem has been extended, but the filesystem itself has not been resized to fit that new volume. To do this, run df -h to check the current size of the file system, then run resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv to resize it, and df -h one more time to check the new file system available space.

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv