Resizing a virtual disk with VMware

The other day, an old virtual machine of mine with VMware (that I sometimes used to test various configurations, cases, applications, etc.) ran out of disk space since it had only 2GB for storage! By today’s standards, 2GB of storage seems like a joke! But anyways, I had to solve this inconvenient problem or else I would lose time creating a new virtual machine and configuring the operating system from scratch according to the new specifications for virtual disks.

VMware provides a set of line-of-command utilities to support the administration of virtual machines. Among them is a utility called vmware-vdiskmanager that makes this operation much simpler. Simply run the command with the “-x” option and the desired new size for the virtual disk and…problem solved.

For example:

$ Vmware-vdiskmanager -x 5GB virtual_disk.vmdk

Well, the task seemed simple, but the “virtual disk manager” (a.k.a. vmware-vdiskmanager)refused to perform this operation, signalling that you cannot perform such an operation on disks that use or have used snapshots. The message appeared as follows:

This disk is part of a snapshot chain in ‘/var/lib/vmware/Virtual Machines/vm1/SO.vmx’.
The selected operation can only be executed on a disk with no snapshots.

A question came to me almost immediately: how we get rid of snapshots? A solution could be to reverse the snapshot(s), but this implies having to go back to an older state of the virtual machine. This is definitely not what you want. If the solution must maintain the current state of the virtual machine, then a simple way to solve this problem is to generate a new virtual disk from the snapshot desired.

This task is performed with the “-r” option of the vmware-vdiskmanager, which lets you convert a virtual disk to another type.

For example:

$ vmware-vdiskmanager -r origen.vmdk -t 0 destino.vmdk

Types of disks:

0: single file (expandable).
1: divides the virtual disk into 2GB pieces (expandable)
2: reserved physical space
3: similar to the Type 1 but with the physical space reserved.

In my case, I used Type 0 and it worked perfectly! No more snapshots!

The next step is to increase the size of the new virtual disk (which in this case corresponds to “destino.vmdk”).

$ vmware-vdiskmanager -x 5GB destino.vmdk

Now we have a new disk with 5GB and the only thing that remains to be done is to increase the size of the partition in the Guest Operating System so that they can make use of the space according to their needs. Problem solved!

Thanks to Marcelo Espinosa for inspiring this content.

Comments

  1. Simon Latore says

    There is a really simple method to do this now in vSphere, described here in detail:

    http://www.jjclements.co.uk/index.php/2009/09/14/vmware-esx-vsphere-resize-disk

  2. thank you!
    This benefits me!

  3. There is a way to combine the convert and resize command. Simply add ‘-s GB’ after the ‘-t 0’ parameter. This saves some time…

  4. Thanks for the tip :).

Speak Your Mind

*