Growing, thinning, and shrinking virtual disks in ESXi
search cancel

Growing, thinning, and shrinking virtual disks in ESXi

book

Article ID: 341657

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides information on resizing of virtual disk files. You may find yourself in a situation where you need to either:
  • Expand a virtual disk to store more data
  • Thin an existing large virtual disk so it consumes less datastore space, without actually shrinking the virtual disk
  • Shrink a virtual disk, if it is too large
  • Decrease the size of a virtual disk

Resolution

Currently, three major operations are supported by VMware Converter:

  • Expanding
  • Thinning
  • Shrinking
 
Warning: An effective backup strategy should always be used before performing permanent changes to existing virtual disks.
  • Cloning, importing, and converting virtual disks should leave the source files unmodified.
  • In addition to the cloning, importing, and converting of a virtual disk, related source-disk snapshot files will be committed to the destination disk when cloning, importing, or converting. However, the original virtual disk and associated snapshots remains unmodified in the original directory.
  • Do not alter the base disk in any way without committing all snapshots first or they will be invalidated.
  • Changes cannot be made to a disk in use or locked.
  • Use VMware Converter, as it streamlines and simplifies the process, further, eliminating some areas where user error can occur.

    Note: When using the VMware Converter wizard, you can perform operations on running virtual machines by treating them as physical machines. For more information, see the vCenter Converter Standalone Documentation .
 
Expanding Virtual Disk
  • Select a VM in the inventory and make sure VM doesn't have a snapshot
  • SSH into ESXi server
  • change the Directory to Virtual Machine directory
Example: cd /vmfs/volumes/VM-DIRECTORY/VIRTUAL-MACHINE
  • Virtual disks can be expanded using this ESXi command:
           vmkfstools -X <new size> <virtual disk>.vmdk

           For example, use this command to grow the virtual disk to 25GB in size:

           vmkfstools -X 25g /vmfs/volumes/xxxx/vmname/vmname.vmdk
 
  • Changes are made to the disk and are almost instant
  • Partitions residing within the virtual disks will not resize and there will be unallocated space at the end of the disk. Third-party partitioning tools are required at this point to resize the primary partition to take advantage of the additional space
  • VMware Converter allows you to specify a new disk size in its conversion wizard. It will also take care of partition resizing for you.

    Notes:
    • For more information about VMware Converter, see the vCenter Converter Standalone Documentation for VMware product version.
    • Some virtual machine guest operating systems may require a reboot to detect changes to the size of the virtual disks.
       
Thinning
  • Virtual disks can be thinned so they consume only as much space as there is data residing in the .vmdk.
  • Thinning is currently possible using VMware Converter and hosted products, such as VMware Workstation. For more information, see the vCenter Converter Standalone Documentation for your VMware product version.
  • In the event that a thinned virtual disk continues to use more space than the operating system residing within it reports, old data in the volume still needs to be zeroed or removed.
  • Deletion of files in most file systems will not completely remove them; merely file tables will be altered. Use of freeware secure file deletion utilities are useful, such as Eraser or SDelete to zero out the space to 'zero' the free space on the volume, effectively clearing the free space of data. It is then, that the disk can be properly thinned. You can then use the vmkfstools -K command (ESXi/ESX 4.1 and later) to complete the block reclaim or use Storage vMotion to migrate the virtual machine to a datastore with different VMFS block size.

    For process limitations and details, see Storage vMotion to thin disk does not reclaim null blocks.

Shrinking
  • Virtual disk shrinking is supported when using VMware Converter converting source virtual machine as a machine source (not as virtual to virtual).
    Note: You cannot shrink virtual disks using vmkfstools in ESXi as the hypervisor is not aware of the file system layout and cannot ensure a safe shrink operation.
Before shrinking
  • Migrate the data away from the end of the disk consume to ensure the data is not lost (because the disk area is effectively removed). For example, in Windows GuestOS use Disk Management tool.
  • Shrink the partition residing within a disk before reducing the size of a virtual disk.
  • Non operating system disks users can also add a new smaller VMDK to the virtual machine and copy the data between the larger and new smaller disk using tools within the guest such as Robocopy.
 

Additional Information