RHCE

How to create LVM or Logical volume Management in Linux?

In this article I will explain, What is disk stripping? Or How can we create Logical volume management or LVM in Linux? But before this, You must know that What is LVM? Friends if knows the answer then before reading next please write in the comment box and if don’t know just continue your study. So, Guys, LVM refers to device mapper which helps in disk management in Linux. It helps in allocating disks,  striping, mirroring, and resizing of volume disks. With the help of LVM, a set of hard disks can be allocated with different sizes of volumes. Basically, it is used to manage logical disk for allocating dynamic volume which can be increased or decrease according to requirements of the user. It is the Modern way of managing Volume management and quite easy comparing to the traditional method of managing storage volumes.

Like Raid Array, we don’t need logical volumes of the same size. You can create LVM over logical disk having different sizes. For example, you have  3 logical disks having sizes of 2TB, 3TB and 500GB. Here you don’t need to have the same size of volumes. The advantage of LVM is that it is flexible which means its size can be increase or decrease as per user requirements.

LVM is different from Raid Array because Raid Array is the grouping of Physical disks while LVM is the logical management of volumes. LVM is used for Flexibility while Raid array is used for Redundancy. So both LVM and Raid Array are different from each other.

Here suppose I have 3 disks named sda1,sda2 and sda3. All disks having the size of 2TB, 3TB and 500GB respectively. Here I want to create a new partition of 500GB from total available space. You can create more than one but its name must be different from the first one. Let’s learn –

Steps To Create LVM in Linux –

Create a group of  Physical Volumes

[ root@rdsaini ~]#pvcreate /dev/sda{1,2,3}
[ root@rdsaini ~]#pvs/pvscan/pvdisplay
  • pvcreate stands for physical volume create.  It is a command to create Physical Volumes.
  • pvs/pvscan/display – the command to watch physical volumes

Now create Volume group of Physical Volume Group

[ root@rdsaini ~]#vgcreate vg1 /dev/sda{1,2,3}
[ root@rdsaini ~]#vgs/vgscan/vgdisplay
  • vgcreate stands for volume group create. It is the command to create a volume group.
  • vgs/vgscan/vgdisplay – the command to watch the volume group.

Create New logical volumes

[ root@rdsaini ~]#lvcreate -L +500GB -n lv1 vg1
[ root@rdsaini ~]#lvs/lvscan/lvdisplay
  • lvcreate stands logical volume. It is the command to create the logical volume.
  • -L +500GB stands for length/size of Logical Volume where -L is constant and size can change according to requirement.
  • -n stands for the name of the logical volume.
  • lv1 – Name was given to logical Volume.
  • vg1 – Path of the logical volume where we have created LVM.

Create a New Directory

[ root@rdsaini ~]#mkdir /lvm

Format Logical Volume to Mount it

[ root@rdsaini ~]#mkfs.ext3 /dev/vg1/lv1

Mount logical Volume in a Directory

[ root@rdsaini ~]#mount /dev/vg1/lv1 /lvm
  • /dev/vg1/lv1 – Path of the logical volume.

Till now, we have learned What is LVM, What is the use of LVM and How to create LVM in Linux. Now we will learn How we can remove Logical Volume from Linux. Before creating LVM, we created a group of physical disks i.e. PV(Physical volume) and then we created vg1 i.e. our volume group and then we created an lv1 having the size of 500GB i.e. our Logical Volume. In the same way, we can create many Logical Volumes of different size. For example, we can create lv2,lv3,lv4……….LVn of different. We can create in Megabytes or Gigabytes according to space required.

Now we will learn the process of removing LVM in Linux. The process of removing LVM is just opposite to creation of Logical Volume. Because during creation first we have to start by creating Physical volume but it has a reverse process of its deletion. So first we will remove lv1 i.e our Logical Volume and we named it as lv1. and then we remove the vg1 and later we will remove our Physical volume.

Let’s learn how to remove Logical Volume Management(LVM) step by step –

Unmount your Mounted Directory

[ root@rdsaini ~]#umount /lvm

Remove Logical Volume

[ root@rdsaini ~]#lvremove /dev/vg1/lv1

 Are sure to remove Logical Volume -y/n (yes/no)

Press Y for continue or Type Yes

Now remove Volume groups

[ root@rdsaini ~]#vgremove vg1

‘Remove Physical Volumes of disks

[ root@rdsaini ~]#pvremove /dev/sda{1,2,3}

In this post, we have learned What is Logical Volume Management or LVM? How to create Logical Volume? How to remove LVM from Linux. So, Guys if you have doubts or any queries with this post then don’t hesitate to contact me. And if you have any suggestions for me then please write to me in the comment box. I’ll get back to you as soon as possible. If you like my posts please share it with your friends.

 

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s