1. Shut down the VM from Hypervisor
2. Expand the disk capacity from settings with your desired value. Here we choose to expand the VHD with additional 60 GB space.
3. Start the VM from the hypervisor.
4. Login to virtual machine console as root.
5. Execute below command to check the disk space.
6. Now execute this below command to initialize the expanded space and mount it.
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').
7. After this enter ‘n’ in the next line for creating new partition.
Command action e extended p primary partition (1-4) p
8. Then assign the partition number you wish based on your existing partition numbering.If you have to expand existing linux space you have in anycase create a new partition /dev/sda3 or /dev/sda4 if was already created before.
Partition number (1-4): 3
Partition number (1-4): 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM)
9. In the next line choose code ‘8e’ for select the LINUX OS
Hex code (type L to list codes): 8e
Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM)
10. Next enter ‘w’ to proceed further.
Command (m for help): w
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
11. Reboot the system.
12. Now we need to create physical & logical volumes execute below command to create physical volume.
13. Execute below command to get the name of current Volume Group
14. Execute below command to extend the Volume Group with /dev/sda3
vgextend VolGroup /dev/sda3
15. Execute below command to get Logical Volume path.
16. Execute below command to extend the Logical Volume with /dev/sda3
lvextend /dev/VolGroup/lv_root /dev/sda3
lvextend -l+100%FREE /dev/VolGroup/lv_root
17. Execute below command to update the Logical Volume
18. Check for the new disk space.
19. Your Disk space is now successfully increased with 60 GB.
Real example of increasing space :
I create primary partition sda4, type 8E (linux lvm), and I follow the procedure.
Just resize2fs don’t work with your server, I need to use fsadm resize /dev/centos/root