当我删除.vagrant文​​件时,如何销毁虚拟机?

问题描述:

我删除了包含.vagrant文​​件的目录。当我启动一台新VM时,它抱怨端口正在使用中。那么如何销毁虚拟机而不需要.vagrant文​​件呢?当我删除.vagrant文​​件时,如何销毁虚拟机?

+0

共享问题是一个问题的一半:完全相同的愚蠢问题,立即解决了感谢SO再次...... – 2017-05-01 21:37:30

以下VirtualBox命令可能会有所帮助。如果poweroff不起作用,请尝试unregistervm。

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

来源: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脚本停止所有正在运行的虚拟机:

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

这些命令肯定会破坏虚拟机。但是他们仍然为机器留下了“流浪的全球地位”的条目。 – 2014-11-03 14:51:01

+35

@ValkoSipuli尝试'vagrant global-status --prune'。参见http://*.com/a/24446866/300836 – 2014-12-28 10:54:26

+1

就我而言,我使用了一个小小的变化:'VBoxManage list vms; VBoxManage discardstate ; VBoxManage unregistervm ' – N13 2015-01-18 14:56:13

最容易做的是刚刚推出的VirtualBox的GUI客户端和删除(可能关停后的事)虚拟机。您可以右键单击虚拟机并执行这些操作。

enter image description here

+4

如果你已经ssh进入你的开发盒或者只能从命令行工作,那么不行。此外,如果你'别名killvms =“VBoxManage列表runningVms | awk'{print \ $ 2;}'| xargs -I vmid VBoxManage controlvm vmid poweroff”'你只需要键入killvms而不是启动并等待GUI。 – Pickels 2013-04-01 17:03:25

+0

我通常假设开发人员在本地机器上使用Vagrant,并且仍然在后台运行GUI :) – Gerry 2013-04-01 17:40:56

+2

您的假设是错误的!但是,既然你住得如此接近我,我会让这一张幻灯片。 Hihi,只是在开玩笑,对于那些在当地流浪的人来说,这仍然是一个很好的答案。 – Pickels 2013-04-01 18:30:17

如果您删除使用VM的GUI和你仍然得到错误,可以尝试从“%USERPROFILE%\ VirtualBox的虚拟机”删除指定的虚拟机。这为我工作

以下bash函数将poweroff和销毁相关的所有虚拟机的当前用户的所有文件:

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 
} 

它添加到您~/.bash_aliases并通过killvms调用它在你的shell。

+1

救了我一天的感谢 – Kingalione 2018-01-22 09:17:28