These are all the steps required to resize a LVM or LVM2 partition -
sudo lvresize --verbose --resizefs -L -150G /dev/ubuntu/root
sudo pvresize --setphysicalvolumesize {any size here} /dev/sda5
/dev/sda5: cannot resize to xxxxx extents as later ones are allocated.
You have to rearrange the unallocated space at the end of the LVM. That means after root and swap_1 partition. So, you need to move that free space using the command below
pvs -v --segments /dev/sda5
This will show the output like below
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx yyyy 0 free
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyyy end swap 0 linear /dev/sda5:yyyy-end
Now use the command below to remove external fragmentation -
sudo pvmove --alloc anywhere /dev/sda5:yyyy-end
Now let us see how it goes -
pvs -v --segments /dev/sda5
This will show the output like below
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx yyyy swap 0 linear /dev/sda5:xxx-yyyy
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyyy end 0 free
After that use the gparted and resize the LVM to maximum used area and rest will be in unallocated space. Enjoy...