LVM thin provisioning allows you to over-commit the physical storage. You can create file systems which are larger than the available physical storage. LVM thin provisioning allows you to create virtual disks inside a thin pool. The size of the virtual disk can be greater than the available space in the thin pool. It is important that you monitor the thin pool and add more capacity when it starts to become full.
Create Thin pool
Thin pools are created using the lvcreate command and as such, they are essentially logical volumes. Use either the –T option, or the –thin option, or the –thinpool option when creating a thin pool. The following example creates a thin pool named mythinpool from the centos volume group that is 100m in size:
# lvcreate -v -L 100m -T centos/mythinpool ... Logical volume “mythinpool” created
# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mythinpool centos twi-a-tz-- 100.00m 0.00
The “Data%” column shows the allocated pool data. The example shows 0.00% because virtual thin volumes have not yet been created in this thin-pool.
Create Thin Volume
Use the lvcreate command with the –V option to create a thin volume (a virtual disk) from a thin pool. The following example creates a 1 GB thin volume named mythinvol in the centos/mythinpool thin pool. Note that the size of the thin volume is larger than the size of the thin pool that contains it.
# lvcreate -V 1g -T centos/mythinpool -n mythinvol Logical volume "mythinvol" created
# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mythinpool centos twi-a-tz-- 100.00m 0.00 mythinvol centos
Vwi-a-tz-- 1.00g mythinpool 0.00
Note the difference in attributes. The thin volume has a V attribute for virtual disk. The Data% column shows 0.00 until you create a file system on the thin volume.
Create File system
Lets create an ext4 filesystem on the thin volume we just created.
# mkfs.ext4 /dev/centos/mythinvol # mkdir /myvol # mount /dev/centos/mythinvol /myvol
Check the size of mount point in df -hP command output.
# df -hP | grep myvol /dev/mapper/centos-mythinvol 976M 2.6M 907M 1% /myvol
Create a file of size 100MB using fallocate in the /myvol directory.
# cd /myvol # fallocate -l 100m test_file
# df -hP | grep my /dev/mapper/centos-mythinvol 976M 103M 807M 12% /myvol
# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mythinpool centos twi-a-tz-- 100.00m 49.00 mythinvol centos Vwi-aotz-- 1.00g mythinpool 4.79
This shows you have used 49% of the allocated pool data. This also shows that the thin volume has used 4.79% of 1 GB.
Extending thin pool
You can use the lvextend command to add space to a thin pool logical volume.
# lvextend -L 500m centos/mythinpool Extending logical volume mythinpool_tdata to 500.00 MiB Logical volume mythinpool successfully resized
Note that the size of the thin pool is now 500 MB and the percentage used is 9.81%.
# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mythinpool centos twi-a-tz-- 500.00m 9.81 mythinvol centos Vwi-aotz-- 1.00g mythinpool 4.79