Setup Thin Provisioning Volumes in Logical Volume Management (LVM) – Part IV

[‘

n

Logical Volume management has great features such as snapshots and Thin Provisioning. Previously in (Part – III) we have seen how to snapshot the logical volume. Here in this article, we will going to see how to setup thin Provisioning volumes in LVM.

n

Setup Thin Provisioning in LVM
Setup Thin Provisioning in LVM

n

What is Thin Provisioning?

n

Thin Provisioning is used in lvm for creating virtual disks inside a thin pool. Let us assume that I have a 15GB storage capacity in my server. I already have 2 clients who has 5GB storage each. You are the third client, you asked for 5GB storage. Back then we use to provide the whole 5GB (Thick Volume) but you may use 2GB from that 5GB storage and 3GB will be free which you can fill it up later.

n

But what we do in thin Provisioning is, we use to define a thin pool inside one of the large volume group and define the thin volumes inside that thin pool. So, that whatever files you write will be stored and your storage will be shown as 5GB. But the full 5GB will not allocate the entire disk. The same process will be done for other clients as well. Like I said there are 2 clients and you are my 3rd client.

n

So, let us assume how much total GB I have assigned for clients? Totally 15GB was already completed, If someone comes to me and ask for 5GB can I give? The answer is “Yes“, here in thin Provisioning I can give 5GB for 4th Client even though I have assigned 15GB.

n

Warning: From 15GB, if we are Provisioning more than 15GB it is called Over Provisioning.

n

How it Works? and How we provide storage to new Clients?

n

I have provided you 5GB but you may used only 2GB and other 3GB will be free. In Thick Provisioning we can’t do this, because it will allocate the whole space at first itself.

n

In thin Provisioning if I’m defining 5GB for you it won’t allocate the whole disk space while defining a volume, it will grow till 5GB according to your data write, Hope you got it! same like you, other clients too won’t use the full volumes so there will be a chance to add 5GB to a new client, This is called over Provisioning.

n

But it’s compulsory to monitored each and every volume growth, if not it will end-up in a disaster. While over Provisioning is done if the all 4 clients write the data’s badly to disk you may face an issue because it will fill up your 15GB and overflow to get drop the volumes.

n

Requirements

n

    n

  1. Create Disk Storage with LVM in Linux – PART 1
  2. n

  3. How to Extend/Reduce LVM’s in Linux – Part II
  4. n

  5. How to Create/Restore Snapshot of Logical Volume in LVM – Part III
  6. n

n

My Server Setup

n

    n

  1. Operating System – CentOS 6.5 with LVM Installation
  2. n

  3. Server IP – 192.168.0.200
  4. n

n

Step 1: Setup Thin Pool and Volumes

n

Let’s do it practically how to setup the thin pool and thin volumes. First we need a large size of Volume group. Here I’m creating Volume group with 15GB for demonstration purpose. Now, list the volume group using the below command.

n

# vgcreate -s 32M vg_thin /dev/sdb1rn

n

Listing Volume Group
Listing Volume Group

n

Next, check for the size of Logical volume availability, before creating the thin pool and volumes.

n

# vgsrn# lvsrn

n

Check Logical Volume
Check Logical Volume

n

We can see there is only default logical volumes for file-system and swap is present in the above lvs output.

n

Creating a Thin Pool

n

To create a Thin pool for 15GB in volume group (vg_thin) use the following command.

n

# lvcreate -L 15G --thinpool tp_tecmint_pool vg_thinrn

n

    n

  1. -L – Size of volume group
  2. n

  3. –thinpool – To o create a thinpool
  4. n

  5. tp_tecmint_pool– Thin pool name
  6. n

  7. vg_thin – Volume group name were we need to create the pool
  8. n

n

Create Thin Pool
Create Thin Pool

n

To get more detail we can use the command ‘lvdisplay’.

n

# lvdisplay vg_thin/tp_tecmint_poolrn

n

Logical Volume Information
Logical Volume Information

n

Here we haven’t created Virtual thin volumes in this thin-pool. In the image we can see Allocated pool data showing 0.00%.

n

Creating Thin Volumes

n

Now we can define thin volumes inside the thin pool with the help of ‘lvcreate’ command with option -V (Virtual).

n

# lvcreate -V 5G --thin -n thin_vol_client1 vg_thin/tp_tecmint_poolrn

n

I have created a Thin virtual volume with the name of thin_vol_client1 inside the tp_tecmint_pool in my vg_thin volume group. Now, list the logical volumes using below command.

n

# lvs rn

n

List Logical Volumes
List Logical Volumes

n

Just now, we have created the thin volume above, that’s why there is no data showing i.e. 0.00%M.

n

Fine, let me create 2 more Thin volumes for other 2 clients. Here you can see now there are 3 thin volumes created under the pool (tp_tecmint_pool). So, from this point, we came to know that I have used all 15GB pool.

n

Create Thin Volumes
Create Thin Volumes

n

Creating File System

n

Now, create mount points and mount these three thin volumes and copy some files in it using below commands.

n

# mkdir -p /mnt/client1 /mnt/client2 /mnt/client3rn

n

List the created directories.

n

# ls -l /mnt/rn

n

Creating Mount Points
Creating Mount Points

n

Create the file system for these created thin volumes using ‘mkfs’ command.

n

# mkfs.ext4 /dev/vg_thin/thin_vol_client1 && mkfs.ext4 /dev/vg_thin/thin_vol_client2 && mkfs.ext4 /dev/vg_thin/thin_vol_client3rn

n

Create File System
Create File System

n

Mount all three client volumes to the created mount point using ‘mount’ command.

n

# mount /dev/vg_thin/thin_vol_client1 /mnt/client1/ && mount /dev/vg_thin/thin_vol_client2 /mnt/client2/ && mount /dev/vg_thin/thin_vol_client3 /mnt/client3/rn

n

List the mount points using ‘df’ command.

n

# df -hrn

n

Print Mount Points
Print Mount Points

n

Here, we can see all the 3 clients volumes are mounted and therefore only 3% of data are used in every clients volumes. So, let’s add some more files to all 3 mount points from my desktop to fill up some space.

n

Add Files To Volumes
Add Files To Volumes

n

Now list the mount point and see the space used in every thin volumes & list the thin pool to see the size used in pool.

n

# df -hrn# lvdisplay vg_thin/tp_tecmint_poolrn

n

Check Mount Point Size
Check Mount Point Size

n

Check Thin Pool Size
Check Thin Pool Size

n

The above command shows, the three mount pints along with their sizes in percentage.

n

13% of datas used out of 5GB for client1rn29% of datas used out of 5GB for client2rn49% of datas used out of 5GB for client3rn

n

While looking into the thin-pool we can see only 30% of data is written totally. This is the total of above three clients virtual volumes.

n

Over Provisioning

n

Now the 4th client came to me and asked for 5GB storage space. Can I give? Because I had already given 15GB Pool to 3 clients. Is it possible to give 5GB more to another client? Yes it is possible to give. This is when we use Over Provisioning, which means giving the space more than what I have.

n

Let me create 5GB for the 4th Client and verify the size.

n

# lvcreate -V 5G --thin -n thin_vol_client4 vg_thin/tp_tecmint_poolrn# lvsrn

n

Create thin Storage
Create thin Storage

n

I have only 15GB size in pool, but I have created 4 volumes inside thin-pool up-to 20GB. If all four clients start to write data to their volumes to fill up the pace, at that time, we will face critical situation, if not there will no issue.

n

Now I have created file system in thin_vol_client4, then mounted under /mnt/client4 and copy some files in it.

n

# lvsrn

n

Verify Thin Storage
Verify Thin Storage

n

We can see in the above picture, that the total used size in newly created client 4 up-to 89.34% and size of thin pool as 59.19% used. If all these users are not writing badly to volume it will be free from overflow, drop. To avoid the overflow we need to extend the thin-pool size.

n

Important: Thin-pools are just a logical volume, so if we need to extend the size of thin-pool we can use the same command like, we’ve used for logical volumes extend, but we can’t reduce the size of thin-pool.

n

# lvextendrn

n

Here we can see how to extend the logical thin-pool (tp_tecmint_pool).

n

# lvextend -L +15G /dev/vg_thin/tp_tecmint_poolrn

n

Extend Thin Storage
Extend Thin Storage

n

Next, list the thin-pool size.

n

# lvsrn

n

Verify Thin Storage
Verify Thin Storage

n

Earlier our tp_tecmint_pool size was 15GB and 4 thin volumes which was over Provision by 20GB. Now it has extended to 30GB so our over Provisioning has been normalized and thin volumes are free from overflow, drop. This way you can add ever more thin volumes to the pool.

n

Here, we have seen how to create a thin-pool using a large size of volume group and create thin-volumes inside a thin-pool using Over-Provisioning and extending the pool. In the next article we will see how to setup a lvm Striping.

n

‘]