vagrant での synced_folderが共有できなかった時のメモ

vagrant up してもsynced_folder がエラーになるときとならないときがあり、謎が解けたっぽいのでメモ。

### 環境
OS : Windows 7
vagrant 1.6.5
VirtualBox 4.3.18
BOX : CentOS 7.0 からの派生。

### 流れ
1. synced_folder のエラー… 
1. vagrant plugin vagrant-vbguest のインストール 
1. vagrant plugin ffi のインストール 
1. vagrant up ! 

### こんなことやりました。

1. Vagrantファイルに書いたのはこんな感じ。owner, groupはVMに作成済みです。
        config.vm.synced_folder "../../../nonCloud/workspaceTmp/private/cp/cp", "/home/hoge/RPJ", owner: "hoge", group: "hoge"
    * vagrant up!!

            $ vagrant up

            Failed to mount folders in Linux guest. This is usually because
            the "vboxsf" file system is not available. Please verify that
            the guest additions are properly installed in the guest and
            can work properly. The command attempted was:

            mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
            mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

            The error output from the last command was:

            /sbin/mount.vboxsf: mounting failed with the error: No such device
    * 頑張って和訳

        > ゲストLinuxへのマウントが失敗しました。
        > "vboxsf"ファイルシステムは使用出来ないのは通常通りです。
        > ゲストにインストールされている"the guest additions"を確認して下さい。おそらく稼働しています。
        > 下記コマンドを実行しました。

        > mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
        > mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

        > コマンドからのエラー出力は下記の通りです。

        > /sbin/mount.vboxsf: mounting failed with the error: No such device        
    * "the guest additions"が動いていると書いてあるけれど、これが問題らしい。と下記URLでお勉強させてもらいました。

        [Vagrant の Box の Guest Additions を最新化する方法](http://weblabo.oscasierra.net/vagrant-vbguest-plugin-1/)

        非常に参考になりました。とういことで、vagrant-vbguestを入れる必要があることもわかりました。

1. vbguestをインストール 

        C:\Users\hoge>vagrant plugin install vagrant-vbguest
        Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
        Installed the plugin 'vagrant-vbguest (0.10.0)'!
    *  インストールに成功したので再度vangrant up ! そしてエラー !

            hoge@hoge ~/gitHub/hogePRJ/hogePRJ
            $ vagrant up
            C:/Users/hoge/.vagrant.d/gems/gems/childprocess-0.5.6/lib/childprocess/windows/handle.rb:44: [BUG] Segmentation fault
            ruby 2.0.0p353 (2013-11-22) [i386-mingw32]

                -- Control frame information -----------------------------------------------
            c:0031 p:---- s:0201 e:000200 CFUNC  :get_exit_code
            中略
            c:0004 p:0158 s:0023 e:000022 METHOD D:/developmentEnvironment/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/cli.rb:42
            c:0003 p:0020 s:0017 e:000016 METHOD D:/developmentEnvironment/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/lib/vagrant/environment.rb:292
            c:0002 p:0807 s:0013 E:0026f0 EVAL   D:/developmentEnvironment/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/bin/vagrant:174 [FINISH]
            c:0001 p:0000 s:0002 E:001704 TOP    [FINISH]

            D:/developmentEnvironment/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/bin/vagrant:174:in `<main>'
            中略
            C:/Users/hoge/.vagrant.d/gems/gems/childprocess-0.5.6/lib/childprocess/windows/handle.rb:44:in `get_exit_code'

            -- C level backtrace information -------------------------------------------
            C:\Windows\SysWOW64\ntdll.dll(ZwWaitForSingleObject+0x15) [0x773FF91D]
            中略
            C:\Windows\SysWOW64\ntdll.dll(RtlKnownExceptionFilter+0xb7) [0x77451D17]

            -- Other runtime information -----------------------------------------------

            * Loaded script: D:/developmentEnvironment/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/bin/vagrant

            * Loaded features:

                0 enumerator.so
                1 D:/developmentEnvironment/HashiCorp/Vagrant/embedded/lib/ruby/2.0.0/i386-mingw32/enc/encdb.so
            中略  299 D:/developmentEnvironment/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.6.5/plugins/providers/virtualbox/driver/meta.rb

            [NOTE]
            You may have encountered a bug in the Ruby interpreter or extension libraries.
            Bug reports are welcome.
            For details: http://www.ruby-lang.org/bugreport.html

            This application has requested the Runtime to terminate it in an unusual way.
            Please contact the application's support team for more information.

1. vagrant plugin ffi のインストール
    * エラーを読んでもさっぱりわからず…。検索してみるとffiの問題のようなので、えいやっとffiインストール！

            C:\Users\hoge>vagrant plugin install ffi --plugin-version 1.9.8
            Installing the 'ffi --version '1.9.8'' plugin. This can take a few minute
            Installed the plugin 'ffi (1.9.8)'!
    * vagrant up ! 手が滑って違うBOX(CentOS6)で実行してしまいました…。
    * しかしログを読むと"GuestAdditions versions on your host (4.3.20) and guest (4.3.14) do not match."とあり、"Installing Virtualbox Guest Additions 4.3.20"とインストール開始。なんかエラー(An error occurred during installation of VirtualBox Guest Additions 4.3.20)が出ているけどだいたい大丈夫と書いてあるので、今回はスルー。そして無事に起動!!

            hoge@hoge ~/private/hoge2
            $ vagrant up
            Bringing machine 'default' up with 'virtualbox' provider...
            ==> 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: Adapter 3: intnet
            ==> default: Forwarding ports...
                default: 22 => 2222 (adapter 1)
            ==> default: Running 'pre-boot' VM customizations...
            ==> 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 timeout. Retrying...
                default: Warning: Remote connection disconnect. Retrying...
            ==> default: Machine booted and ready!
            GuestAdditions versions on your host (4.3.20) and guest (4.3.14) do not match.
            Loaded plugins: fastestmirror, langpacks, priorities
            Loading mirror speeds from cached hostfile
             * base: www.ftp.ne.jp
             * extras: www.ftp.ne.jp
             * rpmforge: mirror.nl.leaseweb.net
             * updates: www.ftp.ne.jp
            16 packages excluded due to repository priority protections
            Package 1:make-3.82-21.el7.x86_64 already installed and latest version
            Resolving Dependencies
            --> Running transaction check
            ---> Package gcc.x86_64 0:4.8.2-16.2.el7_0 will be updated
            --> Processing Dependency: gcc = 4.8.2-16.2.el7_0 for package: gcc-c++-4.8.2-16.2.el7_0.x86_64
            --> Processing Dependency: gcc = 4.8.2-16.2.el7_0 for package: gcc-gfortran-4.8.2-16.2.el7_0.x86_64
            --> Processing Dependency: gcc = 4.8.2-16.2.el7_0 for package: libquadmath-devel-4.8.2-16.2.el7_0.x86_64
            ---> Package gcc.x86_64 0:4.8.3-9.el7 will be an update
            --> Processing Dependency: libgomp = 4.8.3-9.el7 for package: gcc-4.8.3-9.el7.x86_64
            --> Processing Dependency: cpp = 4.8.3-9.el7 for package: gcc-4.8.3-9.el7.x86_64
            --> Processing Dependency: libgcc >= 4.8.3-9.el7 for package: gcc-4.8.3-9.el7.x86_64
            ---> Package perl.x86_64 4:5.16.3-283.el7 will be updated
            ---> Package perl.x86_64 4:5.16.3-285.el7 will be an update
            --> Processing Dependency: perl-libs = 4:5.16.3-285.el7 for package: 4:perl-5.16.3-285.el7.x86_64
            --> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-285.el7.x86_64
            --> Running transaction check
            ---> Package cpp.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package cpp.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package gcc-c++.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package gcc-c++.x86_64 0:4.8.3-9.el7 will be an update
            --> Processing Dependency: libstdc++-devel = 4.8.3-9.el7 for package: gcc-c++-4.8.3-9.el7.x86_64
            --> Processing Dependency: libstdc++ = 4.8.3-9.el7 for package: gcc-c++-4.8.3-9.el7.x86_64
            ---> Package gcc-gfortran.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package gcc-gfortran.x86_64 0:4.8.3-9.el7 will be an update
            --> Processing Dependency: libquadmath = 4.8.3-9.el7 for package: gcc-gfortran-4.8.3-9.el7.x86_64
            --> Processing Dependency: libgfortran = 4.8.3-9.el7 for package: gcc-gfortran-4.8.3-9.el7.x86_64
            ---> Package libgcc.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libgcc.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package libgomp.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libgomp.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package libquadmath-devel.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libquadmath-devel.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
            ---> Package perl-libs.x86_64 4:5.16.3-283.el7 will be updated
            ---> Package perl-libs.x86_64 4:5.16.3-285.el7 will be an update
            --> Running transaction check
            ---> Package libgfortran.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libgfortran.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package libquadmath.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libquadmath.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package libstdc++.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libstdc++.x86_64 0:4.8.3-9.el7 will be an update
            ---> Package libstdc++-devel.x86_64 0:4.8.2-16.2.el7_0 will be updated
            ---> Package libstdc++-devel.x86_64 0:4.8.3-9.el7 will be an update
            --> Finished Dependency Resolution

            Dependencies Resolved

            ================================================================================
             Package                 Arch         Version                  Repository  Size
            ================================================================================
            Updating:
             gcc                     x86_64       4.8.3-9.el7              base        16 M
             perl                    x86_64       4:5.16.3-285.el7         base       8.0 M
            Installing for dependencies:
             perl-Time-HiRes         x86_64       4:1.9725-3.el7           base        45 k
            Updating for dependencies:
             cpp                     x86_64       4.8.3-9.el7              base       5.9 M
             gcc-c++                 x86_64       4.8.3-9.el7              base       7.2 M
             gcc-gfortran            x86_64       4.8.3-9.el7              base       6.6 M
             libgcc                  x86_64       4.8.3-9.el7              base        92 k
             libgfortran             x86_64       4.8.3-9.el7              base       290 k
             libgomp                 x86_64       4.8.3-9.el7              base       127 k
             libquadmath             x86_64       4.8.3-9.el7              base       179 k
             libquadmath-devel       x86_64       4.8.3-9.el7              base        42 k
             libstdc++               x86_64       4.8.3-9.el7              base       294 k
             libstdc++-devel         x86_64       4.8.3-9.el7              base       1.5 M
             perl-libs               x86_64       4:5.16.3-285.el7         base       687 k

            Transaction Summary
            ================================================================================
            Install             (  1 Dependent package)
            Upgrade  2 Packages (+11 Dependent packages)

            Total download size: 47 M
            Downloading packages:
            Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
            --------------------------------------------------------------------------------
            Total                                              2.0 MB/s |  47 MB  00:23
            Running transaction check
            Running transaction test
            Transaction test succeeded
            Running transaction
              Updating   : libquadmath-4.8.3-9.el7.x86_64                              1/27
              Updating   : libgcc-4.8.3-9.el7.x86_64                                   2/27
              Updating   : libstdc++-4.8.3-9.el7.x86_64                                3/27
              Updating   : libstdc++-devel-4.8.3-9.el7.x86_64                          4/27
              Updating   : libgfortran-4.8.3-9.el7.x86_64                              5/27
              Updating   : 4:perl-libs-5.16.3-285.el7.x86_64                           6/27
              Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                       7/27
              Updating   : 4:perl-5.16.3-285.el7.x86_64                                8/27
              Updating   : cpp-4.8.3-9.el7.x86_64                                      9/27
              Updating   : libgomp-4.8.3-9.el7.x86_64                                 10/27
              Updating   : gcc-4.8.3-9.el7.x86_64                                     11/27
              Updating   : libquadmath-devel-4.8.3-9.el7.x86_64                       12/27
              Updating   : gcc-gfortran-4.8.3-9.el7.x86_64                            13/27
              Updating   : gcc-c++-4.8.3-9.el7.x86_64                                 14/27
              Cleanup    : gcc-gfortran-4.8.2-16.2.el7_0.x86_64                       15/27
              Cleanup    : gcc-c++-4.8.2-16.2.el7_0.x86_64                            16/27
              Cleanup    : libquadmath-devel-4.8.2-16.2.el7_0.x86_64                  17/27
              Cleanup    : gcc-4.8.2-16.2.el7_0.x86_64                                18/27
              Cleanup    : libgfortran-4.8.2-16.2.el7_0.x86_64                        19/27
              Cleanup    : libstdc++-devel-4.8.2-16.2.el7_0.x86_64                    20/27
              Cleanup    : libstdc++-4.8.2-16.2.el7_0.x86_64                          21/27
              Cleanup    : 4:perl-libs-5.16.3-283.el7.x86_64                          22/27
              Cleanup    : 4:perl-5.16.3-283.el7.x86_64                               23/27
              Cleanup    : libgcc-4.8.2-16.2.el7_0.x86_64                             24/27
              Cleanup    : libquadmath-4.8.2-16.2.el7_0.x86_64                        25/27
              Cleanup    : cpp-4.8.2-16.2.el7_0.x86_64                                26/27
              Cleanup    : libgomp-4.8.2-16.2.el7_0.x86_64                            27/27
              Verifying  : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                       1/27
              Verifying  : libgfortran-4.8.3-9.el7.x86_64                              2/27
              Verifying  : gcc-c++-4.8.3-9.el7.x86_64                                  3/27
              Verifying  : libgomp-4.8.3-9.el7.x86_64                                  4/27
              Verifying  : libstdc++-devel-4.8.3-9.el7.x86_64                          5/27
              Verifying  : gcc-gfortran-4.8.3-9.el7.x86_64                             6/27
              Verifying  : libquadmath-devel-4.8.3-9.el7.x86_64                        7/27
              Verifying  : cpp-4.8.3-9.el7.x86_64                                      8/27
              Verifying  : libgcc-4.8.3-9.el7.x86_64                                   9/27
              Verifying  : gcc-4.8.3-9.el7.x86_64                                     10/27
              Verifying  : 4:perl-5.16.3-285.el7.x86_64                               11/27
              Verifying  : libstdc++-4.8.3-9.el7.x86_64                               12/27
              Verifying  : 4:perl-libs-5.16.3-285.el7.x86_64                          13/27
              Verifying  : libquadmath-4.8.3-9.el7.x86_64                             14/27
              Verifying  : libquadmath-devel-4.8.2-16.2.el7_0.x86_64                  15/27
              Verifying  : libgfortran-4.8.2-16.2.el7_0.x86_64                        16/27
              Verifying  : 4:perl-libs-5.16.3-283.el7.x86_64                          17/27
              Verifying  : gcc-gfortran-4.8.2-16.2.el7_0.x86_64                       18/27
              Verifying  : cpp-4.8.2-16.2.el7_0.x86_64                                19/27
              Verifying  : 4:perl-5.16.3-283.el7.x86_64                               20/27
              Verifying  : gcc-c++-4.8.2-16.2.el7_0.x86_64                            21/27
              Verifying  : gcc-4.8.2-16.2.el7_0.x86_64                                22/27
              Verifying  : libstdc++-4.8.2-16.2.el7_0.x86_64                          23/27
              Verifying  : libgcc-4.8.2-16.2.el7_0.x86_64                             24/27
              Verifying  : libgomp-4.8.2-16.2.el7_0.x86_64                            25/27
              Verifying  : libquadmath-4.8.2-16.2.el7_0.x86_64                        26/27
              Verifying  : libstdc++-devel-4.8.2-16.2.el7_0.x86_64                    27/27

            Dependency Installed:
              perl-Time-HiRes.x86_64 4:1.9725-3.el7

            Updated:
              gcc.x86_64 0:4.8.3-9.el7             perl.x86_64 4:5.16.3-285.el7

            Dependency Updated:
              cpp.x86_64 0:4.8.3-9.el7             gcc-c++.x86_64 0:4.8.3-9.el7
              gcc-gfortran.x86_64 0:4.8.3-9.el7    libgcc.x86_64 0:4.8.3-9.el7
              libgfortran.x86_64 0:4.8.3-9.el7     libgomp.x86_64 0:4.8.3-9.el7
              libquadmath.x86_64 0:4.8.3-9.el7     libquadmath-devel.x86_64 0:4.8.3-9.el7
              libstdc++.x86_64 0:4.8.3-9.el7       libstdc++-devel.x86_64 0:4.8.3-9.el7
              perl-libs.x86_64 4:5.16.3-285.el7

            Complete!
            Downloading VirtualBox Guest Additions ISO from http://download.virtualbox.org/virtualbox/4.3.20/VBoxGuestAdditions_4.3.20.iso

            Copy iso file C:/Users/hoge/.vagrant.d/tmp/VBoxGuestAdditions_4.3.20.iso into the box /tmp/VBoxGuestAdditions.iso
            mount: /dev/loop0 is write-protected, mounting read-only
            Installing Virtualbox Guest Additions 4.3.20 - guest version is 4.3.14
            Verifying archive integrity... All good.
            Uncompressing VirtualBox 4.3.20 Guest Additions for Linux............
            VirtualBox Guest Additions installer
            Removing installed version 4.3.14 of VirtualBox Guest Additions...
            Copying additional installer modules ...
            Installing additional modules ...
            Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
            Building the VirtualBox Guest Additions kernel modules
            Building the main Guest Additions module[  OK  ]
            Building the shared folder support module[  OK  ]
            Building the OpenGL support module[  OK  ]
            Doing non-kernel setup of the Guest Additions[  OK  ]
            Starting the VirtualBox Guest Additions [  OK  ]
            Installing the Window System drivers
            Could not find the X.Org or XFree86 Window System, skipping.
            An error occurred during installation of VirtualBox Guest Additions 4.3.20. Some functionality may not work as intended.
            In most cases it is OK that the "Window System drivers" installation failed.
            Cleaning up downloaded VirtualBox Guest Additions ISO...
            ==> default: Checking for guest additions in VM...
            ==> default: Setting hostname...
            ==> default: Configuring and enabling network interfaces...
            ==> default: Rsyncing folder: /cygdrive/d/nonCloud/workspaceTmp/study/ => /var/www
            ==> default: Mounting shared folders...
                default: /vagrant => D:/developmentEnvironment/vagrantFiles/hoge2
            ==> default: Running provisioner: shell...
                default: Running: inline script
            ==> default: Running provisioner: openshift...
            Running ssh/sudo command 'mkdir -p ~/sync && chown -R vagrant:vagrant ~/sync' with timeout 600. Attempt #0
    *  centos7のほうのBOXでvagrant upして、こちらも無事起動。synced_folderも正常にマウントされておりました。

            $ vagrant up
            Bringing machine 'default' up with 'virtualbox' provider...
            ==> 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: Adapter 3: intnet
            ==> default: Forwarding ports...
                default: 22 => 2222 (adapter 1)
            ==> default: Running 'pre-boot' VM customizations...
            ==> 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 timeout. Retrying...
                default: Warning: Remote connection disconnect. Retrying...
            ==> default: Machine booted and ready!
            GuestAdditions 4.3.20 running --- OK.
            ==> default: Checking for guest additions in VM...
            ==> default: Setting hostname...
            ==> default: Configuring and enabling network interfaces...
            ==> default: Mounting shared folders...
                default: /home/hogePRJ => D:/nonCloud/workspaceTmp/private/hogePRJ/hogePRJ
                default: /vagrant => D:/developmentEnvironment/vagrantFiles/hoge2
            ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
            ==> default: to force provisioning. Provisioners marked to run always will still run.