Elasticity in storage of Linux

Redhat linux

🤔 🤔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.

Complete architecture that how LVM works

To know some deep use cases of LVM refer the below link :

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.

running instance

Now to go inside this instance, i am going to use PuTTY program and will use Security key for Authentication.

successfully login

Finally check the volumes attached to this instance using the command “fdisk -l

Volumes available

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

installing lvm2
successfully installed lvm2

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.

successfully created both pv

Check whether they have been created or not ?? Using command “pvdisplay

Both the physical volumes

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

successfully created volume group

Lets look its status, using command “vgdisplay vg_name

Detailed info about the volume group

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

successfully created a logical volume

To get the information about this logical volume, we use the command “lvdisplay vg_name/lv_name

our logical volume complete info

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.

Successfully created the folder/directory

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.

Successfully formatted the volume

Now our volume is ready to be mounted!!

Successfully mounted the volume

Check whether it has been mounted or not, we use “lsblk” command

our logical volume

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

Added one file lvmInfo

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

Extending the volume capacity

Lets check its status

Successfully extended

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.

Only allocated the formatted part

The actual structure of the logical block will be :

Actual structure of logical volume (this time)

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.

On-line resizing of logical volume

Now, if we check the allocation status we will get the updated block size

Successfully resized and allocated the complete block

Wait a min 🤔!!we haven’t checked that our previous data is being there or not??

Data in the /lvmStorage directory

🤩🤩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 !!!

I am a tech enthusiast, researcher and work for integrations. I love to explore and learn about the new technologies and their right concepts from its core.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store