schedule2020-03-18

【Ubuntu】Vagrantの共有フォルダの設定とエラーmount unknown filesystem type 'vboxsf'の対処

VagrantのホストOSとゲストOSのフォルダを共有するよう設定し、立ち上げるとmount: unknown filesystem type 'vboxsf'のエラーが出た。

環境

  • Ubuntu 18.04.4 LTS (ホストOS)
  • Vagrant 2.2.7
  • config.vm.box = "centos/7" (ゲストOS)

Vagrantfileの共有フォルダの設定

config.vm.synced_folder "/home/suzu6/vagrant/", # ホストOSのフォルダ
                        "/srv/app",             # ゲストOSのフォルダ
                        :mount_options => ["dmode=777,fmode=777"]

対処方法

こちらの解決策2を試し解決した。 プラグインのvagrant-vbguestをホストOSにインストールするだけで済んだ。

$ sudo vagrant plugin install vagrant-vbguest
$ vagrant vbguest --status
[default] GuestAdditions 6.1.4 running --- OK.

この状態でvagrant upするとゲストOSにフォルダ共有に必要な追加機能をインストールしてくれる。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...

...

==> default: Machine booted and ready!
# 起動後に追加機能がないことを確認すると自動的にインストールする
[default] No Virtualbox Guest Additions installation found.

# 依存パッケージを追加
...

Complete!

# VBoxGuestAdditions.isoでmntする
Copy iso file /usr/share/virtualbox/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Mounting Virtualbox Guest Additions ISO to: /mnt
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 6.1.4 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.4 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 
3.10.0-1062.12.1.el7.x86_64.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
Unmounting Virtualbox Guest Additions ISO from: /mnt
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /home/suzu6/vagrant/my-vagrantfile/ => /vagrant
==> default: Mounting shared folders...
    default: /srv/app => /home/suzu6/vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

以上でフォルダが共有できました。

vagrant-vbguest

github

vagrant-vbguestは、ゲストシステムにホストのVirtualBox Guest Additionsを自動的にインストールするVagrantプラグイン。

VirtualBox Guest Additionsの中にフォルダを共有する機能がある。 vagrant upをするとプラグインがゲストOSに自動的にインストールしてくれる。

エラーの全文

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=1000,gid=1000 srv_app /srv/app

The error output from the command was:

mount: unknown filesystem type 'vboxsf'

参考