How To Extend a Logical Volume On Linux OS-Virtualize Environment.

To extend the logical volume on Linux OS

Purpose/Scope
This article provides steps for extending the root partition residing in a logical volume created with Logical Volume Manager (LVM) in a virtual machine running Red Hat/CentOS.

Caution: Always take a complete backup of the virtual machine prior to making these changes.
1.Power off the virtual machine.


a. Click Edit the virtual machine settings and extend the virtual disk size.

i.e existing size is 75 G space allocated.

b. Increase the size of the disk volume up 200G.

i.e Increase the size of the drive volume to 200G.
c. Power on the virtual machine update Hard Drive Increase at VMDK level(VMware)

d. Log into Linux OS as Root and Open Terminal Shell Window-

 

 

*Will be using PVS, VGS and LVS commands.

e. Identify the device name, which is by default /dev/sda, and confirm the new size by running the command:

# fdisk -l

fdisk -l result:

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors (200G allocate on step b)
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b48a5
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   157286399    78130176   8e  Linux LVM
Disk /dev/mapper/centos-root: 52.3 GB, 52269416448 bytes, 102088704 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-home: 25.5 GB, 25518145536 bytes, 49840128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

f.Create a new primary partition:
Run the command:

1. # fdisk /dev/sda

By default, there are 2: sda1 and sda2. 2. Press n to create a new primary partition. 3. Press p for primary. 4. Press 3 for the partition number, depending on the output of the partition table print.

5. Press 3 for the partition number, depending on the output of the partition table print.
6. Press Enter two times.

 


7. Press t to change the system’s partition ID.
8. Press 3 to select the newly creation partition.
  

9.Type 8e to change the Hex Code of the partition for Linux LVM.


10.  Press “w” to write the changes to the partition table.

*Save change by press w to complete the above steps- This required.

g.Restart the virtual machine.
Run this command to verify that the changes were saved to the partition table and that the new partition has an 8e type:

11..# fdisk -l

h.Run this command to convert the new partition to a physical volume:

Note: The number for the sda can change depending on system setup. Use the sda number that was created in step f.

# pvcreate /dev/sda3

i. Run this command to extend the physical volume:

# vgextend centos /dev/root

Note: To determine which volume group to extend, use the command vgdisplay.

j.Run this command to verify how many physical extents are available to the Volume Group:

1# vgdisplay centos| grep “Free”

2..Run the following command to extend the Logical Volume:

3.# lvextend -L+#G /dev/centos/root

 

Where # is the number of Free space in GB available as per the previous command. Use the full number output from Step including any decimals.

Note: To determine which logical volume to extend, use the command lvdisplay.

4.Run the following command to expand the ext3 filesystem online, inside of the Logical Volume:

#xfs_growfs /dev/centos/root

Notes:
Use resize2fs instead of ext2online if it is not a Red Hat virtual machine.
By default, Red Hat and CentOS 7 use the XFS file system you can grow the file system by running the xfs_growfs command.

 

5.Run the following command to verify that the / filesystem has the new space available:

# df -h /


Reference:
Extending a logical Volume in a virtual machine running RHEL and Centos OS
https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006371

How to Increase the size of a Linux LVM by expanding the virtual machine disk
https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk/

How to extend  and reduce LVM on Linux 
https://www.tecmint.com/extend-and-reduce-lvms-in-linux/

Setup Flexible Disk Storage with Logical Volume Managment (LVM) in Linux
https://www.tecmint.com/create-lvm-storage-in-linux/

Increase virtual disk on Vmware Vsphere
https://kb.vmware.com/selfservice/microsites/microsite.do?cmd=displayKC&docType=kc&externalId=1004047&sliceId=1&docTypeID=DT_KB_1_1

RHEL Logical Volume Management 
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/

Extend Disk Space-LVM How To Video
https://www.youtube.com/watch?v=d0Vj7mgJlxM


Leave a Reply

Your email address will not be published. Required fields are marked *