DEV Community

AJAY SHRESTHA
AJAY SHRESTHA

Posted on

Increase the Size of a Virtual Machine on VMware ESXi

Expanding the storage capacity of a virtual machine (VM) can often be necessary as your data requirements grow over time. This process involves increasing the virtual disk size and extending the filesystem within your VM to utilize the new space. This blog will guide you through the steps of increasing the size of a VM using VMware ESXi and resizing partitions within a Linux system (Ubuntu), as detailed by a typical "lsblk" output.

NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                         8:0    0   50G  0 disk 
├─sda1                      8:1    0    1M  0 part 
├─sda2                      8:2    0  1.5G  0 part /boot
└─sda3                      8:3    0 18.5G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0   10G  0 lvm  /
sr0                        11:0    1  1.2G  0 rom  
Enter fullscreen mode Exit fullscreen mode

Understanding the Current Setup
Before making changes, it's crucial to understand the current disk setup. Here's a breakdown based on the lsblk output:

sda: The primary disk with a total size of 50 GB.
sda1: A small partition, likely for boot loader-related files.
sda2: The boot partition with 1.5 GB.
sda3: An 18.5 GB partition, part of an LVM setup that houses the logical volume.
ubuntu--vg-ubuntu--lv: The logical volume where the root filesystem is mounted, currently sized at 10 GB.

Step 1: Increase the Virtual Disk Size
The first step involves increasing the disk size in VMware ESXi:

  • Shut down the VM: Ensure data integrity by shutting down the VM before changing disk sizes.
  • Modify Virtual Machine Settings: In the VMware ESXi, right-click the VM and select "Edit Settings". Choose the virtual disk you want to expand and set a new, larger size. We'll increase our example to utilize the full 50 GB of sda.
  • Apply Changes and Restart the VM: Save the changes and boot the VM.

Step 2: Resize the Physical and Logical Volumes
Now that the VM's disk is larger, the Linux system needs to utilize the new space.

Extend the Physical Partition
You might need to resize the physical partition (sda3) to fill the expanded disk space:

  • Use a Partition Tool: Tools like gparted are user-friendly for resizing partitions. You can also use fdisk or parted from the command line. Be careful not to delete the partition—just resize it.
sudo parted /dev/sda
resizepart 3 100%
quit
Enter fullscreen mode Exit fullscreen mode

Note: Adjust the endpoint (100%) based on available disk space or how much you want to assign.

  • Update the system about the change in partition size:
sudo partprobe /dev/sda
Enter fullscreen mode Exit fullscreen mode
  • Resize the Physical Volume: After adjusting the partition, use pvresize to resize the physical volume:
sudo pvresize /dev/sda3
Enter fullscreen mode Exit fullscreen mode

Extend the Logical Volume:
Increase the size of the logical volume using the lvextend command:

sudo lvextend -L +50G /dev/ubuntu--vg/ubuntu--lv
Enter fullscreen mode Exit fullscreen mode

Step 3: Resize the Filesystem
Finally, resize the filesystem to make use of the additional space in the logical volume:

  • For ext4 filesystems
sudo resize2fs /dev/ubuntu--vg/ubuntu--lv
Enter fullscreen mode Exit fullscreen mode
  • For xfs filesystems:
sudo xfs_growfs /
Enter fullscreen mode Exit fullscreen mode

Conclusion
After completing these steps, your VM should have more disk space available, as confirmed by running "df —h" to view the filesystem sizes. This process helps accommodate growing data needs without the need to migrate to a new VM. Regularly monitoring disk usage and proactively managing storage resources ensures optimal performance and avoids potential data storage crises in a virtualized environment.

Expanding a VM's disk in VMware ESXi and managing partitions on Linux can seem daunting, but with careful planning and execution, it can be straightforward. Always ensure you have reliable backups before undertaking such tasks to protect against accidental data loss.

Top comments (0)