In order to increase the disk space of an existing virtual machine on VMware ESXi we have to do 2 steps. First, we modify the virtual machine setting to have an addition disk. This is same as we plug a new physical hard disk into a real machine. Second, we will need to go into the OS and modify the disk layout. Let’s see 2 steps in detail.
Login into VMware ESXi infrastructure using your favorite management tool. You can use the VMware vSphere Client, Web Client or CLI. In this tutorial, i use the VMware vSphere Web Client to add 100GB disk.
Then click Save to apply the changes. If you have VMware Tool installed on the virtual machine, you won’t need to reboot the it to see the new disk in the OS.
fdisk tool to make changes to the new disk
sudo fdisk /dev/sdb
n to create new partition
Command (m for help): n
Choose your partition type. Because this is the new disk, you will create the primary partition by selecting
Then specify the partition size. For example i want to use the maximum space that the disk has, so i hit ENTER key for 3 times to select the default values. Should be good.
Partition number (1-4, default 1):
t to change the partition system type. In the hex code input, use
8e as we are going to use for the LVM.
Command (m for help): t
Now it is time to write changes to the disk. Input
w to do that.
Command (m for help): w
If you receive a message saying that the kernel still using the old partition table, and to reboot to use the new table. You can use
partprobe command to do that without reboot.
sudo partprobe -s
Before we begin, let’s check the current Volume Group. In this example, my Volume Group name is ubuntu-1604-vg which has 19.52 GiB space. We will need to extend the Volume Group before adding more space to the Logical Volume.
Now, create the Physical Volume from the new partition.
sudo pvcreate /dev/sdb1
Then extend the Volume Group with above Physical Volume
sudo vgextend ubuntu-1604-vg /dev/sdb1
Double check to see whether the Volume Group was extended. We will notice that the total size was increased to 119.52 GiB.
Now let’s extend the it’s Logical Volume. You might have one or more Logical Volume. In this example i will use /dev/ubuntu-1604-vg/root which is my OS root disk. Please adjust it in your system.
sudo lvextend /dev/ubuntu-1604-vg/root /dev/sdb1
All that remains now, it to resize the file system to the Volume Group, so we can use the space.
sudo resize2fs /dev/ubuntu-1604-vg/root
Now let’s see how the the current disk usage on the system with
df -h again.