環境
Host OS: Windows 10 Home (バージョン 1809(OSビルド 17763.557))
Vagrant 2.2.4
Virtual Box 6.0.8
Vagrant Box(Guest OS): CentOS/7
発端
VagrantのゲストOS(CentOS)にある共有ディレクトリに設置したファイルをホストOS(Windows 10)から操作しようとしたところ、共有ファイルが相互に反映されない状態だったので原因を調べてみた。
結果
Vagrantにvagrant-vbguest
というプラグインをインストールすることでファイル共有に成功した。
ファイル共有に失敗する現象は、VirtualBox
とGuest Additions
というソフトウェアのバージョン不一致によって起こり、vagrant-vbguest
はそのバージョン不一致を解消するプラグインということだ。
試したこと
Vagrantの環境構築が初めてだったため、設定に問題があるのかと考え、様々な記事を参考にVagrantfile
を見直してみる。
主にconfig.vm.synced_folder
やそのmount_options
でディレクトリのアクセス権限を変更してみたが状況は変わらず。
どのようなエラーが発生しているのか調べたところ、
> vagrant up
を実行したとき、以下のようなエラーメッセージが表示されていた。
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' version '1902.01' is up to date...
.
.
.
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 home_vagrant_workspace /home/vagrant/workspace
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device
[vagrant mount フォルダ共有ができない問題を解決する | ふらっと考える]
を参考にkernel-devel
をインストールしてみたが、
> vagrant up
.
.
.
The error output from the command was:
mount: unknown filesystem type 'vboxsf'
というエラーメッセージが表示され、この場合の解決策にはならなかった。
解決にいたった経緯
以下の記事を参考に、vagrant-vbguest
プラグインをインストールしたところ、ファイルの共有に成功した。
[Vagrantでマウントエラーが発生したときの解消方法 - Qiita]
[Vagrantで共有フォルダのマウントに失敗するときの対処方法 - Qiita]
> vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching: micromachine-2.0.0.gem (100%)
Fetching: vagrant-vbguest-0.18.0.gem (100%)
Installed the plugin 'vagrant-vbguest (0.18.0)'!
また、VirtualBox公式ドキュメントにもこの方法が紹介されているが、あくまでも公式サポートされている方法ではないとのこと。
[Synced Folders - Getting Started - Vagrant by HashiCorp]
参考
[Vagrantでマウントエラーが発生したときの解消方法 - Qiita]
[Vagrantで共有フォルダのマウントに失敗するときの対処方法 - Qiita]
[Synced Folders - Getting Started - Vagrant by HashiCorp]