Virtual Kim

@Kim_Bottu … Virtually Gung Ho

Removing a locked file from a datastore

Recently I had to remove a locked file from a datastore on request of one of the administrators. No problem.

How to remove file

#Logon on your ESXi host using shell. Browse to the path where the file is located in the datastore. you need to move one file in MyVM called MyVM-Flat2.vmdk which is locked.

cd /vmfs/volumes/datastore/MyVM
rm MyVM-Flat2.vmdk -f

#The result is the following.

—> rm: can’t remove ‘MyVM-Flat2.vmdk’: Device or resource busy

You follow the procedure in the following article: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=10051 and you find the host which locks the VM

cd /vmfs/volumes/datastore/MyVM
vmkfstools -D MyVM-Flat2.vmdk

Lock [type 10c00001 offset 139745280 v 1721, hb offset 3276800
gen 811, mode 1, owner 5585f111-8c0ee12c-217d-106a4baaeaa mtime 286919
num 0 gblnum 0 gblgen 0 gblbrk 0]
Addr <4, 299, 51>, gen 1704, links 1, type reg, flags 0, uid 0, gid 0, mode 600
len 408072591360, nb 389169 tbz 363712, cow 0, newSinceEpoch 389169, zla 4304, bs 1048576

It is the host with a VMKNIC with MAC 106a4baaeaa

you reboot the host and try to remove the file again.

cd /vmfs/volumes/datastore/MyVM
rm MyVM-Flat2.vmdk -f
rm: can’t remove ‘MyVM-Flat2.vmdk’: Device or resource busy

you try to find again why that lock is still there

cd /vmfs/volumes/datastore/MyVM

vmkfstools -D MyVM-Flat2.vmdk

Lock [type 10c00001 offset 139745280 v 1721, hb offset 3276800
gen 811, mode 1, owner 5585f111-8c0ee12c-217d-106a4ba1ae mtime 286919
num 0 gblnum 0 gblgen 0 gblbrk 0]
Addr <4, 299, 51>, gen 1704, links 1, type reg, flags 0, uid 0, gid 0, mode 600
len 408072591360, nb 389169 tbz 363712, cow 0, newSinceEpoch 389169, zla 4304, bs 1048576

HEY! the lock was moved to another host.

So here is the solution:

Disable HA on the cluster
Put the host which holds the lock in Maintenance mode
DO NOT migrate Offline VMs

Try to remove the lock again and it will work.

NOTE: After a week or so I found a VM where that same vmdk was attached to. I still wonder why it did not show when I was looking for the lock. In any case…if the vmfs volume is not in use, you can follow my little procedure.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on July 3, 2015 by in ESXI, Locked files, Script, Storage and tagged , , , .
Follow Virtual Kim on WordPress.com

Blog Stats

  • 26,240 hits
%d bloggers like this: