Thin Provisioning is a way of providing 5gb of free space to 3 Logical Partitions, but using a 10GB Volume. You may have noticed that 5gb x 3 partitions = 15gb, not 10gb. This is correct. You are able to assign more space than you have, with the idea of adding the extra disks when you need them. You do not get “magic space”. You need to keep a close eye on the usage to ensure that the total data does not exceed the size of the thin_pool This is useful if you don't know which partition is going to need the space, or it is important that there is no lower hard limit.
vgcreate -s 32M vg_thin /dev/sdb1
lvcreate -L 10G --thinpool tp_pool vg_thin
lvs # Check the Status
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <77.47g
tp_pool vg_thin twi-a-tz-- 10.00g 0.00
Notice the Data% column here, this shows the usage of the pool. You need to take action when it nears 100%
lvcreate -V 5G --thin -n thin_one vg_thin/tp_pool
lvcreate -V 5G --thin -n thin_two vg_thin/tp_pool
lvcreate -V 5G --thin -n thin_three vg_thin/tp_pool
lvs #Check status again
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <77.47g
tp_pool vg_thin twi-a-tz-- 10.00g 0.00
thin_one vg_thin Vwi-a-tz-- 5.00g 0.00
thin_two vg_thin Vwi-a-tz-- 5.00g 0.00
thin_three vg_thin Vwi-a-tz-- 5.00g 0.00
>
mkdir -p /mnt/pool1 /mnt/pool2 /mnt/pool3
mkfs.ext4 /dev/vg_thin/thin_one && mkfs.ext4 /dev/vg_thin/thin_two && mkfs.ext4 /dev/vg_thin/thin_three
mount /dev/vg_thin/thin_one /mnt/pool1/ && mount /dev/vg_thin/thin_two /mnt/pool2/ && mount /dev/vg_thin/thin_three /mnt/pool3/
#add some random data to these folders (DON'T EXCEED 10GB TOTAL)
>
lvdisplay vg_thin/tp_thin --- Logical volume --- LV Name tp_thin VG Name vg_thin LV UUID R0beoU-6OJ6-e83O-h435-BeN1-gHcn-sDdo62 LV Write Access read/write> LV Creation host, time localhost, 2019-08-29 13:>23:>17 +0000 LV Pool transaction ID 3 LV Pool metadata tp_thin_tmeta LV Pool data tp_thin_tdata LV Pool chunk size 64.00 KiB LV Zero new blocks yes LV Status available LV Size 15.00 GiB Allocated pool data 54.14% Allocated metadata 13.47% Current LE 480 Segments 1 Allocation inherit Read ahead sectors auto - currently set> to 8192 Block device 253:>0 lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <77.47g tp_pool vg_thin twi-a-tz-- 10.00g 54.14 thin_one vg_thin Vwi-a-tz-- 5.00g 21.42 thin_two vg_thin Vwi-a-tz-- 5.00g 18.71 thin_three vg_thin Vwi-a-tz-- 5.00g 19.24
You can use the same tools as normal volumes. Ensure that you have free space in the parent pool (vg_thin) Add new disks if needed.
lvextend -L +15G /dev/vg_thin/tp_pool
lvs #Lets see the changes
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <77.47g
tp_pool vg_thin twi-a-tz-- 25.00g 21.61
thin_one vg_thin Vwi-a-tz-- 5.00g 21.42
thin_two vg_thin Vwi-a-tz-- 5.00g 18.71
thin_three vg_thin Vwi-a-tz-- 5.00g 19.24
You can see the tp_pool is now down to 21% and we can keep writing data. In this situation we are safe, becuse we only have 3x5gb=15gb of 25gb assigned.