VSphere 4 – how can I cancel a file copy in progress

vmware-vsphere

VMware vSphere 4
SAN storage with multiple data-stores
No vCenter

I shut-down a virtual machine and using the data-store browser did a copy/paste to copy the VM to a new datastore with additional space. The file copy performance was very poor, and due to time constraints I decided to cancel the copy task. However the copy task showing in the vsphere client can not be cancelled; the cancel option is disabled.

Currently I am not able to start the machine in it's original location as the disk files are locked for the copy. How can I abort the copy? I tried deleting the target directory but this did not abort the copy task.

Best Answer

The answer depends on the version of vSphere you've got.

Step 1:First make sure you disable the automatic restart of VM's.

enter image description here

Step 2: enable the SSH console

From: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=8375637

To create a user in ESX host for using a SSH client:

Log in to the vSphere Client as a root user.
Click Users & Groups.
Right-click on a blank area and click Add.
Enter a username and password. Confirm your password.

Note: Starting in ESX 4.0, the password needs to be at least 
8 characters in length.

Select Grant shell access to this user and click OK.

Step 3: log into ssh
Download putty from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Step 3a (ESX only) Restart the VM client daemon

service mgmt-vmware restart

Step 3b (Esxi only) Restart the VM client daemon

/etc/init.d/hostd restart

Step 4 Wait for the vSphere client to reconnect
All of your VM's will still be running as before, only the vSphere app will restart.
With it the copy process will stop.

Bonus: a better way to copy

If you have thinly provisioned client, you can use the command-line tool vmkfstools like so:

vmkfstools -i /vmfs/volumes/path_to_datastore/path_to_source_vm/vmname.vmdk /vmfs/volumes/path_to_dest_datastore/path_to_dest_vm/vmname.vmdk -d thin &

This will clone (-i) the vmdk file and make sure the destination file is thinly (-d thin) provisioned. The & at the end of the command will make sure you get your command prompt back.

It will copy much faster than the GUI copy does, and you can cancel it easier.

canceling a vmkfstools copy

ps |grep vmkfstools Note down the PID. kill 12345
Where 12345 is the first number listed on the vmkfstools line.