James's Ramblings

LVM

Created: May 24, 2020

Thin Provisioning

Thin provisioning allows the provisioning of more space than is actually physically present in the physical volume or volume group.

Thin provisioned volumes be contained within a special type of logical volume called a Thin Pool.

To create a thin pool (TP):

lvcreate -L SIZE --thinpool LV_NAME VG_NAME

To create a volume (potentially overprovisioned) within the thin pool:

lvcreate -V SIZE --thin -n LV_NAME VG_NAME/TP_NAME

The thin pool and any overprovisioned volumes need monitoring using lvs to ensure the thin pool does not fill up.

The use case for thin provisioning is when future storage requirements are unknown and when the thin pool can be constantly monitored.

Automatically Extending Thin Pools

In /etc/lvm/lvm.conf there are two relevant (default) settings:

thin_pool_autoextend_threshold = 100
thin_pool_autoextend_percent = 20

When set below 100(%) thin_pool_autoextend_threshold triggers an automatic extension of the thin pool at the specified percentage. Setting the threshold to 100 disables automatic extensions.

thin_pool_autoextend_percent is the percentage that the logical volume is extended by when an automatic extension event occurs.

Use with care as the thin pool could easily grow to the size of the entire volume group.

Limiting the Size of the Overprovisioned LV

A trick to make thin pools a bit less cumbersome is to artificially limit the size of whatever is contained within the overprovisioned LV to what is physically available.

For example, the volume groups of a VM guest that uses the overprovisioned volume (on the host) as a disk could be limited to what is physically available (on the host). When more storage is added/ required, lvextend could be used to do a live resize.

One alternative might be to use a normal LV, enlarge the (host) LV when necessary, and then resize from within the guest. However, this approach means the physical volume of the guest would need resizing, which involves unmounting logical volumes (aka downtime).

Filesystems, however, can usually be grown online. Using a normal LVM would probably be preferable for that use case.