Sunday 17 May 2015

How to extend an LVM partition

In my previous post, I explained how to reduce an LVM partition.

In this post, I will explain the steps to extend an LVM partition. 

NOTE: If the underlying volume group don't have enough free space, to extend the Logical Volume. The first step is to extend the underlying volume Group by adding another physical volume to it.


As per the image below, in my server I have a drive "/dev/vda" of 42 GB. I have created a PV of 20 GB from it.

From that PV, I created a VG named VG_DAS_1. From that VG,I created an LVM partitions. In our case, "/dev/mapper/VG_DAS_1-opt_oracle"  is the LVM partition which is of 10 GB.

I need to increase it to 15 GB. But, VG_DAS_1 doesn't have enough free space on it. So, first I need to  create a PV in disk "/dev/vda" and add it to VG.

STEP 1:  Create a new partition "/dev/vda3" as shown in below snapshot.

Now, in "fdisk -l" result you will be able to see the third partition "/dev/vda3" as below:

STEP 2:   Create a new PV using pvcreate command as below:

STEP 3:  Now extend VG using vgextend command as below:

Now, if you run "pvscan"  you will be able to see the output as below, with details of PVs.

STEP 4:  Extending the logical volume.

Now, the logical volume "/dev/mapper/VG_DAS_1-opt_oracle" has got 10 GB. The below snapshot shows the current status.

 Lets add 5 GB to "/dev/mapper/VG_DAS_1-opt_oracle"  using "lvextend".

A logical volume can be extended using the lvextend command. You can specify either the amount by which you want to increase the size of the volume:

lvextend --size +5G /dev/mapper/VG_DAS_1-opt_oracle

or the final size that you want to achieve:

lvextend --size 15G /dev/mapper/VG_DAS_1-opt_oracle

The snapshot below shows the result:

STEP 5:  Now, extend the filesystem using resize2fs as below:

Finally, if you run "lvs" command you will be able to see the size of LVM "opt_oracle" has increased by 5GB as a result the available size is 15 GB.

So, we have achieved our final result.

Kool :)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.