Thursday, August 16, 2012

Unable to delete VMDKs in VMware (vSphere)

I have been trying to P2V a Win 7 desktop and had to make another attempt when it produced an error at 14% completion where the VMW KB workaround suggests to P2V a single volume at a time. The desktop in question has 3 virtual disks plus the Win 7 boot partition so on my next attempt, I went to P2V just the FAT32 boot partition and C:\ when I discovered that the LUN I created on the SAN shows insufficient space...WTF. I launch vSphere client and double check that I deleted the VM that was created during the previous P2V attempt and it was indeed gone. Suspicious, I check the volume to find that there remains 2 VMDKs from the previous P2V attempt that vSphere did not successfully delete nor did it spit out an error about it either. I right click one of the disks and select delete just to get an error that simply states: Cannot delete file....super. Typically an error like this is seen where a VM has locked the volume but there is no VM to speak of so the typical method to unlock a volume will not work here.

Meh.


The way to remove the locked volume where a VM does not exist is through shell and if you haven't poked around on the ESX shell or are unfamiliar with Linux, this may seem like a daunting task but I promise you that it is not. First if you have not already, enable remote shell access to your ESX or ESXi host and once that is established, use a program such as Putty to remotely connect to your target host. If you are running your hosts off of a SAN like myself, it honestly does not matter which host you access so long as that host has access to the SAN volume in question where the VMDKs are located. Once connected via putty, run the following command to figure out where the volume exists;

[root@yourhost ~]# lsof | grep name_of_vmdk.vmdk

The above command will reveal the path of the vmdk assuming that it does exist, the output should look something like this;

vix-async 8586 root 136u REG 0,18 319959334912 377047
/vmfs/volumes/915udud0-6b77a6b7-05a-992ba5sest69/name_of_vmdk.vmdk

Notice the 4 digit number in the above output after vix-async which is the ID number you will use to terminate it's running processes with the following command;

[root@yourhost ~]# kill -9 8586

With all processes pertaining to the ID terminated, we will change the working directory to where the VMDK is for simplicity's sake;

[root@yourhost ~]# cd /vmfs/volumes/915udud0-6b77a6b7-05a-992ba5sest69/

Once there you will delete the VMDK and you will be asked to confirm deletion as a redundancy check to ensure that the deletion is intended by typing Y or N;

[root@name_of_directory ~]# rm name_of_vmdk.vmdk
rm: remove regular file name_of_vmdk.vmdk? y


That should have removed the locked VMDK and have freed up space on your volume.

No comments:

Post a Comment