LoginSignup
20
13

More than 5 years have passed since last update.

Vagrant で bento/ubuntu-16.04 を vagrant up すると Connection timeout になってしまう

Last updated at Posted at 2016-11-21

ちょっと複雑な環境を構築する必要があって、(Virtualbox で Windows Server, Virtualbox + Vagrant + Ansible で Ubuntu) ネットワークの設定をごにょごにょしていたので問題解決まで時間がかかってしまった

環境

  • macOS Sierra 10.12.1
  • Virtualbox 5.0.28 r111378
  • Vagrant 1.7.4 (1.8.7 でも同じ現象になることを確認)

現象

Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.box = "bento/ubuntu-16.04"
# 略

として vagrant up をしたが、

==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
<中略>
    default: Warning: Connection timeout. Retrying...
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.

となってしまう。なので、Virtualboxから仮想マシンのGUIを開くと

スクリーンショット 2016-11-21 19.12.48.png

A start job is running for Raise network interfaces (進行秒数s / 5min 4s)

となってる。待っていると、表示の通り、5分4秒後にいつもの起動手順をふみ、ログイン可能になる。この時、VirtualboxのGUI上ではログインできるものの、vagrant sshは繋がらないまま。

調査

参考: Timeout error during vagrant up
https://github.com/chef/bento/issues/682

他のBoxでも同様の現象が起きているようで、このIssueによると

vb.customize ["modifyvm", :id, "--cableconnected1", "on"]

を加えると動いたという報告が。今回使っている bento/ubuntu-16.04 でも動いた報告があった

対応

なので、Virtualbox provider の設定を

Vagrantfile
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
    vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  end

と追加したところ、問題なく起動&SSH接続ができるようになった。

ちなみに

Vagrant のバージョンが古かった (1.7.4) ことで、別の問題が発生していた。
(別件についてはこちら → Vagrant で bento/ubuntu-16.04 を vagrant up すると途中で ネットワーク周りでコケる)
本件の対応のあとで Vagrant のバージョンアップをした (1.8.7) ので、
再度 確認したら、1.8.7 でも発生した

20
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
13