I wanted to create a new LV on one of my VGs, but I wanted it to be allocated at the end of the PV because I knew that I wouldn't want to extend it (or if I ever did, I wouldn't care about its content -- it was for a /tmp partition), and I wanted the LVs on that same PV to be able to extend linearly if possible. Basically, I wanted to create a new LV that wouldn't get in the way.
The only solution I found was kind of the nuclear one, but it works great: specify which Physical Extents (PEs) the LV should be allocated on. This can easily be specified to lvcreate
as a :PEStart-PEEnd
suffix to the PhysicalVolumePath
argument.
But to provide the correct PE range, we first need to find what "correct" is here. For that, pvdisplay --maps
comes in handy, showing how PEs are allocated on a PV. Once you got the free PE range(s), and the PE size, you can easily calculate how many PEs you'll need, and so which range to specify. Beware though, apparently if you want to allocate the very last PE, you should not specify it, but simply give an "open" range, like ":PEStart-": otherwise, lvcreate
told me the range was incorrect (and if you guess it was a 0-based PE value and lower start and end by 1, you get 1 free PE at the end).
As you provide PE ranges, I suggest you provide the size of the LV in Logical Extents (LEs, --extents
) instead of megabytes or gigabytes (--size
) -- anyway you already calculated how many PEs you needed for the size you wanted.
I also chose to explicitly specify the allocation policy as contiguous, just to be sure LVM wouldn't try and be a smartass behind my back in case I messed up with my ranges.
In the end, I ended up with this command:
lvcreate --alloc contiguous -l768 -n NewLVName VGName /dev/mapper/PVName:37149-
And a pvdisplay --maps
nicely shows I got free PEs only before that LV -- so you could extend the previous one even with the contiguous allocation policy.
PS: well, actually I didn't use this command exactly, because I didn't know about that last PE range issue, so I first allocated it one PE too short of the range I wanted. But then, I decided it was alright and just extended the LV by one PE, using lvextend --alloc contiguous -l+1 /dev/mapper/VGName-LVName /dev/mapper/PVName:37148-
.