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?
4 Answers
The following VirtualBox commands might help. If poweroff doesn't work, try unregistervm.
$ VBoxManage list runningvms
$ VBoxManage controlvm <uuid> poweroff
$ VBoxManage unregistervm <uuid>
Shell script to stop all running vms:
VBoxManage list runningvms | awk '{print $2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff
-
4These commands certainly destroy the VM. But they still leave an entry for the machine in "vagrant global-status". 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 -
1In my case, I used a slight variation:
VBoxManage list vms; VBoxManage discardstate <uuid>; VBoxManage unregistervm <uuid>
– nshew13Jan 18, 2015 at 14:56 -
4Use
vboxmanage unregistervm --delete
to physically delete the VM like withvagrant destroy
– ensNov 8, 2016 at 16:35
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.
-
4Not 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.– PickelsApr 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 :)– GerryApr 1, 2013 at 17:40
-
2Your 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.– PickelsApr 1, 2013 at 18:30
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
.
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