楽しいだけで十分です

好きなことを書きます

vagrant upした時に、`Vagrant was unable to mount VirtualBox shared folders. This is usually ~`というエラーが出た時の対処

Vagrantでfile_syncedを設定してvagrant upすると、次のようなエラーで怒られました。

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 uid=1000,gid=1000 var_www_html /var/www/html

The error output from the command was:

mount: unknown filesystem type 'vboxsf'

これを解決するまでにやったことのメモします。

解決するには

  • 次の2つのことをした後に、再起動(vagrant reload)をすると解決します。

カーネルのアップデート

  • 上記のエラーが出た時でも仮想マシンへの接続は可能なので、vagrant sshで接続後、次のコマンドを実行します。
[vagrant@localhost ~]$ sudo yum -y update kernel
[vagrant@localhost ~]$ sudo yum -y install kernel-devel kernel-headers dkms gcc gcc-c++

VirtualBox Guest Additionsのバージョンを合わせる

  • VirtualBox Guest Additionsは、VirtualBox 上に作成したゲストOSにインストールするソフトウェアで、ホストとゲストとの間での操作を便利にしてくれる機能が使えます。このバージョンがインストールしているVirtualBoxとゲストマシンのGuest Addtionsで一致しない場合に上記のエラーで失敗してしまいます。
  • 手動でバージョンを合わせる方法もありますが、「vagrant-vbguest」プラグインを使うと便利です。インストール方法は次のコマンド。
$ vagrant plugin install vagrant-vbguest