Saturday, 12 September 2015

Convert a VMDK from Thick to Thin on ESX




Convert a VMDK from Thick to Thin on ESX

This article gives the steps to convert a thick provisioned virtual hard drive VMDK to thin provisioned on ESX 4 or newer versions.

One method you have is an option to Migrate (say vMotion) the VM Guest to another datastore and change the advanced configuration of the hard drive to thin provisioned or If you can't vMotion or migrate the VM to another datastore you can use this vmkfstool command from the VM host to convert it.

Optional steps to check:

  1. Login to the VM Guest
  2. Make sure the VMTools are updated
  3. Run an OS Defrag of the drives
  4. Use Microsoft SDelete 
    1. http://technet.microsoft.com/en-us/sysinternals/bb897443
    2. Download and install on the VM Guest OS
    3. Run sdelete -c
If Powered On VM

  1. Power Off the VM Guest
  2. Login to the VM Host that has the VM Guest either by Power CLI or SSH
    1. You may need to enable SSH and ESX Shell to do this
  3. Browse to the VM Guest file location
    1. Example: cd /vmfs/volumes/mydatastore/vmname/
  4. Clone original disk to a thin copy
    1. vmkfstools -i SERVERNAME.vmdk -d thin thin-SERVERNAME.vmdk
  5. Rename the original disk
    1. vmkfstools -E SERVERNAME.vmdk orig-SERVERNAME.vmdk
  6. Rename the thin disk to the original disk name
    1. vmkfstools -E thin-SERVERNAME.vmdk SERVERNAME.vmdk
  7. Remove VM Guest from VM Host inventory
  8. Add the VM Guest back to the VM Host inventory
    1. This so the VM Host registers that it's now a thin provisioned disk/s
    2. This may not be needed for vSphere 5
  9. Verify that the VM Guest boots and runs correctly
  10. Remove original Thick disk/s
    1. vmkfstools -U orig-SERVERNAME.vmdk

Reference Sources;
http://communities.vmware.com/thread/296983

Note: In Lab Manager 4 undeploy the VM Guest first. The VM Guest does not need to be removed and re-added because undeploying and deploying essentially does that.



Increasing a VMDK file size using VMKFStools



Increasing a VMDK file size using VMKFS tools

This article provides the steps to extend a Vmware VMDK virtual disk file from command-line with the Vmware utility vmkfstools.
Steps to Follow:
  1. Power Off the VM Guest
  2. Undeploy the VM Guest if in Lab Manager
  3. Remove any snapshots
  4. Consolidate if a template in Lab Manager
  5. Login to the VM Host Console
  6. Change directories to the appropriate path to the VM Guest
    1. Example: cd /vmfs/volumes/<datastore>/<vm guest>
  7. Optionally create a backup of the VM disk
    1. Example: vmkfstools -i <vmname>.vmdk -d thin backup-<vmname>.vmdk
  8. Extend the disk size
    1. Do Not run the command on the file name with flat. Run it against the smaller meta file that just ends in vmdk.
    2. Example: vmkfstools -X 60G <vmname>.vmdk
    3. The new size will be 60 GB
  9. Deploy the VM Guest if in Lab Manager
  10. Power On the VM Guest
  11. Use a partition management utility if older than Windows Vista/2008 to extend the partition with the new unallocated space in the OS.
  12. Remove backup VMDK when satisfied that it was successful.
  13. Done

Reerence sources:
http://communities.vmware.com/docs/DOC-2459

Note: If you consolidate a VM guest in Lab Manager it will convert the VMDK files to thick.  So at the end of this process you may want to follow the steps to convert it back to thin which will update soon.

Friday, 11 September 2015

Recover Orphaned Virtual Machines



Virtual machines appear in the vSphere inventory listed as orphaned appended to their name.
Virtual machines that reside on an ESXi host managed by vCenter Server might become orphaned in rare cases. Such virtual machines exist in the vCenter Server database, but the ESXi host no longer recognizes them.
Virtual machines can become orphaned if a host failover is unsuccessful, or when the virtual machine is unregistered directly on the host. If this situation occurs, move the orphaned virtual machine to another host in the datacenter that has access to the datastore on which the virtual machine files are stored.
1
In the vSphere inventory list, right-click the virtual machine and select Migrate.
2
Click Change Host and click Next.
3
Select the host on which to place the virtual machine.
If no hosts are available, add a host that can access the datastore on which the virtual machine's files are stored.
4
Click Finish to save your changes.
The virtual machine is connected to the new host and appears in the inventory list.