Vagrant启动超时。

44

我在启动Vagrant时遇到了一些问题, 已经获取了虚拟机,运行vagrant init命令,但在运行vagrant up命令后,我收到了以下消息。

Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Importing base box 'precise32'...
    ==> default: Matching MAC address for NAT networking...
    ==> default: Setting the name of the VM: virtm_default_1400193131859_61200
    ==> default: Fixed port collision for 22 => 2222. Now on port 2201.
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
    ==> default: Forwarding ports...
        default: 22 => 2201 (adapter 1)
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
        default: SSH address: 127.0.0.1:2201
        default: SSH username: vagrant
        default: SSH auth method: private key 
    Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period.

    If you look above, you should be able to see the error(s) that Vagrant had when attempting to connect to the machine. These errors are usually good hints as to what may be wrong.

    If you're using a custom box, make sure that networking is properly working and you're able to connect to the machine. It is a common problem that networking isn't setup properly in these boxes. Verify that authentication configurations are also setup properly, as well.

    If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value.

有什么建议吗?

https://dev59.com/FmAg5IYBdhLWcg3ws8vo#39892470 - paulalexandru
14个回答

23

有多种问题可能导致超时问题。一个好的技巧是启用GUI模式来跟踪它。这将启动VirtualBox机器界面,可能提供更好的问题线索。

要启用GUI模式,请确保您的Vagrantfile文件中的此部分已取消注释:

config.vm.provider "virtualbox" do |vb|
   vb.gui = true
end

然后执行vagrant reload。这会打开VirtualBox应用程序,显示您的虚拟机UI界面。通常问题会变得明显,无论是网络问题还是grub引导加载程序问题。

修复问题后,可以再次注释掉此部分,然后执行另一个vagrant reload返回到无头模式。

参考资料:Vagrant文档


2
谢谢。在我的情况下,VM卡在引导加载程序(grub)等待“ENTER”键处。我正在使用默认的hashicorp/precise32。 我使用GUI启动了机器,然后运行了sudo grub-mkconfig,这样重置了/boot/grub/grub.cfg文件,然后我可以将vb.gui=true行取消注释。 - maggix
2
@maggix,这是我遇到的同样问题;我不确定,但我认为每当在先前执行“vagrant halt”后启动VM时会发生这种情况;现在我进行更干净的关闭,如:vagrant ssh -c 'sudo shutdown -h now' - BrianC
谢谢 @BrianC,如果再出现问题,我会遵循您的建议! - maggix
我已经按照这里描述的步骤解决了我的问题:https://github.com/hashicorp/vagrant/issues/10208#issuecomment-422626935 - marquito

5
一个解决方案在这里优雅地描述:此处。对于我使用的Ubuntu 16.04.2、Vagrant 1.9.3和Virtualbox 5.1.18,尝试运行ubuntu/trusty32(i686),这是唯一有效的解决方法。
您需要修复服务器上的网络并增加一些额外的启动时间:
  • start the VM, log in to the server via GUI (username: vagrant, password: vagrant) and run the following commands

    $ sudo ifdown eth0
    $ sudo ifup eth0
    
  • then add the following to the file /etc/rc.local

    ifdown eth0
    ifup eth0
    
  • on the host, add the following to the Vagrantfile

    config.vm.boot_timeout = 600
    
现在停止虚拟机。下次执行“vagrant up”时,它将是正常的。

[编辑]添加了一个之前遗漏的步骤(两个sudo命令)。再次工作正常。不过需要等待几分钟。 - fkaralis

4

如果您的Vagrant box运行的是Ubuntu 16.04,那么这是由于以下启动步骤...正在运行提高网络接口的启动作业(5分钟8秒) 克服这个问题的一种方法是从VirtualBox启动虚拟机,然后执行vagrant ssh


3

config.vm.boot_timeout即使将其设置为最大值,也无法帮助我解决问题!!!

实际上,我的问题是它无法创建网络适配器。我必须显式地编辑box.ovf文件以启用它。

找到box.ovf文件并在文本编辑器中打开它,然后按下面所示添加cable="true",保存并退出。之后使用vagrant destroy销毁您的vagrant,然后再次运行它。

Locate(box.ovf): C:\Users\<use_name>\.vagrant.d\boxes\box-cutter-VAGRANTSLASH-centos68-desktop\2.0.21\virtualbox\box.ovf

Before: <Adapter slot="0" enabled="true" MACAddress="084017AA8CEB" type="virtio">

After: <Adapter slot="0" enabled="true" MACAddress="084017AA8CEB" cable="true" type="virtio">

这里有一个不错的讨论线程,链接在这里


2
将VirtualBox升级到5.1.12
我使用以下软件时遇到了同样的问题:
  • VirtualBox 5.0.0
  • Vagrant 1.9.1 (vagrant -v)
  • Test Kitchen 1.14.2 (kitchen -v)
  • centos-7.2
当我尝试运行以下命令时:
kitchen create

并且

kitchen test

将Oracle VirtualBox升级(下载+安装)至VirtualBox 5.1.12,问题得到解决。
如果升级不是您的解决方案,您可以使用 @paulalexandru 提到的以下变通方法,但它有以下主要缺点: 您需要为您运行的每个命令执行该手动步骤。
但是似乎VirtualBox已经解决了“已连接电缆”选项的问题。现在,如果您进入“设置”>“网络”>“适配器1”>“高级”,您会发现“已连接电缆”复选框默认被选中:

Cable Connected is checked


使用5.0.26r108824版本时,在一个全新创建的OpenSuse-42.2系统上,我发现两个网络接口中的第一个默认情况下被禁用了“电缆连接”。在OpenSuse Leap-42.1上没有出现这种情况。但我无法确认问题是否与操作系统版本有关。 - Kamafeather

1
这也是我遇到的相同问题。最后我们发现,这个问题是由于我们使用的Linux操作系统与Vagrant版本不兼容所致。所以,我们采用了最新版本(即v1.6.3)的Vagrant,并将我们的操作系统更新到以下版本: agent.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20131103.box"
Vagrant版本4.3.8无法在下面的操作系统上工作。 agent.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box"
我们完全遇到了上述显示的相同问题。

0

我正在使用Windows 10。

我按照提示中的步骤解决了这个问题:

“如果您正在使用Windows,则可能需要启用硬件虚拟化(VT-x)。通常可以通过BIOS启用它。如果您在UEFI系统上使用Hyper-V,则可能还需要禁用Hyper-V才能访问VT-x。”


0

使用我的设置,Windows 11,Vagrant 2.2.19:

我尝试了互联网上所有建议的解决方案,但它们对我都没有用。最终,我通过更改Oracle VM VirtualBox Manager的设置来解决了我的问题,具体操作如下:设置 -> 系统 -> 处理器 -> 取消勾选 PAE / NX。


目前你的回答表述不清楚。请编辑并添加更多细节,以帮助他人理解它如何回答所提出的问题。你可以在帮助中心了解更多有关如何编写良好答案的信息。 - Community

0

对我来说,从BIOS启用虚拟化选项解决了这个问题。


0

对我来说,我在我的Windows 10中卸载了Docker-CE,然后Vagrant就正常工作了。 另外,请检查this选项是否已禁用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接