February 15, 2010

LVM, inherit and contiguous policies

Recently I was trying to do a regular and simple task for a maintenance: extending a LVM partition. But when using the lvextend on that certain logical volume I was greeted with an error:

" Insufficient suitable contiguous allocatable extents for logical volume "

That was pretty odd, I had recently resized other partitions on that very server and there was nothing “unusual” about its setup: hardware raid, one volume group occupying the entire array and all the logical volumes in that volume group. Googled a bit, but nothing relevant. Then I did what I should have done in the first place: ran the command lvscan to show me some details about the logical volumes.

I noticed that the partition I wanted to extend was different from the others: it had as allocation policy “contiguous” instead of “inherit” like all the others. The manual for LVM ( man 8 lvm ) provides us with all the answers:

" The default for a logical volume is inherit which applies the same policy as for the volume group. "
" The contiguous policy requires that new extents be placed adjacent to existing extents. "

So my partition could be extended just by using free space on the drive that was next to it. And there wasn’t any because there were other partitions created after it. Someone had created - for unknown and illogical reasons in our case - the partition with a “ contiguous “ allocation policy. So this was an easy fix:

lvchange --alloc inherit [lv]

Then I could extend my partition easily. The moral of the story: be careful when creating LVM partitions and volume groups to assign them their allocation policyin line with your needs and setup.