こんにちは、エンジニアのオオバです。
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 dmode=777,fmode=777,uid=500,gid=500 var_www_server /var/www/server
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device

Mojave環境でハマったVirtualBoxとVagrantの関係
前回引っかかった上記のエラー対応について進めていきます。
※ただし今回の記事は前回とは環境が少し違って、macOS HighSierraでの作業となります。
→11万文字で徹底解説した「DOTweenの教科書」Unityアニメーションの超効率化ツールはこちら
検証環境
- macOS HighSierra 10.13.6
- VirtualBox 5.1.22
- Vagrant 1.9.6
またコチラの環境でも以下の方法でうまくいきました。
- macOS Mojave 10.14
- VirtualBox 5.2.20
- Vagrant 2.2.0
冒頭のエラー内容を要約すると、共有フォルダにアクセスできず、使用できないということだと思われます。
ホスト⇔ゲスト間のフォルダ共有機能はGuest Additionsが提供していますが
ホスト(VirtualBox)とゲスト(Guest Additions)でバージョン不一致があるとマウントエラーが起きるようです。
コチラのQiita記事から引用させてもらっていますが、そのようです。
ということで記事の通りvagrant-vbguest
を使っていきます。
vagrant-vbguestがインストールされているか確認
vagrant vbguest --status
vbguestをの状態を確認します。
[default] No installation found.
するとインストールされていない旨が出力されたため、インストールします。
vagrant plugin install vagrant-vbguest
Installed the plugin 'vagrant-vbguest (0.14.2)'!
このように出力されたため、インストールされたと思われます。再度vagrant vbguest --status
で確認します。
[default] No installation found.
...一旦vagrantの再起動をしてみます。 vagrant reload
を実行します。
[default] No installation found.
とりあえず、vbguestを実行してみます。 vagrant vbguest
と実行します。
[default] No installation found.
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
- base: ftp.tsukuba.wide.ad.jp
- extras: ftp.tsukuba.wide.ad.jp
- updates: ftp.tsukuba.wide.ad.jp
No package kernel-devel-2.6.32-696.3.2.el6.x86_64 available.
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
Nothing to do
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 5.1.22 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.22 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.22 of VirtualBox Guest Additions...
vboxadd.sh: Stopping VirtualBox Additions.
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.
An error occurred during installation of VirtualBox Guest Additions 5.1.22. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
vboxadd.sh: Starting the VirtualBox Guest Additions.
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: modprobe vboxguest failed.
と最初はプラグインが存在しないからインストールを試みるも、だめでエラーが出ています。
ログを確認する
/var/log/VBoxGuestAdditions.log
、/var/log/vboxadd-install.log
この辺りをチェックしてくれと勧められているので確認します。
vagrant ssh
でログインします。
cat /var/log/VBoxGuestAdditions.log
と実行してログ内容を出力します。
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: modprobe vboxguest failed.
このエラー内でも/var/log/vboxadd-install.log
を見てほしい旨が書かれています。
cat /var/log/vboxadd-install.log
と実行してログを確認します。
/tmp/vbox.0/Makefile.include.header:112: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR= and run Make again. Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.
Error: unable to find the sources of your current Linux kernel
この辺りをキーワードにしてググって探しました。
- VBoxLinuxAdditions.run を実行して unable to find the sources of your current Linux kernel になった時の対応方法 - Qiita
- Vagrantのmountエラーを解決しようとしたらvboxのリビルドがこける - Qiita
こちらの記事たちを参考にいじりました。
不本意ではあるのですが、原因わからずうまく行ってしまったため以下はただのやったことの羅列になっています。
vagrant ssh
でまずはログインしますyum update
します。 ※ルート権限ではない場合はsudo を頭につけるか、sudo su
ルートでログインして実行しますyum install kernel-devel
でkernel-develをインストールします。※既にインストール済みと言われるかもしれませんyum -y update kernel
※更新するものは無いと言われるかもしれませんyum -y install kernel-devel kernel-headers dkms gcc gcc-c++
exit
してvagrant reload

なんか気持ち悪いけど成功。
まあ、業務で使用するわけではないので、一旦このまま作りたいものを作るために先に進もうと思います。
以上

この記事が気に入ったらフォローしよう
- VirtualBox 5.2.20
- Vagrant 2.2.0
- macOS Mojave 10.14