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

Virtual MachineVagrant

Virtual Machine Problem Overview


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?

Virtual Machine Solutions


Solution 1 - Virtual Machine

> 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

Solution 2 - Virtual Machine

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.

enter image description here

Solution 3 - Virtual Machine

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.

Solution 4 - Virtual Machine

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPickelsView Question on Stackoverflow
Solution 1 - Virtual MachinePickelsView Answer on Stackoverflow
Solution 2 - Virtual MachineGerryView Answer on Stackoverflow
Solution 3 - Virtual MachinePowerKiKiView Answer on Stackoverflow
Solution 4 - Virtual MachineAmazingTurtleView Answer on Stackoverflow