Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
[root@localhost ~] vgdisplay
  --- Volume group ---
  VG Name               vg_root
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               297,59 GiB
  PE Size               4,00 MiB
  Total PE              76182
  Alloc PE / Size       59392 / 232,00 GiB
  Free  PE / Size       16790 / 65,59 GiB
  VG UUID               XXXXXXXXXX


[root@localhost ~] pvdisplay

  --- Physical volume ---
  PV Name               /dev/mapper/udisks-luks-uuid-ASDFASDF
  VG Name               vg_root
  PV Size               297,59 GiB / not usable 2,00 MiB
  Allocatable           yes 
  PE Size               4,00 MiB
  Total PE              76182
  Free PE               16790
  Allocated PE          59392
  PV UUID               YYYYYYYYYYY

So I have a VG with 65 GByte free space. But when I want to shrink this Volume Group about ~50 GByte:

pvresize -tv --setphysicalvolumesize 247G /dev/mapper/udisks-luks-uuid-ASDFASDF
  Test mode: Metadata will NOT be updated and volumes will not be (de)activated.
    Using physical volume(s) on command line
    Test mode: Skipping archiving of volume group.
    /dev/mapper/udisks-luks-uuid-ASDFASDF: Pretending size is 517996544 not 624087040 sectors.
    Resizing volume "/dev/mapper/udisks-luks-uuid-ASDFASDF" to 624087040 sectors.
    Resizing physical volume /dev/mapper/udisks-luks-uuid-ASDFASDF from 0 to 63231 extents.
  /dev/mapper/udisks-luks-uuid-ASDFASDF: cannot resize to 63231 extents as later ones are allocated.
  0 physical volume(s) resized / 1 physical volume(s) not resized
    Test mode: Wiping internal cache
    Wiping internal VG cache

So the error message is:

cannot resize to 63231 extents as later ones are allocated.

Q: How can I defrag the vg_root so I can remove the unneeded part of it?

p.s: I already found out that I only need to resize the PV to resize the VG, or are there any better commands to do the VG resize (ex.: what can I do if I would several VG's on a PV? ...)?

share|improve this question

2 Answers 2

up vote 15 down vote accepted

You can use pvmove to move those extents to the beginning of the device or another device:

sudo pvmove --alloc anywhere /dev/device:60000-76182

Then pvmove chooses where to move the extents to, or you can specify where to move them.

See pvs -v --segments /dev/device to see what extents are currently allocated.

share|improve this answer

This older post covers this sort of shrinking so you can use the new space for something else. You'll need to resize it to the data however before. This should cover that and other errors you get as well. As it's older, do read through first:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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