63

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
  • A problem shared is a problem halved: Did exactly the same dumb problem, immediately resolved thanks to SO once again...
    – Benjamin R
    May 1, 2017 at 21:37

4 Answers 4

98

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
4
  • 4
    These commands certainly destroy the VM. But they still leave an entry for the machine in "vagrant global-status".
    – Make Mark
    Nov 3, 2014 at 14:51
  • 38
    @ValkoSipuli Try vagrant global-status --prune. See stackoverflow.com/a/24446866/300836 Dec 28, 2014 at 10:54
  • 1
    In my case, I used a slight variation: VBoxManage list vms; VBoxManage discardstate <uuid>; VBoxManage unregistervm <uuid>
    – nshew13
    Jan 18, 2015 at 14:56
  • 4
    Use vboxmanage unregistervm --delete to physically delete the VM like with vagrant destroy
    – ens
    Nov 8, 2016 at 16:35
31

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

3
  • 4
    Not if you are ssh'd into your dev box or only work from the command line. Also if you alias killvms="VBoxManage list runningvms | awk '{print \$2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff" you only need to type killvms instead of launching and waiting for the GUI.
    – Pickels
    Apr 1, 2013 at 17:03
  • I assume typically developers work with Vagrant on their local machine and still run a GUI somewhere in the background :)
    – Gerry
    Apr 1, 2013 at 17:40
  • 2
    Your assumption was wrong! But since you live so close to me I'll let this one slide. Hihi, just kidding it's still a good answer for people running vagrant locally.
    – Pickels
    Apr 1, 2013 at 18:30
7

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.

0
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.