How to shrink size of a vmdk file in ESXi 5.0?




Scenario

When we try to reduce or shrink the size of an existing vmdk file, the operation fails.

Resolution  

There is no option to reduce the size using vSphere client. For this you may need to use putty or cli. Please remember to delete unwanted data from the OS and to shrink the partition internally using the diskmgmt.msc tool. After shrinking , perform the below:
  •  Login to the ESXi using putty
  • Browse to the vmdk location (eg: cd vmfs/volumes/datastore1/VMname)
  • Take a backup of the existing vmname.vmdk and vmname-flat.vmdk files using the cp command in linux (cp filename backup_filename)
  •  Open the vmdk file using vi editor
    • vi vmname.vmdk
  • Modify the value corresponding to RW to the required disk space. If you need to shrink the file to xGB, use the value : x*1024*1024*2.  For eg: if you want to shrink the disk to 25GB, give the value 25*1024*1024*2= 52428800 
  • Once finished save the file and use vmkfstools command to clone a disk using the new settings.



    • vmkfstools -i vmname.vmdk vmname-new.vmdk
  • Remove the old vmdk files
    • rm vmname.vmdk  rm vmname-flat.vmdk
  • Once removed, again use the vmkfstools to clone vmdk files of the same old name.
    • vmkfstools -i vmname-new.vmdk vmname.vmdk
  • Using vi client , remove the hard disk from virtual machine and add again.






Comments

  1. sorry but how can you clone after removal? or didnt i get it?

    ReplyDelete
  2. The clone is taken of the newly created vmdk file

    ReplyDelete
  3. There is a mistake in the following step:

    Remove the old vmdk files

    rm vmname.vmdk rm vmname-new.vmdk

    It should be:

    Remove the old vmdk files

    rm vmname.vmdk rm vmname-flat.vmdk


    the steps mentioned in the jpg are fine, though.

    ReplyDelete

Post a Comment

Popular posts from this blog

VMware and Windows Interview Questions: Part 2

VMware and Windows Interview Questions: Part 3

VMware vMotion error at 14%