Partition Concepts (With elasticity in LVM)

Ayushmilan
5 min readSep 26, 2021

In this blog, we are going to see some partition concepts and elasticity in LVM.

What is Partition & What are its use cases?

In most cases, large storage devices are divided into separate sections called partitions. Partitioning also allows us to divide our hard drive into isolated sections, where each section behaves as its own hard drive. Every time we face such cases where we need to divide one single hard disk into many sections so that we can use each section for different use.

In windows, we see different drives such as C, D, and E drive which is actually a division of one single hard disk which is further formatted and mounted for different use.

For using any hard disk we need to follow three steps:

  • Creating partition
  • Formatting the disk
  • Mounting the disk

Let’s go to see how to create and to do some operations in partitions

At first, see what is available on your disk:

Now for creating a partition we run the command: fdisk /dev/sdb

I have created a partition of 5Gb out of a total of 30 Gb available space. For this, we have to write +5G and finally

w: to save the changes

we can check this created partation

For formatting, we use this command: mkfs.ext4 /dev/sdb1

And for mounting this I created a directory with the name ayu and mounted my partition to that ayu directory by using the command:

mount /dev/sdb1 /ayu

Now Our first task is to increase and decrease the size of the static partition without losing our data.

create a file in the ayu directory and put some data.

For increasing and decreasing the size of the static partition we need to first unmount our disk.

Now we use the command:

e2fsck -f /dev/sdb1

resize2fs /dev/sdb1 +3G

It will check errors and will mark the file system as clean and the second one will decrease the size to 3GB and format the unformatted part.

Now you can mount it to the directory and check the data in that file. we can see that the disk size is now 3GB.

again repeat the above command to resize this disk to 4GB

This is my first task done, let's move to the second one.

In this, I have to integrating LVM with Hadoop and providing Elasticity to Data Node Storage.

See the disk attached to your system.

Now we will create a physical volume of /dev/sdb and /dev/sdc respectively …by using pvcreate command

now run vgcreate vg1 /dev/sdc /dev/sdb

This command will create a volume group of name vg1 and space 15 Gb combining space of /dev/sdb and /dev/sdc

let's run: lvcreate - -size 12G - -name lv1 vg1

This command will create a logical volume of size 12Gb and name lv1 and this logical volume will be over volume group vg1.

For the Hadoop cluster, we have to mount this to the data node directory after formatting.

Now we have to extend size of our storage from 12Gb to 14Gb

lvextend — size +2G /dev/vg1/lv1

This command will extend the size of our logical volume by 2Gb.

Now run resize2fs to show the changed size onto the mounted directory.

So, we have finally done the Elasticity to Data Node Storage.

In the next task, we have to implement partition concepts using python.

Here is the python code which I have done. and you can check it and go to this post to see it is working where I use it in my web menu with the integration of CGI, click here for the code and click here for the demo video.

See you in the next blog check my profile for such content.

THANK YOU.

--

--

Ayushmilan

Associate Data Scientist, Technical Content Writer, GATE CSE(2022, 2023) Qualified