Sunday, April 21, 2013

Compact the Virtual Disk in VMware Workstation

My previous post was about how you can defragment your virtual disk in VMWare. Though I already mentioned there that you cannot reclaim your virtual hard disk's  unused space on a virtual disk, it is best practice to run a disk defragmentation before compacting the disk.

What really happens if you compact the virtual Disk?

If you have a virtual disk that grows as data is added, you can shrink it as describes in this post. Note that if you have allocated all the space for you virtual disk at the time you created it, you cannot shrink it. In my case, I am running a fedora 14 virtual machine (VMWare workstation 7.1.4) which has oracle 11g installed in it. As I create databases and maintain them, the disk size grows fast and ultimately I had to perform some tasks to come out of the disk full issue by following some actions. 

When you delete files from your virtual machine, the disk space occupied by those files is not immediately returned to your host system. If a virtual disk has such empty space, you can use the Clean up disks command to return that space to the hard drive on a Microsoft Windows host.

The Clean up disks command is similar to the Compact command in the Workstation virtual machine settings and the shrink command provided by VMware Tools. 

If you want to know how to Defragment the virtual hard disk in VMWare, refer the post under Defragmenting the virtual Disk in VMWare because it is best [raactice to defragment your virtula hard disk before you compact or shrink it

Before shrinking the virtual disk, consider the following restrictions and requirements

  • Shrinking requires free disk space on the host equal to the size of the virtual disk you are shrinking.
  • Shrinking applies only to virtual disks. You cannot shrink physical disks or CD-ROMs.
  • You cannot shrink the virtual disk if,
    •  you have already created Snapshots of your virtual machine
    • If your VM is a parent of a linked clone 
    • If your VM is a linked clone (because linked clone depends on its parent clone
Note that there are two types of clones that you can create using a Virtual machine. They are Full clones and Linked Clones. For the moment, remember that Full clone is similar to a Copy of a file that you create in any Operating system and  a Linked clone is like a shortcut that you create for a file. Shortcuts are always dependent on the actual file whereas copies of files can work independently. I'll explain these concepts in some other post but keep in mind you have to consider the above points before performing a Shrinking of disk.

Steps to Shrink a virtual hard disk

Please note that I run  my virtual machine in VMWare Workstation 7.1.4 in which the Shrink task is refers as Compact. follow the below steps to perform the task

  1. Power off the virtual machine if it is already running
  2. select the proper tab of your virtual machine from the VMWare Home screen
  3. Select VM tab from the top and select Settings
  4. Under Hardware tab, click on Hard Disk (SCSI) and select Compact from the Utilities drop down list.
  5. The disk compact starts automatically and displays a success message if it completes

It would take some time to complete the disk compact task. When it completes, it will display a success message.