How to increase virtual machine disk size in VMware? , Ranjan.info

The main advantage of virtual machines is the flexibility to allocate additional resources to VMs when you need them. If you run out of free space on your virtual hard disk, you can increase it quickly and easily. This article describes how to resize virtual machine disk in VMware ESXi and then extend partition in Windows or Ubuntu guest OS without stopping or rebooting the virtual machine.

There are some limitations to consider when it comes to increasing the hard disk size of a VMware virtual machine:

Cannot resize VMDK on VMware: The attempted operation cannot be performed in its current state

The process of increasing the disk size of a virtual machine consists of two steps:

  1. First, you need to increase the size of the VMDK file in the VM settings on vCenter/ESXi;
  2. Then extend the disk partition in the guest OS (we’ll take a separate look at how to extend a hard drive on both Windows and Linux).

Increase VM Disk (VMDK) size in VMware

For example, you have a virtual machine with a single virtual hard disk file (vmdk) of 40GB, and you plan to increase this virtual disk size to 50GB.

  1. Connect to your vCenter Server or a standalone ESXi host using the vSphere Web Client;
  2. Find the virtual machine and open its settings (action , edit settings, edit vmware vm settings
  3. Find the virtual disk you want to extend. In this example, the VM has only one hard disk 1 With a size of 40 GB. Specify the new disk size in this field and save the settings. Note that the maximum disk size available for this type of datastore (VMFS, NFS, vSAN) is specified in Maximum size Field; Extend Virtual Hard Disk in VMware ESXi

You can also use VMware PowerCLI module cmdlets to increase the virtual machine VMDK disk size. Install the PowerCLI module on your computer (you can also install the PowerShell module on a Linux host) and connect to your vCenter/ESXi:

Connect-VIServer hostname

Run the following command to expand the virtual disk:

Get-HardDisk VMTest1 | where {$_.Name -eq "hard disk 1"} | Set-HardDisk -CapacityGB 50 -ResizeGuestPartition -Confirm:$false

PowerShell: Extend Virtual Disk Size in VMware

then you can use invoke-vmscript Cmdlet to extend partition in guest operating system:

Invoke-VMScript -VM VMTest1 -ScriptText "echo select vol c > c:\diskpart.txt && echo extend >> c:\diskpart.txt && diskpart.exe /s c:\diskpart.txt" -GuestUser $guestUser -GuestPassword $guestPass -ScriptType BAT

Don’t forget to end the PowerShell management session once you’re done:

Disconnect-VIserver -Confirm:$false

Now that you have increased the virtual disk size in VMware console, you need to expand the partition in the guest OS

Extend partition in Windows virtual machine

You must start the Disk Management console (Computer Management -> Storage -> Disk Management) and run rescan disc command for the guest Windows OS to view additional locations.

Rescan the Disk in Windows

Next, select the partition you want to extend and click turn up the volume, Extend System Volume in Windows

Specify how many MB of Unallocated space you want to add to the selected Windows partition (in the Select the amount of space in MB,

set new volume size in windows

Now click Next -> Finish and check whether your C drive has been extended successfully or not.
Check new system drive size

When expanding the system partition (C:\ drive), you may find that it is followed by the Windows Recovery Environment partition instead of Unallocated space. In this case, the Extend Volume option will not be available in Disk Manager (greyed out). Extend Volume in Windows Disk Management

In that case, you won’t be able to expand your C: drive unless you delete or move the recovery partition to the end of the drive. We described this process in the article Extend Volume option is grayed out in Windows.

Windows XP and Windows Server 2003 systems do not support online expansion of the C: volume. you can use del ExtPart Tool to extend system partition without rebooting.

To extend system partition in Windows 2003/XP, copy the tool to the guest operating system and run it with the following parameters:

extpart.exe c: 1020

Where? C: is the name of the volume you want to extend, and 1020 is the size (in MB) by which you want to extend the disk.

extpart.exe tool

You can also increase the offline VM disk partition in other ways:

  • Boot your virtual machine from any LiveCD (for example, GParted), and increase the partition;
  • Connect the virtual VMDK file to another VM and expand the partition on that machine;
  • Use the VMware vCenter Converter Tool to reconfigure the volume size.

How to increase partition in Linux virtual machine?

Now let’s see how to extend the disk partition if the Linux family guest operating system is installed in your virtual machine.

The first thing to do is make sure Linux sees the new disk size. To start Rescan, run the command:

$ echo 1>/sys/class/block/sdd/device/rescan

Use the cfdisk tool to display the available virtual hard disk space:

$ sudo cfdisk

This example shows that the /dev/sda drive has 2 GB of free space. Select the partition you want to extend (which is /dev/sda3 in this example) and chose Shape from the bottom menu.

cfdisk - check free space

then press Write To apply the change to the partition.

extend partition

In my case, I need to extend partition in Ubuntu 22.04 LTS virtual machine. By default, this version of Ubuntu is installed on an LVM volume:

$ sudo lsblk

lsblk shows LVM volumes

Before you can extend an LVM volume, you must extend a Physical Volume (PV):

$ sudo pvresize /dev/sda3

Once this is done, you can extend the logical volume (we’ll use all the free space available):

$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

Extend LVM on Ubuntu VM

The next step is expanding the file system:

$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Check free disk space in Linux:

$ df -h

check partio size in ubuntu

If you don’t have an LVM volume, you can use the parted tool to mount a partition in Linux:

$ sudo parted

Let’s see how much free space you have on disk:

print free

as you can see, Free Space = 2149 MB

parted - check free space

to extend /dev/sda3 split, run:

resizepart 3

Specify a new partition size (in this example, we need to specify Ending size from free space block):

Ending? [21.5GB], 23.6G

Extend parted Linux partition

Then exit parted:

quit

Only an ext4/3/2 filesystem remains to be developed.

$ sudo resize2fs /dev/sda3

This article describes how to increase the virtual hard disk size in a VMware vSphere environment with Windows and Linux guest operating systems. In a separate article, we have described how to reduce (shrink) the size of a virtual hard disk on VMware.

Leave a Comment