🤔 🤔Just imagine of a situation where you have 8 GB pendrive(PD) and you have used its complete space and you require more storage capacity within the same pen drive, also you don’t wants to remove the previously stored data!! Is it possible ?? Physical extension won’t be possible but we can beautifully perform the logical extension of the volumes.😎
Foe this i am going to use the concept of Logical Volume Management.
Logical Volume Management is the concept of Linux. In Linux, Logical Volume Manager (LVM) is a device mapper framework that provides logical volume management for the Linux kernel. Most modern Linux distributions are LVM-aware to the point of being able to have their root file systems on a logical volume.
To know some deep use cases of LVM refer the below link :
Elasticity in the Storage of distributed Hadoop Cluster
🤔🤔Have you ever thought that how we can automate the storage size as and when required ?? Yes !! It is possible 🤩…
Lets move towards the implementation part !!🤩🤩
First of all, we will be comfortable with the environment on which we need to perform the task. Then we will toward creating an Logical Volume(LV).
Step 1: Check for the instance
Here I have already created an AWS instance of RedHat Linux.
Now to go inside this instance, i am going to use PuTTY program and will use Security key for Authentication.
Finally check the volumes attached to this instance using the command “fdisk -l ”
Here we see that apart from root hard disk, there are two external volumes one of 20 GB and other of 30 GB. Lets think of a situation where we require 35 GB of storage to store some data. Then either we need to add on more volume of 35 GB to the instance, but it will be the wastage of these 20 and 30 GB. So we are planning to combine both the volumes logically then it will be considered as a single 50 GB, That is quite exciting 😁😁
Step 3: Check the requirements and setup them
For creating a logical combined volume. These separate volumes are also known as Physical Volumes(PV). When we combine them and create a single block (logically ) then that logical block will be known as Volume Group(VG).
This Volume Group will be treated as a new device. This will be called a Logical Volume (because it is not real).
This complete concept is known as Logical Volume Management (lvm). So we need to install lvm2 here using the command “yum install lvm2 -y”
Step 4: Create a Volume Group
To create a volume group, we require physical volume. To convert this block devices into the physical volume we use the command “pvcreate device_path”
Create two physical volumes one of 20 GiB and other for 30 GiB.
Check whether they have been created or not ?? Using command “pvdisplay ”
So we have two physical volumes, lets bind them in a single logical block. to create one , we use the command “vgcreate vg_name pv_name”
Lets look its status, using command “vgdisplay vg_name”
An interesting fact about volume group is that , we can as many volumes as we want.
So we are all set with the volume group. Now we are ready to create logical partitions and to use them. 🤩🤩We can create as many partitions as we want.
Step 5: Create a Logical volume of some specific size (as per the requirement).
To create a logical volume, we use the command
To get the information about this logical volume, we use the command “lvdisplay vg_name/lv_name”
Note : We can have multiple Volume groups in a system.
Step 5: Using the created Logical Volume by mounting it to any folder.
In my case, the folder that i am going to use is /lvmStorage.
To mount this logical block on this storage directory, we use the command “mount block_name directory_name” but before mounting we need to format this first!! to format i am using mkfs.ext4 file System.
Now our volume is ready to be mounted!!
Check whether it has been mounted or not, we use “lsblk” command
Now we can store our data in the /lvmStorage directory, it will be automatically stored in the logical volume that we have created. Lets store some data here
Suppose there is a situation where we have completely used the capacity of this storage block and we want some more storage to be added in the same without loosing the previously stored data. Here comes the benefits of extending this storage size.
Step 6: Extend the storage size
To extend the storage by 10 GB , we use the command
Lets check its status
Since in the details of the logical volume it is showing that its size is increased to 45 GB from 35 GB. But right now we have 35 GB , a formatted block and 10 GB , an unformat block. It is very much obvious that we cannot allocate the unformat block to store some data in it.
The actual structure of the logical block will be :
Now this is the situation where we cannot use mkfs to format that part, because if we use this, then the complete device will be reformatted and we will loose our data that we have previously installed. So here we use “resize2fs path_of_lv” command.
Now, if we check the allocation status we will get the updated block size
Wait a min 🤔!!we haven’t checked that our previous data is being there or not??
🤩🤩yeah!!! we have complete data. You can match the timing of the data that was visited and its availability.
I hope you like this concept, and i believe that this would be helpful to you — to solve the great industry use cases. 😇
💫Keep Sharing, Keep Learning💫
Thank You !!!