LoginSignup
5
5

More than 5 years have passed since last update.

Vagrantで共有フォルダがマウントできないエラーが起こった時に試したこと全て

Posted at

ローカル開発環境構築時にvagrant upで仮想マシンを起動する時に共有フォルダのマウントに失敗して、
かなりハマったので同じ現象が起きている方の一助となればと思い、試したことをまとめました。

検証したことの全てをメモしたのでお急ぎの方は、②→⑤を行っていただくと良いと思います。

現象

host環境:Windows,Macの両方
guest環境:CentOS6.8
vagrant upで以下のエラーが起きた。

エラーメッセージ
[default] GuestAdditions versions on your host (5.1.14) and guest (4.3.6) do not match.
/root/.bashrc: line 18: ./git-completion.bash: No such file or directory
Loaded plugins: fastestmirror, versionlock
Setting up Install Process
Determining fastest mirrors
 * base: ftp.iij.ad.jp
 * epel: mirror01.idc.hinet.net
 * extras: ftp.iij.ad.jp
 * remi-safe: mirror.innosol.asia
 * updates: ftp.iij.ad.jp
http://mirror.innosol.asia/remi/enterprise/6/safe/x86_64/repodata/68a846401998085575f92ce3a446345190661596f651c24649dd3d89663b585a-primary.sqlite.bz2: [Errno 12] Timeout on http://mirror.innosol.asia/remi/enterprise/6/safe/x86_64/repodata/68a846401998085575f92ce3a446345190661596f651c24649dd3d89663b585a-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
No package kernel-devel-2.6.32-431.3.1.el6.x86_64 available.
~~~

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=500,gid=500 vagrant /vagrant

The error output from the command was:

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

どうやら、ゲストとホストのバージョンが違うからマウントに失敗しているようだ。
というのはエラーメッセージでなんとなくわかった。

①ググった

Vagrantで共有フォルダのマウントに失敗するときの対処方法
vagrant up 時に shared folder の mount でエラーが発生する
[Vagrant]共有フォルダのマウントに失敗
CentOS 6.5とvagrant-vbguestで詰まる

②vagrant-vbguestというプラグインをインストール

vagrant up時に自動的に新しいバージョンのGuest Additionsに更新してくれる「vagrant-vbguest」というプラグインがあることを知り、それをインストールしました。

コマンドプロンプト
vagrant plugin install vagrant-vbguest
コマンドプロンプト
vagrant reload
 →エラー内容少し変わったけどエラー

③Guest環境でyum updateした

Guest(仮想マシン側)でyumを更新するといいという情報があったので、
まずはGuestにSSH接続。
(マウントエラーが起きていても仮想マシンは起動しているので入れます。)
僕はPoderosaでSSH接続しました。

terminal
sudo yum update
 →エラー

エラー内容で調べるとversionlockというのが邪魔しているらしく、
とりあえずversionlockのファイルの中身を全部消してみた。

terminal
vi /etc/yum/pluginconf.d/versionlock.list
 →全部消す
terminal
sudo yum update
 →できた!

色々更新して、「やった!」と思いましたが、
アプリにアクセスすると何も動かない。。。
きっと何かのバージョンが変わって動かなくなったのでしょう。。

再度vagrant_boxを初めから作成。

④VirtualBoxのバージョンを古くする

そもそもバージョンの違いで動かないので、最初のエラーメッセージのバージョンを合わせたらいいのでは!と思い、
hostのVirtualBoxのバージョンを古くしてみることに。
[default] GuestAdditions versions on your host (5.1.14) and guest (4.3.6) do not match.

・・・macOS SierraではVirtualBox4.3.6はインストールできませんでした。。。

⑤カーネルデビルをインストール

再度エラーメッセージを読み直す。
No package kernel-devel-2.6.32-431.3.1.el6.x86_64 available.
ん、なんかパッケージが無いって言ってる?

色々調べてみるとこのパッケージをインストールするといいらしいことがわかった。
GuestにSSH接続して下記コマンドでインストール。

terminal
sudo yum install http://vault.centos.org/6.5/updates/x86_64/Packages/kernel-devel-2.6.32-431.3.1.el6.x86_64.rpm

上記のkernel-devel-2.6.32-431.3.1.el6.x86_64.rpmこの部分は、ご自身の環境で必要なバージョンをインストールしてください。
パッケージ一覧

コマンドプロンプト
vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
[default] GuestAdditions 5.1.14 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/tamoto/develop3/vagrant_box
    default: /var/www/subscription => C:/Users/tamoto/develop3/mikata_contents

できたーーー!

まとめ

開発環境構築ってハマるとすんごいハマりますね。
解決できると楽しいですね。

5
5
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
5