kakakakakku blog

Weekly Tech Blog : Keep on Learning 👍

Vagrant で Synced Folders のエラーが出た

近々 Vagrant を使う必要がありそうで,久し振りに Vagrant で環境構築をしている.

ミドルウェアVagrant で良いけど,コードはローカルで書きたいなぁと思っていて,共有ディレクトリの設定をしようと思ったらハマった.


現在の「ホスト端末」の Vagrant 環境は以下.

➜  vagrant  VBoxManage -v
➜  vagrant  vagrant -v
Vagrant 1.7.4


[vagrant@vagrant-centos65 ~]$ cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m

Synced Folders のエラー

普通に vagrant up をしたら Synced Folders のエラーが出た.

( ゚д゚)ナンデ?

➜  vagrant  vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
Installing Virtualbox Guest Additions 4.3.30 - guest version is 4.3.6
An error occurred during installation of VirtualBox Guest Additions 4.3.30. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
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

ただし vagrant ssh をすることはできる.


vbox を手動でビルドしてみる

Guest Additions でエラーになっていた.

[vagrant@vagrant-centos65 ~]$ 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-431.3.1.el6.x86_64

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


[vagrant@vagrant-centos65 ~]$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

ビルド結果に書いてある通り kernel-devel-2 をインストールしてみたけど,無かった.

[vagrant@vagrant-centos65 ~]$ sudo yum install -y kernel-devel-2.6.32-431.3.1.el6.x86_64
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Setting up Install Process
Nothing to do

詳しいことはわからないけど vault.centos.org の URL を直接指定したらインストールできた.

[vagrant@vagrant-centos65 ~]$ sudo yum install -y http://vault.centos.org/6.5/updates/x86_64/Packages/kernel-devel-2.6.32-431.3.1.el6.x86_64.rpm

再度 vbox をビルドする


[vagrant@vagrant-centos65 ~]$ 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 をリロードする

ホスト側に戻って vagrant reload をしたらうまく Synced Folders の設定ができた.


➜  vagrant  vagrant reload
==> default: Attempting graceful shutdown of VM...
GuestAdditions 4.3.30 running --- OK.
==> default: Mounting shared folders...


Vagrantfile に以下の設定を追加する.

config.vm.synced_folder '${HOST_DIR}', '${GUEST_DIR}'


Docker に慣れちゃうと Vagrant 遅っ!って思ってしまうなー.