This post shows how to create LVM volume with thin provisioning, that is, only actually used ranges of the volume will actually be allocated.
Check volume groups
First, check lvm volume groups to find out which vg has space for our thin volume pool.
Choose one of the volume groups with sufficient space. Because we are using thin provisioning, we could use less space than normal provisioning.
Second, check existing logical volumes also.
Creating thin volume pool
Next, we create thin volume pool in the chosen volume group (example, vgdata).
lvcreate -L 50G --thinpool globalthinpool vgdata
Print the resulting volumes using lvs :
We see that globalthinpool are created with logical size 50 gigabytes.
Creating thinly provisioned volume
Now we create thinly provisioned volume using previously created pool.
lvcreate -V100G -T vgdata/globalthinpool -n dockerpool
The command would create a 100 G logical volume using thin provisioning. Note that the volume created is 100G, which is larger than the actual thin pool volume. Beware that we must monitor actual volume usage because if the 50GB volume runs out then the programs would froze. See http://unix.stackexchange.com/questions/197412/thin-lvm-pool-frozen-due-to-lack-of-free-space-what-to-do if you encountered such condition (hint : something like lvresize -L +100g vgdata/globalthinpool).
The result is shown in the picture below:
If we have errors such as /usr/sbin/thin_check execvp failed, usually this means thin_check not installed yet. In ubuntu, install by using
apt-get install thin-provisioning-tools
Formatting the new volume
Before the new volume could be used, format it using mkfs.ext4 :
Now we could mount it :
mount /dev/mapper/vgdata-dockervol /mnt/dockervol
LVM thin provisioning could be used so that only used blocks are being allocated in the LVM.
Note: I also have uploaded the screencast session to youtube :