When I use LVM to partition one or more storages I noticed it use 4 MiB' blocks (physical extent) by default, while the storage itself usually uses 512 bytes per sector.

I believed it should not be a problem if I align the LVM partitions to 4 MiB, but no matter what size they be, it will always show some "not usable" size when run pvdisplay:

--- Physical volume ---
PV Name               /dev/sda2
VG Name               xpto
PV Size               17.00 GiB / not usable 4.00 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              4351
Free PE               0
Allocated PE          4351
PV UUID               xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx

But even if I reallocate the PV to match the size minus the not usable, it decrease the total PE and still have remaining not usable size. Even using pvdisplay --unit B to see the exact number.

I'm wondering what is the exact size of the LVM header, I read some text arguing it would be 4 sectors of 512 bytes, other saying it is 180 KiB, but I have tried all combinations and was not able to discover how it is calculated.

Is there a way to align the PV partition in order to zero the not usable size, or at least reduce to minimum?

  • I would swear storage has not been using 512 bytes for quite sometime now. The distribution/usage of files vs sectors is highly dependent also in what fs you are using on top of lvm – Rui F Ribeiro Aug 6 '18 at 17:59
  • @RuiFRibeiro I have read somewhere it could be 4096 bytes as well, but I believe it depend on vendor, or maybe could be customized, anyway in my case it is 512 bytes for sure. – Tiago Pimenta Aug 6 '18 at 18:03
  • 1
    Exact partition size blockdev --getsize64 /dev/sda2? Perhaps some kind of rounding error? I get for example PV Size 401.00 MiB / not usable 0 so it works for me. The extra 1.00MiB is the default metadata size (1st PE Offset). If the size is correct, which distro, version of kernel / lvm2 / ...? – frostschutz Aug 6 '18 at 18:11
  • Answer I wrote just yesterday to a similar question, may be of interest unix.stackexchange.com/a/460387/30851 – frostschutz Aug 6 '18 at 18:13
  • 1
    That 4 MB is about 0.023 % of the size of the whole PV. Are you sure it's worth spending the effort to try to recover it? – ilkkachu Aug 6 '18 at 18:24

Your Answer

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

Browse other questions tagged or ask your own question.