I am trying to resize an encrypted physical volume so that I have free space to make a dual boot system.

So far, I've successfully decrypted the PV, resized the filesystem and the LVs but when I try to resize the PV I run into issues relating to the sector extents of my LVs.

root@ubuntu:/home/ubuntu# pvresize --setphysicalvolumesize 174G /dev/mapper/cryptdisk
/dev/mapper/cryptdisk: cannot resize to 44543 extents as later ones are allocated.
0 physical volume(s) resized / 1 physical volume(s) not resized

On the physical volume I have two logical volumes: root (first) and swap (second). I've resized (shrunk) the root volume to create free space, but the extents of the free space lay between the root and swap volumes. Because the extents of the swap volume are located at the end of the physical volume, I cannot shrink the physical volume using pvresize.

How can I change the extents of the swap volume so that the free space is located after it?

I've had a look at pvmove, but I don't think it's what I need - in this case I need something like lvmove (but it doesn't exist).

root@ubuntu:/home/ubuntu# pvdisplay --maps /dev/mapper/cryptdisk
--- Physical volume ---
PV Name               /dev/mapper/cryptdisk
VG Name               elementary-vg
PV Size               222.59 GiB / not usable 0   
Allocatable           yes 
PE Size               4.00 MiB
Total PE              56983
Free PE               12546
Allocated PE          44437
PV UUID               DkBRl8-3gAq-Ewzv-7kjB-AHZI-dhqC-69gaZo

--- Physical Segments ---
Physical extent 0 to 40354:
  Logical volume    /dev/elementary-vg/root
  Logical extents   0 to 40354
Physical extent 40355 to 52898:
Physical extent 52899 to 56980:
  Logical volume    /dev/elementary-vg/swap_1
  Logical extents   0 to 4081
Physical extent 56981 to 56982:

kvpm overview

  • Pvmove Is exactly what you need – D'Arcy Nader Dec 28 '19 at 4:15

pvmove is the right tool:

pvmove /dev/mapper/cryptdisk:52899:56980 /dev/mapper/cryptdisk:40355

will move the extents.

However since we’re talking about swap I’d just remove the LV and recreate it...

  • I ended up recreating the swap – Nukolas Dec 28 '19 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.