「Vagrant was unable to mount」エラーで困ったら?VirtualBox 共有フォルダのマウント問題を解決に導く!

vagrant

こんにちは。久しぶりのブログデーということで色々アウトプット中です。docker が結構人気ではありますが、vagrant を使う人もある一定数いるんじゃないでしょうか。特にwindows ユーザの方はもしかしたら愛用してる方もいるかもしれません。

たまにこんなエラー出ませんか?

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,_netdev vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

え、なにこれと思って、vagrant reload しても直らないし、どうしたものかと思うかもしれません。
このエラーの解決方法について今回は解説していきます!!

解決方法その1

vagrant plugin のvagrant-vbguest をインストールする方法です。

# install
vagrant plugin install vagrant-vbguest

# list 表示
vagrant plugin list
vagrant-vbguest (0.32.0, global)

このように出ると大丈夫です。これをした上でvagrantfile に以下の記述を入れてあげます。if Vagrant.has.plugin から、2行下のend までを追記してあげます。

Vagrant.configure("2") do |config|
    config.vm.box = "bento/almalinux-8"

     // vagrant vbguest 追記
      if Vagrant.has_plugin?("vagrant-vbguest")
        config.vbguest.auto_update = false
      end

     config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

     config.vm.network "private_network", ip: "xxx.xxx.xxx.xxx"

この3行を追記して、再度vagrant reload をしてみてください。

これでもエラーが発生する場合は、以下の手順も実施してください。

解決方法その2

まずは、vagrant ssh でサーバーの中にssh してください。そして、このコマンドを叩いてください。

sudo su -
 
dnf install kernel-headers kernel-devel

dnf update -y

それぞれinstall とupdate には少し時間がかかると思いますので、その間は待機です。そして、インストールとアップデートが終わったら、exit して、再度vagrant halt して、vagrant upをしてみてください。

これで成功するはずです!!

今回の原因

上のエラーにも書いてありますが、どうもvirutalbox となかにあるホストのOS のVirtualBox Guest Additionsのバージョンが一致しないことが原因なようです。これを合わせるために、vagrant ssh してkernel モジュールのバージョンをアップデートすることによって、virtualbox との互換性が取れるようになって、mount が上手くいくということみたいです。

元々は、mount sync folder などの機能もvirtualbox をより使いやすくするためにvirtualbox Guest Additions が提供しているものですので、互換性が取れない場合は失敗するのは納得ですね。

互換性が取れた後のログを見ても、このようになっておりmodule support ができてるログが出力されるようになります。

Building the main Guest Additions 7.1.6 module for kernel 4.18.0-553.58.1.el8_10.x86_64.
Building the shared folder support module.
Building the graphics driver module.

逆に上手くできてないと、下記のようになります。

Could not find the X.Org or XFree86 Window System, skipping.
kernel modules and services were not reloaded

X.Org やXFree86 などは今回使用しないので、これでオッケーです。

まとめ

あんまり見慣れないエラーなので、解決までに時間がかかるかもですが、このブログが助力となれば幸いです!!

コメント

タイトルとURLをコピーしました