vagrantのshared folderのmountに失敗してしまった場合

  • 12
    Like
  • 0
    Comment
More than 1 year has passed since last update.

環境

HostOS: MacOS 10.10.2
Getst: CentOS 7.2
vagrant: 1.8.1

症状

一度仮想環境を終了した後に, 再びvagrant upで再起動を行った際に, shared folderのmountに失敗したとのログが表示される.
起動したゲストOSへはSSHでログインすることができる.

Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

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

原因

調べたところ, VirtualBoxでディレクトリ共有を行うために使っているVirtualboxGuestAdditionというツールのバージョンが, ホストとゲストでずれているとこのような問題がおこるらしい.
仮想環境を作った初期状態では当然ずれていないのですが, ゲストOSのカーネルを更新したりすると、こういった問題が起こるらしい(そして, yum updateするとカーネルは更新されるらしい)
なので, このバージョンのズレを解決してやればよい

解決法

vagtantのvbguestというpluginを導入して, 実行してやればよし.

$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Installed the plugin 'vagrant-vbguest (0.11.0)'!

$ vagrant vbguest
GuestAdditions versions on your host (5.0.20) and guest (4.3.30) do not match.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* rpmforge: ftp.riken.jp
* updates: ftp.iij.ad.jp
Package kernel-devel-3.10.0-327.18.2.el7.x86_64 already installed and latest version
Package gcc-4.8.5-4.el7.x86_64 already installed and latest version
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Package 4:perl-5.16.3-286.el7.x86_64 already installed and latest version
Package bzip2-1.0.6-13.el7.x86_64 already installed and latest version
Nothing to do
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.20 - guest version is 4.3.30
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.20 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.30 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules[  OK  ]
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules[  OK  ]
Doing non-kernel setup of the Guest Additions[  OK  ]
Starting the VirtualBox Guest Additions Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
[  OK  ]

ログを見ると, 最初にバージョンのズレを検出して, あとはなんやかんやリビルドをしているみたいですね.
実行後に一応状態を確認してみると

$ vagrant vbguest --status
GuestAdditions 5.0.20 running --- OK.

無事, バージョンのズレは解決しました.
あとは, 仮想環境を再起動してやればOK

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
......
==> default: Machine booted and ready!
GuestAdditions 5.0.20 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/xxx/src
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`

無事問題は解決しました

参考

VirtualBoxの/vagrantがマウントに失敗: http://tech.withsin.net/2015/07/10/virtualbox-vagrant-mount-fail/