Windowsアップデートをしてvagrant upでエラーが出るようになったときの対処
先日Windowsアップデートをしたら、vagrant upをしたときにエラーが出るようになってしまいました。
今後同様のことがあったときに困らないように対処方法をまとめておきます。
- 環境
- 最初に出ていたエラー
- Vagrantを最新バージョンにする
- authentication_keysのパーミッションを確認・変更
- VirtualBox Guest Additionsを入れる
- まとめ
環境
最初に出ていたエラー
vagrant up
をすると、途中からひたすらWarning: Authentication failure. Retrying...
が繰り返され、タイムアウトしてしまいました。
エラーは出ますが、仮想マシンはちゃんと立ち上がっていて、vagrant ssh
もすることができます。
$ 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 aborted. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. 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.
Vagrantを最新バージョンにする
Vagrantのアップデート方法(Windows) - Qiita
Vagrant 2.2.3が最新だったので、バージョンアップしてみます。
WindowsアップデートでVagrantが動かなくなることはよくあるらしく、まずバージョンアップしましょうとのことでした。
結果
何も変わりませんでした。
authentication_keysのパーミッションを確認・変更
vagrant up時にAuthentication failureが出続ける原因と対処法 - Qiita
次に、こちらの記事を見て、authentication_keysのパーミッションが気になったので確認してみました。
$ vagrant ssh [vagrant@localhost ~] ls -l .ssh/authentication_keys -rw-rw-r--. 1 vagrant vagrant 381 Dec 29 16:33 .ssh/authorized_keys
パーミッションが664になっていました。
公開鍵は他人が変更や読み取りができてしまうような設定になっていると認証に使ってもらえないようなので、適切なパーミッション600に修正します。
[vagrant@localhost ~] chmod 600 .ssh/authorized_keys [vagrant@localhost ~] ls -l .ssh/authorized_keys -rw-------. 1 vagrant vagrant 381 Dec 29 16:33 .ssh/authorized_keys
結果
vagrant up
してみます。
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'bento/centos-6.8' version '2.3.4' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Booting VM... ==> 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 aborted. Retrying... default: Warning: Connection reset. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: No guest additions were detected on the base box for this VM! Guest default: additions are required for forwarded ports, shared folders, host on ly default: networking, and more. If SSH fails on this machine, please install default: the guest additions and repackage the box to continue. default: default: This is not an error message; everything may continue to work prope rly, default: in which case you may ignore this message. ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => C:/Users/take-/MyVagrant/MyCentOS Vagrant was unable to mount VirtualBox shared folders. This is usually because the filesystem "vboxsf" is not available. This filesystem is made available via the VirtualBox Guest Additions and kernel module. Please verify that these guest additions are properly installed in the guest. This is not a bug in Vagrant and is usually caused by a faulty Vagrant box. For context, the command attempted was: mount -t vboxsf -o uid=500,gid=500 vagrant /vagrant The error output from the command was: /sbin/mount.vboxsf: mounting failed with the error: No such device
エラーの種類が変わりました。
==> default: Mounting shared folders... default: /vagrant => C:/Users/take-/MyVagrant/MyCentOS Vagrant was unable to mount VirtualBox shared folders. This is usually because the filesystem "vboxsf" is not available. This filesystem is made available via the VirtualBox Guest Additions and kernel module. Please verify that these guest additions are properly installed in the guest. This is not a bug in Vagrant and is usually caused by a faulty Vagrant box. For context, the command attempted was: mount -t vboxsf -o uid=500,gid=500 vagrant /vagrant The error output from the command was: /sbin/mount.vboxsf: mounting failed with the error: No such device
エラーが起きているのはこの部分で、共有フォルダのマウンティングに失敗したと言っているようです。
また、「 VirtualBox Guest Additionsが適切にインストールされているか確認してください。」と書いてあります。
VirtualBox Guest Additionsを入れる
VirtualBox Guest Additionsの入れ方は、以下の記事を参考にさせていただきました。
vagrantのshared folderのmountに失敗してしまった場合 - Qiita
この記事によると、「VirtualBoxでディレクトリ共有を行うために使っているVirtualboxGuestAdditionというツールのバージョンが, ホストとゲストでずれているとこのような問題がおこる」そうです。
プラグインを入れて、実行します。
$ vagrant plugin install vagrant-vbguest Installing the 'vagrant-vbguest' plugin. This can take a few minutes... Installed the plugin 'vagrant-vbguest (0.17.1)'! $ vagrant vbguest [default] No Virtualbox Guest Additions installation found. Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: ftp.riken.jp * extras: ftp.riken.jp * updates: ftp.riken.jp Package gcc-4.4.7-23.el6.x86_64 already installed and latest version Package binutils-2.20.51.0.2-5.48.el6.x86_64 already installed and latest version Package 1:make-3.81-23.el6.x86_64 already installed and latest version Package 4:perl-5.10.1-144.el6.x86_64 already installed and latest version Package bzip2-1.0.5-7.el6_0.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package kernel-devel.x86_64 0:2.6.32-754.3.5.el6 will be installed ---> Package kernel-devel.x86_64 0:2.6.32-754.9.1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: kernel-devel x86_64 2.6.32-754.3.5.el6 updates 11 M kernel-devel x86_64 2.6.32-754.9.1.el6 updates 11 M Transaction Summary ================================================================================ Install 2 Package(s) Total download size: 22 M Installed size: 52 M Downloading Packages: -------------------------------------------------------------------------------- Total 4.1 MB/s | 22 MB 00:05 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : kernel-devel-2.6.32-754.3.5.el6.x86_64 1/2 Installing : kernel-devel-2.6.32-754.9.1.el6.x86_64 2/2 Verifying : kernel-devel-2.6.32-754.9.1.el6.x86_64 1/2 Verifying : kernel-devel-2.6.32-754.3.5.el6.x86_64 2/2 Installed: kernel-devel.x86_64 0:2.6.32-754.3.5.el6 kernel-devel.x86_64 0:2.6.32-754.9.1.el6 Complete! Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso Mounting Virtualbox Guest Additions ISO to: /mnt Installing Virtualbox Guest Additions 5.2.22 - guest version is unknown Verifying archive integrity... All good. Uncompressing VirtualBox 5.2.22 Guest Additions for Linux........ VirtualBox Guest Additions installer Removing installed version 5.1.18 of VirtualBox Guest Additions... vboxadd.sh: Stopping VirtualBox Additions. Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Starting. Unmounting Virtualbox Guest Additions ISO from: /mnt
結果
これで再起動したら、上手く動きました!
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'bento/centos-6.8' version '2.3.4' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Booting VM... ==> 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 aborted. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Connection reset. Retrying... ==> default: Machine booted and ready! [default] GuestAdditions 5.2.22 running --- OK. ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => C:/Users/take-/MyVagrant/MyCentOS ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run.
まとめ
今回行ったことをまとめると、
- Vagrantのバージョンアップ
- authorized_keysのパーミッション変更
- VirtualBox Guest Additionsを入れる
でした。
公開鍵のパーミッションが600でないといけない話は全然知らなかったので勉強になりました。