Vagrant 卡在“等待 VM 启动"中 [英] Vagrant stuck in "Waiting for VM to Boot"

查看:29
本文介绍了Vagrant 卡在“等待 VM 启动"中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这个问题的开头提到我确实看过了大多数(如果不是全部)流浪的等待 VM 启动"故障排除线程:

我尝试过的方法包括:

  1. vagrant 连接虚拟机失败

  2. https://superuser.com/questions/342473/vagrant-ssh-虚拟机失败

  3. https://github.com/mitchellh/vagrant/issues/410

  4. http://vagrant.wikia.com/wiki/Usage

  5. http://scotch.io/tutorials/get-vagrant-up-and-running-in-no-time

还有更多.

以下是我设置 Vagrant 的方法:

注意:我们正在使用 Vagrant 1.2.2,因为我们目前没有时间将配置更改为更新版本.我也在使用 VirtualBox 4.2.26.

  1. 我的办公室有一个 /official/ 文件夹,其中包含诸如 Vagrantfile 之类的内容.在我的 Vagrantfile 中有这些自定义设置:

<块引用>

 config.vm.box = "my_box"config.ssh.private_key_path = "~/.ssh/github_rsa"config.ssh.forward_agent = trueconfig.ssh.forward_x11 = 真config.ssh.max_tries = 300config.vm.provision :shell, :inline =>/etc/init.d/networking restart"

  1. 我通过 vagrant box add my_box absolute_path/package.box 安装了我们的自定义框(称为 package.box),这很顺利.

  2. 运行vagrant up,我会查看VirtualBox 的预览",它只会停留在登录页面.我的终端也只会说:Waiting for VM to boot.这可能需要几分钟时间. 据我所知,这是一个 SSH 问题.或者我的私钥问题,尽管在我的 Vagrantfile 中我明确指出了我的私钥位置.

有趣的笔记:

  1. 在 VirtualBox GUI 中运行 dhclient,它说没有找到命令.运行 sudo dhclient eth0 是建议的修复之一.

  2. 此修复:https://superuser.com/a/343775/298915的修改/etc/rc.local 文件以在 exit 0 之前包含行 sh/etc/init.d/networking restart."没有采取任何措施来解决问题.

结论:

我以为我弄乱了文件,尝试重新安装所有东西,但似乎并没有改善问题.我无法解决这个问题.有人能给我一些见解吗?

解决方案

所以经过大约 12 个小时沮丧的故障排除后,我能够(最终)让 VM 启动.

  1. 设置您的私钥/公钥 使用提供的链接.我的盒子是 Debian Linux 3.2.0-4-amd64,所以你必须使用 /home 而不是 /root/.ssh/id_rsa.pub/vagrant/.ssh/id_rsa.pub(以及私钥的相应 id_rsa 路径).

    注意:确保您的文件具有正确的权限.使用 ls -l path 检查,并使用 chmod 更改.您的机器可能没有 /home/vagrant/.ssh/authorized_keys,因此请使用 touch/home/vagrant/.ssh/authorized_keys 生成该文件.

  2. 使用 VirtualBox GUI 启动您的虚拟机(通过 Vagrantfile boot-GUI 命令,或使用 VirtualBox 启动您的虚拟机).出现提示时使用 vagrantvagrant 登录.

  3. 在 GUI 中,使用 sudo dhclient eth0 -v 手动启动 dhclient.为什么默认关闭?我不知道. 我发现当我在上面的教程中尝试 wget 私钥/公钥时它已关闭,但无法做到.

  4. 转到本地机器的命令行并使用 vagrant reload 重新加载 vagrant.它应该会启动,并且不会再挂在等待 VM 启动"状态.

这对我有用.尽管其他机器可能会有所不同,但无论出于何种原因,Vagrant 都喜欢破坏.

建议:可以把这个保存成脚本,这样我们就不用每次都手动做这个了吗?

更新到最新版本的 Vagrant,您将永远不会再看到此问题.时间差不多了吧?

I want to preface this question by mentioning that I have indeed looked over most if not all vagrant "Waiting for VM to Boot" troubleshooting threads:

Things I've tried include:

  1. vagrant failed to connect VM

  2. https://superuser.com/questions/342473/vagrant-ssh-fails-with-virtualbox

  3. https://github.com/mitchellh/vagrant/issues/410

  4. http://vagrant.wikia.com/wiki/Usage

  5. http://scotch.io/tutorials/get-vagrant-up-and-running-in-no-time

And more.

Here's how I setup my Vagrant:

Note: We are using Vagrant 1.2.2 since we do not at the moment have time to change configs to newer versions. I am also using VirtualBox 4.2.26.

  1. My office has an /official/ folder which includes things such as Vagrantfile inside. Inside my Vagrantfile are these custom settings:

  config.vm.box = "my_box"

  config.ssh.private_key_path = "~/.ssh/github_rsa"
  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true
  config.ssh.max_tries = 300
  config.vm.provision :shell, :inline => "/etc/init.d/networking restart"

  1. I installed our custom box (called package.box) via vagrant box add my_box absolute_path/package.box which went without a hitch.

  2. Running vagrant up, I would look at the "preview" of the VirtualBox, and it would simply be stuck at the login page. My Terminal would also only say: Waiting for VM to boot. This can take a few minutes. As far as I know, this is an SSH issue. Or my private key issues, though in my Vagrantfile I explicitly pointed to my private key location.

Interesting Notes:

  1. Running dhclient within the VirtualBox GUI, it says command no found. Running sudo dhclient eth0 was one of the suggested fixes.

  2. This fix: https://superuser.com/a/343775/298915 of "modify the /etc/rc.local file to include the line sh /etc/init.d/networking restart just before exit 0." did nothing to fix the issue.

Conclusion:

Having tried to re-install everything thinking I messed up a file, it did not seem to ameliorate the issue. I am unable to work with this issue. Could someone give me some insight?

解决方案

So after around twelve hours of dejected troubleshooting, I was able to (finally) get the VM to boot.

  1. Setup your private/public keys using the link provided. My box is a Debian Linux 3.2.0-4-amd64, so instead of /root/.ssh/id_rsa.pub, you have to use /home/vagrant/.ssh/id_rsa.pub (and the respective id_rsa path for the private key).

    Note: make sure your files have the right permissions. Check using ls -l path, and change using chmod. Your machine may not have /home/vagrant/.ssh/authorized_keys, so generate that file with touch /home/vagrant/.ssh/authorized_keys.

  2. Boot your VM using the VirtualBox GUI using (through either Vagrantfile boot-GUI command, or starting your VM using VirtualBox). Login using vagrant and vagrant when prompted.

  3. Within the GUI, manually start dhclient using sudo dhclient eth0 -v. Why is it off by default? I have no idea. I found out that it was off when I tried to wget the private/public keys in the tutorial above, but was unable to.

  4. Go to your local machine's command line and reload vagrant using vagrant reload. It should boot, and no longer hang at "Waiting for VM to Boot."

This worked for me. Though it may be different for other machines, for whatever reason Vagrant likes to break.

Suggestion: can this be saved as a script so we don't need to manually do this everytime?

EDIT: Update to the latest version of Vagrant, and you will never see this issue again. About time, huh?

这篇关于Vagrant 卡在“等待 VM 启动"中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆