Ubuntu – GParted – can`t shrink physical volume (pvresize fails)

dual-bootgpartedlvmmountpartitioning

Booted from an USB Ubuntu 18.04 and I`m trying to shrink my current Ubuntu 16.04 partition.

For the sake of completion, this is what lsblk returns in the momento I`m writing this:

sda                     8:0    0 465.8G  0 disk 
├─sda1                  8:1    0   512M  0 part 
├─sda2                  8:2    0   488M  0 part 
└─sda3                  8:3    0 464.8G  0 part 
  ├─ubuntu--vg-root   253:0    0 248.9G  0 lvm  
  └─ubuntu--vg-swap_1 253:1    0  15.9G  0 lvm  
sdb                     8:16   1   1.9G  0 disk /cdrom
├─sdb1                  8:17   1   1.8G  0 part 
└─sdb2                  8:18   1   2.3M  0 part 

As you can see, my /dev/sda3 has 464.8G but just 264.8G are in use by vg-root and vg-swap. What I want is to shrink sda3 so I can install Ubuntu 18.04 in another partition.

Following this answer, after resizing my LV, I`m trying to run pvresize:

ubuntu@ubuntu:~$ sudo pvresize --setphysicalvolumesize 265G /dev/sda3
/dev/sda3: Requested size 265.00 GiB is less than real size 464.78 GiB. Proceed?  [y/n]: y
  WARNING: /dev/sda3: Pretending size is 555745280 not 974721024 sectors.
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Given the message, I understand that everything worked successfully, but when running lsblock (or GParted), everything remains the same: sda3 was not shrinked.


Important to note that GParted is showing a key icon beside sda3 as if it was mounted, when it is not (as I booted from USB). Running umount confirms that:

GParted screen

ubuntu@ubuntu:~$ sudo umount /dev/sda3
umount: /dev/sda3: not mounted.

Also, if I try to resize sda3 using GParted it will run the same pvresize but will answer NO to the confirmation, so it results is an error.

What Im missing here? Do I have to do anything else? Why isnt GParted allowing me to shrink the partition?

Best Answer

Ok, so after a whole afternoon and part of my evening I found what was going on.

  1. pvresize was changed last year and now it prompts for confirmation when you want to resize a PV to a smaller size than the device it's in
  2. apparently GParted wasn't updated yet, as it will fail when trying to resize a partition as it answers NO to the prompt
  3. as GParted won't run pvresize successfully, it won't calculate blocks and run fdisk after it (just became clear to me after reading this post)

Maybe this bug only happens with newer versions of pvresize (as I'm trying Ubuntu 18.04 it would make sense).

Related Question