Vagrantのmountが失敗するやつ

起こった環境はこんな感じ、

$ sw_vers   
ProductName:	Mac OS X
ProductVersion:	10.10.2
BuildVersion:	14C109

$ vagrant --version
Vagrant 1.7.2
$ VBoxManage --version
4.3.22r98236

$ vagrant init chef/centos-6.5
$ vagrant up


==> default: Mounting shared folders...で

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

てな感じにエラーになった

とりあえず下にあげている参考サイトを読んだところvbguestプラグイン入れてると起こるのかなと思い、プラグイン一覧を見てみると

$vagrant plugin list
vagrant-share (1.1.3, system)

あれ?入ってない。そもそもそんなの入れてなかった。

次にvbox をリビルドすると云々という話が多々あったので、リビルドしてみる

[vagrant@localhost ~]$ sudo /etc/init.d/vboxadd setup
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-504.8.1.el6.x86_64

Building the main Guest Additions module                   [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [  OK  ]

The missing package can be probably installed with yum install kernel-devel-2.6.32-504.8.1.el6.x86_64.とあったので、

[vagrant@localhost ~]$ sudo yum install kernel-devel-2.6.32-504.8.1.el6.x86_64 -y
〜インストール完了したあと〜
[vagrant@localhost ~]$ sudo /etc/init.d/vboxadd setup
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  ]

うまくいったっぽい? 期待に胸膨らませながらvagrantを再起動してみる

==> default: Mounting shared folders...
    default: /vagrant => /Users/ユーザ名/MyVagrant/mycentos

無事エラー無しで起動、ssh接続してシェアされてるか確かめてみる

[vagrant@localhost ~]$ cd /
[vagrant@localhost /]$ ls
bin   dev  home  lib64       media  opt   root  selinux  sys  usr      var
boot  etc  lib   lost+found  mnt    proc  sbin  srv      tmp  vagrant
[vagrant@localhost /]$ cd vagrant
[vagrant@localhost vagrant]$ ls
Vagrantfile
[vagrant@localhost vagrant]$ touch uniuni.txt
[vagrant@localhost vagrant]$ ls
Vagrantfile  uniuni.txt
[vagrant@localhost vagrant]$
---------------Macの方から見てみると(Vagrantfile置いてある場所にて)--------------
$ ls
Vagrantfile	uniuni.txt 

無事うまくいきました。結局、Building the main Guest Additions moduleがうまくいってないからだったんですが、なんでそうなったのかがまだ良くわかんないので引き続き調べてみます。

参考サイト:

vagrant-vbguestプラグインがGuestAdditionsを無効にしてしまう - Qiita


VirtualBox - vagrant up 時に shared folder の mount でエラーが発生する - Qiita