Sunday, November 16, 2008

Shrinking the Capacity of a VMware Virtual Disk

I've being using my VMware images with virtual disks that allocate the space as needed, e.g. growable disks. VMware says that if you allocate the full capacity of the virtual disk, you will enhance the performance of your virtual machine. Since I have lots of space on my HD, I decided to convert my virtual disks from growable to preallocated type to enhance virtual machine performance. To do that, you just need to use the vmware-vdiskmanager.exe tool, for example:
vmware-vdiskmanager -r old_disk.vmdk -t 2 new_disk.vmdk
It is pretty simple, but I also want to reduce the virtual disk capacity at the same time. The original capacity was 40 GiB, and I would like to reduce it to 28 GiB. It turns out that this is not something you can do with a simple command line. I thought I could just add the -s option to the command above, but this option is not valid with the convert option (-r), only when creating a new virtual disk.

I thought about using the shrink option (-k), but this option is not to shrink the virtual disk capacity, it is only for reducing the size of the vmdk file itself that was created with the growable option. The virtual disk capacity stays the same. If you actually want to reduce the capacity of your virtual disk, then you will need to:
  • Create a new virtual disk with the desirable capacity. You can do this by either using VMware Server or Workstation GUI or using the vmware-vdiskmanager tool. For example, in my case:
      vmware-vdiskmanager -c -t 2 -s 28GB -a ide new_disk.vmdk
  • Add your new virtual disk to your virtual machine. In VMware Server, you click on Virtual Machine Settings, select Hard Disk, and then click on Add.
  • Shrink the logical partition of your existing virtual disk to fit on the new virtual disk. You can use GParted for this as described here.
  • Copy your logical partition from the original to the new virtual disk. You can also use GParted for this as described here. If you are copying a boot partition, then it will require you an additional step. After you copied the logical partition to the new disk, you will need to add the boot flag to it. To do that, just right click on the partition, select Manage Flags, then check the boot option as shown below.
Although shrinking the capacity of a virtual disk involves lots of work, to expand the capacity is way simpler. You just need to use the expand option (-x) of the vmware-vdiskmanager tool, and it will add extra non formatted space to your virtual disk.

No comments:

Spring Boot Configuration Properties Localization

Spring Boot allows to externalize application configuration by using properties files or YAML files. Spring Profiles  provide a way to segr...