How do I destroy a VM when I deleted the .vagrant

2019-03-07 22:07发布

问题:

I deleted the directory that contained the .vagrant file. When I up a new VM it's complaining about ports being in use. So how do I destroy a VM without having it's .vagrant file?

回答1:

The following VirtualBox commands might help. If poweroff doesn't work, try unregistervm.

$ VBoxManage list runningvms
$ VBoxManage controlvm <uuid> poweroff
$ VBoxManage unregistervm <uuid>

Source: https://support.cloud.engineyard.com/entries/21449637-I-deleted-Vagrantfile-vagrant-and-or-the-app-directory-before-halting-the-VM-Now-ey-local-up-errors-

Shell script to stop all running vms:

VBoxManage list runningvms | awk '{print $2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff


回答2:

Easiest thing to do is just launch the GUI client of VirtualBox and remove (possibly after shutting down) the virtual machine. You can just right click the virtual machine and perform these actions.



回答3:

The following bash function would poweroff and destroy all files related to all VMs for the current user:

function killvms() {
  VBoxManage list runningvms | awk '{print $2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff
  VBoxManage list vms | awk '{print $2;}' | xargs -I vmid VBoxManage unregistervm --delete vmid
}

Add it to your ~/.bash_aliases and call it in your shell via killvms.



回答4:

If you removed the VM using the GUI and you're still getting the error, you may try to delete the named VM from "%userprofile%\VirtualBox VMs". This worked for me