5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant ファイル共有とマウントエラー対処法

Last updated at Posted at 2019-10-18

経緯

これまでファイル転送ツールCyberduckを使用して開発を行っていたが、起動が煩わしく感じるようになったため、マウントさせてhost側とguest(Vagrant)側でファイルを共有することにした

やりたいこと

host側のファイルとguest側のファイルを共有することで、hostとguest双方で編集をできるようにする。
今回はhost側の~/sampleディレクトリとguest側の/shareディレクトリを共有させることにする(~/samle配下と/share配下を共有)

環境

Windows10 / macOS Mojave 10.14.6
VirtualBox 6.0.10
Vagrant 2.2.5

guestへ共有したいディレクトリをhostに生成する

$ mkdir ~/sample

Vagrantfile生成

# 初期化してVagrantfile生成
$ vagrant init

Vagrantfileの中身を編集する

Vagrantfile
(編集前)
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

(編集後)
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "~/sample", "/share"

設定完了後はリロードしてSSH接続

$ vagrant reload
$ vagrant up
$ vagrant ssh

以上でhost側の~/sampleやguest上の/shareでの編集が共有されるようになる

マウントエラー

vagrant reloadvagrant 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 share /share

The error output from the command was:

mount: unknown filesystem type 'vboxsf'

hostとguest間のフォルダ共有はGuest Additionsが提供しており、このバージョンが不一致の場合上記のエラーが発生する。詳しくはこちら

対処
$ vagrant plugin install vagrant-vbguest
$ vagrant vbguest
$ vagrant vbguest --status
GuestAdditions 5.0.16 running --- OK.
$ vagrant reload

以上でguest(vagrant)`/share'ディレクトリが生成され、ファイル共有が完了

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?