Genz
Rajesh Radhakrishnan
19/02/2019 Published 3 weeks ago
Share
https://vmarena.com/wp-content/uploads/2024/11/cloud-services-isometric-composition-with-flat-silhouette-pictograms-big-cloud-storage-with-people-vector-illustration_1284-30499.jpg

How to Extend Virtual Machine LVM Disk

Recently I have deployed a virtual machine from an OVF template to monitor firewall devices and in few days the VM is hung due to the default disk size. This is a Linux virtual machine and I have to extend the drives to bring up the virtual machine back. In this post, I will share the steps I followed to solve the issue.

First Extend the Virtual Machine Disk

Right Click on the VM – > Edit Setting – > Select the Disk and change the Drive Size and Click Ok.

 

we need to create a separate partition and expand the size of LVM which having low space partition.

login to the Virtual machine from Console or use putty if ssh is available, here we perform this procedure from the putty session and run the below command

#fdisk -l   (list the partitions and you can see the device size), as you can see device /dev/sda has a total size of 322 GB and two partitions

Let’s check out the physical volume and lvm detail by running below commands

#pvs

#vgs

#lvs

As you can see there are no free space available in Physical Volume and Volume group and we can’t extend the lvm size . To extend we need to add one physical volume (PV), and then we have to extend the volume group by extending the vg.

Add a Physical Volume (PV)

To add a new PV we have to use fdisk command  and below steps

#fdisk /dev/sda
# Press n  (To Create new partition)
p (Choose primary partition use)
#Choose which number of partition to be selected to create the primary partition.
#Press 1 or next available disk number ( if any other disk already there it will list the available number and you can choose that )
t ( Change the type using )
#Type 8e ( to change the partition type to Linux LVM )

#Use p to print the partition details

#Press w to write the changes.

Restart the system once completed.

Create new PV (Physical Volume) using the following command.

#pvcreate /dev/sda3

Extending Volume Group

Add this PV to  VG to extend the size of a volume group to get more space for expanding LV.

#vgextend centos_cactitemplate /dev/sda3

Check the size of a Volume Group now using.

# vgs
# pvscan

Check the size of each logical volume we have currently before expanding it.

  1. swap defined for Swap.
  2. root defined for /
  3. Now we have 6.67 GB size for / (root).
  4. Currently there are 8192 Physical Extend (PE) available.

Check the available Physical Extend size run.

#vgdisplay

There are 74761 free PE available = 292.04 GB Free space available, So we can expand our logical volume up-to 292 GB more

Now let’s do expansion qith 6000 PE

#lvextend -l +6000 /dev/centos_cactitemplate/root

Note:- Use + to add the more space.

Once extended re-size the file-system

Here tried the #resize2fs  command to rezise the file system and we got error .let see how to resolve this

We will check the existing filesystem type using below command

#mount |grep centos

here found its xfs and we have to use xfs related command to resize, let do with below commands

#xfs_growfs /dev/centos_cactitemplate/root

Check the size of the filesystem using below command 
 
#df -h

here you can see we have increased the space of the partition from 7 GB to 32 GB

 

Conclusion 

We have successfully extended LVM partition of the Linux Virtual Machine and it is available to use.