removing locked vmdk file

we are trying to remove a file from the datastore.
it is no longer in use and not needed.

the error message for 'rm filename.vmdk' is:
rm: cannot remove 'filename.vmdk': Device or resource busy

anyway to determine the process holding this file?

thank you.

ESXi host ver is 4.0
Who is Participating?
hi Ray,

did you try to restart the vmware management services on the ESXi machines, as there is a likely possibility that there might be a VI client task that might have locked the vmdks

"service mgmt-vmware restart " yeah i know this is a basic one, but still do this on both the ESXi servers.

Next :

did you verify if there is any linked clone or anything else.

confirm if there is any vmx file in both the folder locations and query if there is any active process for that vmx file on the esxi console.

refer to this vmware kb article.

As root, run
fuser -k /path-to-filename.vmdk
  to kill the process that lock that vmdk file.

fuser -u /path-to-filename.vmdk
  show which user and pid access that vmdk file.
rastafarayAuthor Commented:
i dont think fuser is installed on ESXi
"-ash: fuser: not found"

any suggestions?
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

This is ESXi after all,  so no,  fuser does not work.   But a VMDK file should not be locked against a Virtual machine is actually running that has this file attached, either as a base disk, or a file referred by a base disk  or VMDK descriptor file.
In fact, the lock should timeout.

Anyways, you haven't shown enough information about the filename to determine if we're talking about a  VM's  descriptor file  (virtual machine name).vmdk,       a flat file with actual data   (vmname)-flat.vmdk,  or a delta file such as  (vmame)-1_1.vmdk

So my question is:   Is this SHARED storage or local storage?
If this is local storage,  matters should be pretty easy,  and you can use vmkfstools  to break the lock, potentially,  although you should try rebooting the host before resorting to such extreme measures.

There are some ways to potentially break the lock and manipulate the file anyways,
but they are quite dangerous, and may lead to an outage if you are actually in error
in your belief the file is unused..

If this is local storage...  I would suggest you go to each powered on virtual machine..
Click Edit settings
look at each hard disk, and verify your particular file is not referred, nor any filename like it.

Of course this is also not absolutely foolproof.
But chances are very good  the file you "think is not being used",  is actually being used.

Unless your VMFS volume has some damage to it as a result of unclean shutdowns...

What's the process name for ESXi?
Or can you temporarily stop ESXi software and remove that vmdk file?
rastafarayAuthor Commented:
hi Mysidia,

looks like i missed a lot of the details.

the file is named "(vmnameX)-flat.vmdk" in one datastore:

and the same exists in another datastore:

i have already deleted the VM (vmnameX), so vmnameX no longer exists in vCenter.  but the above mentioned files are still there.

so the options are to wait or to force delete these files using vmkfstools.  host reboot is not an option at this time due to production environment.

the storage is shared (i assume) on a SAN via iSCSI.

does this help?
Try to restar managment services
and than delete the locked file
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
try lsof and see if it is in use.
I would suggest following the steps in VMware KB 10051

* SSH to the ESX(i) host.

* use the vmkfstools -D command to find which host is locking the file

vmkfstools -D /vmfs/volumes/<UUID>/<VMDIR>/filename.vmdk

You should get the MAC address of the machine locking the file

either displayed on screen, or you may need to tail  /var/log/vmkernel
or /var/log/messages
on versions of ESX before 4.1

* Identify which ESX host has the MAC address that is locking the file.

* SSH to that host

run  the command

lsof | grep  NAME-OF-LOCKED-FILE

to find the PID of the process   locking the file

* Attempt to find a world ID of the process
vm-support -x

* KILL the monitor/VM process for that world

vm-support -X (world id)


rastafarayAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.