vagrant Homestead でホストOSの共有フォルダが見れなくなった際の対処
状況
ある日Homesteadの vagrant up
時に以下の様なエラーが出てゲストOSとホストOSフォルダ共有が出来なくなってしまった。
(windows10 64bit環境)
Going on, assuming VBoxService is correct... bash: line 5: setup: command not found ==> homestead-7: Checking for guest additions in VM... The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! setup Stdout from the command: Stderr from the command: bash: line 5: setup: command not found
エラーでググると以下のページに行き当たり同じ対処をしたが、 GuestAdditions の インストールをHomestead側で行ってもmountがされない様だった。
対応したが私の環境では解決しなかった方法
上記のページに習いmountしてみたが上手くいかなかった。
vagrant@homestead:/mnt$ sudo ./VBoxLinuxAdditions.run Verifying archive integrity... All good. # ... インストール中のメッセージ... VirtualBox Guest Additions: Running kernel modules will not be replaced until the system is restarted vagrant@homestead:/mnt$ cd vagrant@homestead:~$ ls /etc/init.d/ | grep vboxadd # 何も出ない! 入ってない! vagrant@homestead:~$ ls /etc/init.d/ acpid avahi-daemon cron ebtables iscsid lvm2-lvmetad mdadm nfs-common open-vm-tools php7.2-fpm postgresql rsync supervisor unattended-upgrades apparmor beanstalkd cryptdisks grub-common keyboard-setup.sh lvm2-lvmpolld mdadm-waitidle nginx php5.6-fpm plymouth procps rsyslog sysstat uuidd apport blackfire-agent cryptdisks-early hwclock.sh kmod lxcfs memcached ntp php7.0-fpm plymouth-log redis-server screen-cleanup udev x11-common atd console-setup.sh dbus irqbalance lvm2 lxd mysql open-iscsi php7.1-fpm postfix rpcbind ssh ufw # やはり vboxadd がいない!
ちなみにこの記事執筆時のバージョンは以下 6.0.8 でした。 Index of /virtualbox/6.0.8
wget http://download.virtualbox.org/virtualbox/6.0.8/VBoxGuestAdditions_6.0.8.iso
そこでHomesteadのBOXファイル自体が古く対応できていないのでは?と思い至りupdateすることにした
windows側 の Gitbash で以下のコマンドを実行
$ vagrant box list # その他のBOXファイルがここに表示されている # updateを重ね現在は 6.1.0 laravel/homestead (virtualbox, 5.0.1) laravel/homestead (virtualbox, 5.2.0) laravel/homestead (virtualbox, 6.1.0) $ vagrant box update --box laravel/homestead # ここでダウンロードとupdateが行われるがしばらく時間がかかる $ vagrant box list # その他のBOXファイルがここに表示されている laravel/homestead (virtualbox, 5.0.1) laravel/homestead (virtualbox, 5.2.0) laravel/homestead (virtualbox, 6.1.0) laravel/homestead (virtualbox, 8.0.0-beta) # インストール後再度確認、上記の様に8.0.0-betaが入った
しかし、無事updateされて晴れてvagrant up
したが駄目。再度 GuestAdditions をmountしても同じ結果となる。乗らない…。
問題点が判明
windows側のGit bash で状況確認中、以下のerrorが出た事に注目
$ vagrant vbguest vagrant vbguest [homestead-7] GuestAdditions seems to be installed (6.0.8) correctly, but not running. bash: line 5: setup: command not found The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed!
もう直接的に GuestAdditions 6.0.8が駄目っす!って言っている。犯人はお前か。
このerror文章で検索をかけてみた所、以下のページが見つかる。
リンク先引用
[devapp] GuestAdditions seems to be installed (6.0.6) correctly, but not running. Redirecting to /bin/systemctl start vboxadd.service Redirecting to /bin/systemctl start vboxadd-service.service bash: line 4: setup: command not found ==> devapp: Checking for guest additions in VM... The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed!
setup
Stdout from the command:
Stderr from the command:
bash: line 4: setup: command not found ```
6.0.6でも同じ問題があったようだ
で、以下のコメントに注目
alvaro-canepa commented on 20 Apr
I have the same issue with Homestead and Virtualbox 6.0.6.
Adding this to Vagrantfile solve the problem:
if Vagrant.has_plugin?("vagrant-vbguest") config.vbguest.auto_update = false end
alvaro-canepa さんが、Vagrantfileにこの設定を追加しろって言ってる。
このコードはつまり vagrant-vbguest
はアップデートさせず使えって設定を書けってことらしい。
結論
という事で Homestead内の Vagrantfile を開き if文の中に設定を追記
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # ここには他の設定諸々が書かれている # 2019/06/24 add https://github.com/dotless-de/vagrant-vbguest/issues/333 if Vagrant.has_plugin?("vagrant-vbguest") config.vbguest.auto_update = false end end
これでvagrant reload --provision
した所、諸々の再設定がされて無事共有フォルダが反映されるようになりました。
でもいつかupodateが反映され、 その際には vagrant-vbguest も正しく修正された暁には、上の設定は消して新たな設定を反映されるようにするのが望ましいでしょう。