Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Question: Is there a tool supporting de-fragmentation of LVM2 logical volumes ? (Making their extents into consistent sequences)

Preferably by defining desired order of extents (something like "partition A on beginning of disk, B after A, but X on the end of PV")

Of course there is a need of considering following cases:

  • VG consists one PV
  • VG consists many PV, but each LV sits on one PV
  • VG consists many PV, LVs have their extents across many PV

If partitions can be stripped or not, can be discussed.

Know-how: It's possible to move ranges of extents with pvmove , e.g. : pvmove --alloc anywhere /dev/sdb1:1000-1999 /dev/sdb1:0-999 .

Reason: Because moving many ranges manually with pvmove is purely repeatable thing (questionable if brainless or not), I was curious if there exists tool for automatizing/supporting this process. If not... maybe doing one by myself - do you think such tool would be useful for other people?

share|improve this question
It's possible that there's no tool because there's no use case that requires it. I'm curious, why do you want to defragment? Is there a disk technology where there's a benefit for a typical extent size (4MB)? – Gilles Aug 19 '12 at 22:42
Let's consider traditional HardDrive (not SSD) performance characteristics - beginning of disk offers better performance than end. That's most important factor, why you might like to have extents related to some partition to be placed on beginning. – Grzegorz Wierzowiecki Aug 20 '12 at 18:50
For that kind of control, the simple way is to partition the disk into several physical volumes. – Gilles Aug 20 '12 at 20:52
But on the other hand it makes more mess in config files and all setup less flexible. I believe that solutions like mentioned by @JimParis LVM2 defragmenter or pvmove do the job. – Grzegorz Wierzowiecki Aug 20 '12 at 22:36

I've used LVM2 defragmenter before. It is not the simplest or best written, but it does the trick.

share|improve this answer
Looks interesting. I need to try it. – Grzegorz Wierzowiecki Aug 20 '12 at 22:35
do you believe this defrag could make it easier to (based on it) implement/create a way to recover a LV partially as stated is possible (was done) here serverfault.com/a/665826/163750 ? – Aquarius Power Feb 24 '15 at 2:59

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.