いつかエンジニアになりたい

Nothing is too late to start

vagrant up時に「mount: unknown filesystem type 'vboxsf'」が発生する

概要

  • VagrantでUbuntu15.04のBoxを利用しようとした際に以下の Error が出た
mount: unknown filesystem type 'vboxsf'
  • boxに「VirtualBox Guest Additions」がインストールされていなかったのが原因だった

環境

問題

  • Ubuntu15.04のVagrantboxを取得し、起動しようとしたが、以下のエラーが発生
% mkdir TestDir; cd $_
% vagrant box add ubuntu15.04 https://github.com/kraksoft/vagrant-box-ubuntu/releases/download/15.04/ubuntu-15.04-amd64.box
% vagrant box list
ubuntu15.04 (virtualbox, 0)
% vagrant init ubuntu15.04
% vagrant up --provider=virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu15.04'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: TestDir_default_1453617483205_59253
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.22_Ubuntu r98236
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/daicho/Work/DevEnv/ubuntu1504/TestDir
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:
stdin: is not a tty
mount: unknown filesystem type 'vboxsf'

原因

  • GuestOS内に「Virtualbox Guest Additions」がない、もしくはバージョンが違う
  • 実際にログインしてみてもコマンドがない
vagrant@vagrant-ubuntu-trusty:/usr/bin$ vboxsf
vboxsf: command not found

解決策

策1) GuestOS内に「Virtualbox Guest Additions」を手動インストールする

  • GuestOSにSSHログインする
% vboxmanage --version
5.0.10r104061
% vagrant ssh
Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic x86_64)
 * Documentation:  https://help.ubuntu.com/
New release '15.10' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Sun Jan 24 06:43:12 2016 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty:~$
vagrant@vagrant-ubuntu-trusty:~$ wget http://download.virtualbox.org/virtualbox/5.0.14/VBoxGuestAdditions_5.0.14.iso
vagrant@vagrant-ubuntu-trusty:~$ sudo mkdir /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ sudo mount -o loop,ro VBoxGuestAdditions_5.0.14.iso /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
vagrant@vagrant-ubuntu-trusty:~$ rm VBoxGuestAdditions_5.0.14.iso
vagrant@vagrant-ubuntu-trusty:~$ sudo umount /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ sudo rmdir /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ exit
% vagrant reload
/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /usr in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.10.5/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /usr in PATH, mode 040777
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/daicho/Work/DevEnv/ubuntu1504/TestDir
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

※当たり前ですが公式ページにもインストール手順書いてありました

策2) Pluginの「vagrant-vbguest」をインストールしておく

vagrant-vbguest」を入れてくと、起動時にホスト側の「GuestAdditions」をゲスト側にインストールしてくれる

  • vagrant-vbguest」をインストールする
% sudo vagrant plugin install vagrant-vbguest
% vagrant vbguest --status
GuestAdditions 5.0.10 running --- OK.
  • 通常通り「vagrant up」すると自動でインストールされる
% vagrant up --provider=virtualbox
/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /usr in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.10.5/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /usr in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu15.04'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: TestDir_default_1453619815489_18864
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
GuestAdditions versions on your host (5.0.10) and guest (4.3.22_Ubuntu r98236) do not match.
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
linux-headers-3.19.0-15-generic is already the newest version.
linux-headers-3.19.0-15-generic set to manually installed.
The following NEW packages will be installed:
  dkms
0 upgraded, 1 newly installed, 0 to remove and 41 not upgraded.
Need to get 65.5 kB of archives.
After this operation, 351 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ vivid/main dkms all 2.2.0.3-2ubuntu3 [65.5 kB]
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Fetched 65.5 kB in 4s (14.9 kB/s)
Selecting previously unselected package dkms.
(Reading database ... 60906 files and directories currently installed.)
Preparing to unpack .../dkms_2.2.0.3-2ubuntu3_all.deb ...
Unpacking dkms (2.2.0.3-2ubuntu3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up dkms (2.2.0.3-2ubuntu3) ...
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.10 - guest version is 4.3.22_Ubuntu r98236
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 5.0.10. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
stdin: is not a tty
Restarting VM to apply changes...
==> default: Attempting graceful shutdown of VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/daicho/Work/DevEnv/ubuntu1504/TestDir

まとめ

VirtualBoxのVagrantBoxを作成する際はしっかりとVirtualbox Guest Additionsをいれてあげるのは大事だが、 結局利用するホスト側のバージョンはいろいろなので、プラグイン入れておく。

参考