rwar
Contributor
Contributor

best way to delete VMs from ESX3.5

Jump to solution

I use HP SIM to work with some ESX hosts (3.5, 3i). It is common to create some logical servers (kind of VM) and need to delete them from time to time because they become useless for some reasons. These logical servers does not appear in VI Client when they are power off for some reason, but the space configured for them is using space that I could use to create other VMs, for example.

What is the better way to delete them? Go straight to ESX console, look for the volumes created and delete them manualy? Or there is a tool for that?

0 Kudos
1 Solution

Accepted Solutions
fusebox
Enthusiast
Enthusiast

The best way to delete the VMs and files related to it on the disk is first to make sure that the VM is shutdown cleanly,then unregistered from the the ESX host,then making sure that the vmdk files of that VM are not being accessed/locked by any stale/hung PID,then remove those files either using the datastore browser or via the rm -f command from the service console logged in as the root.Half the time, in my experience you will have file locking issues when trying to delete those files.

View solution in original post

0 Kudos
8 Replies
Troy_Clavell
Immortal
Immortal

if your positive these VM's and their files are no longer needed you can delete them by browing the datastore, finding the folder they are in and deleting the contents. Also, you could use WinSCP and browse the datastore as well, find the VM folder in question and delete it that way.

hope this helps.

bradley4681
Expert
Expert

In the new VI Clint you can browse the datastore and delete files and folders much easier then in past versions. You can also upload and move files around using the client. I think its a much safer, and secure why to access the datastores then using the console. Also if a file is locked or in use it "usually" will not allow you to remove it.

Cheers,

Bradley Sessions

If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

Cheers! If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Mazzer
Contributor
Contributor

Hi,

Maybe people delete VM but dont select to remove from disk.

In this case, u can use the Browse Datastore in Sumary tab of VI Client, or acess /vmfs/volumes from shell.

Use VI Client is easyer.

Att,

0 Kudos
fusebox
Enthusiast
Enthusiast

The best way to delete the VMs and files related to it on the disk is first to make sure that the VM is shutdown cleanly,then unregistered from the the ESX host,then making sure that the vmdk files of that VM are not being accessed/locked by any stale/hung PID,then remove those files either using the datastore browser or via the rm -f command from the service console logged in as the root.Half the time, in my experience you will have file locking issues when trying to delete those files.

View solution in original post

0 Kudos
williamarrata
Expert
Expert

You can also VC to the HOST and power off the VM, Right click on the VM and click on the "Delete from Disk". Now you can browse your datastore and it won't be there.

Hope that helped. Smiley Happy

Hope that helped. 🙂
0 Kudos
rwar
Contributor
Contributor

Could you tell how should I proceed to make sure that the vmdk files are not being accessed/locked by any stale/hung PID? And the rm -f command delete VM dependencies (I believe that in some way are created some ones)?

0 Kudos
fusebox
Enthusiast
Enthusiast

Follow the steps below to make sure there are no stale pids accessing the vmdk files of the vm in question:

1) Clean shutdown the VM

2) Browse the datastore and delete the corresponding files (or) use the ,"Delete from disk" option from the VC (or) rm -f command from the service console

3) If the above step happens smoothly without any errors,then you are good to go. If not,proceed to next step 4

4) login to the SC as root

5) vm-support -x ---> This should give you the list of the VM(s) and their vmid(s) currently running/in use. You shouldnt ideally see the VM which you deleted from the VC (incase of clean removal) .But,in this case you will see.

6) cat /proc/vmware/vm/*/names |grep vmname where vmname is the vm that is hung ---> Note down the,"vmid" value from the output given by this command

7) less /proc/vmware/vm/<vmid>/cpu/status where "vmid" is the number in step 6

😎 Locate the field "group" that shows vm.#### where the #### numbers after vm. will be the master user world id. Record the value for "group" vm.####

9) /usr/lib/vmware/bin/vmkload_app -k 9 #### (where #### is the master user world id found in the previous step)

10) If the above command is successful, then you should get a message saying that ,"sending termination signal 9 being sent to that world.id or pid.

11) Now try deleting the vmdk files using the *.vmdk and it should be successful without any errors.

The reason why this is happening may be due to the way VC operates. I think it locks up the vmdk files in its cache and which gives an impression to the esx host that files are in use or being accessed and reports an error while trying to delete. I have faced this issue lot of times and at times the above procedure also doesnt work,as sometimes there is no world.id and which makes it impossible to kill the hung file handle /pid which is accessing the vmdk(s). What I found from the KB, is that in such worst case scenarios,rebooting the VC /esx host helps.. In my view ,this should be used as last resort as its not a workaround,but a dumb reboot to fix on stale file handle issue. Maybe vmware has to come up with some solution for this issue once and for all. Hope this helped answer your question.

0 Kudos
rwar
Contributor
Contributor

For sure it is a great answer! I even have copied the step-by-step to a document that I have with some HOW TOs, i.e, that time we really don't know what to do when something breaks up... Smiley Wink

I don't know how the forum works, but answer like that should become some kind of help/how to document.

Thanks!

0 Kudos