• このエントリーをはてなブックマークに追加


現象とその対策

VirtualBox を 4.3.8 から 4.3.10 に上げてから,以前のエントリ のような環境下で生成した vagrant box を up すると,次のようなエラーが出るようになりました:

% cd /path/to/myproj/vm/mysql
% vagrant up
...
GuestAdditions 4.3.10 running --- OK.
==> server: Checking for guest additions in VM...
==> server: Setting hostname...
==> server: Configuring and enabling network interfaces...
==> server: Mounting shared folders...
    server: /vagrant => /path/to/myproj/vm/mysql
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

エラーメッセージとかで検索したところ,次が目に入りました:

vagrant@projectX:~$ sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions

https://gist.github.com/AubreyHewes/9889323#file-gistfile1-sh-L31

GuestAdditions 関連のライブラリが適切な場所にない(?)ことが原因で,シンボリックリンクを張っておけば OK,ってことですかね.

Packer の provisioner に追記

...
    "provisioners": [
        {
            "type": "shell",
            "execute_command": "echo 'vagrant' | {{.Vars}} sudo -E -S sh '{{.Path}}'",
            "scripts": [
                ...
                "provisioners/_/vbox.sh",
                ...
            ]
        }
    ],
...

このスクリプトで VirtualBox GuestAdditions をインストールするまわりのことをしている(veewee が生成したのを拝借してるだけ)ので,これに次を追記しました:

# ref: https://gist.github.com/AubreyHewes/9889323
if [ ! -d /usr/lib/VBoxGuestAdditions ]; then
    ln -s /opt/VBoxGuestAdditions-$VBOX_VERSION/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
fi

vbox.sh 全体のスクリプトは次のような感じ:

# Without libdbus virtualbox would not start automatically after compile
apt-get -y install --no-install-recommends libdbus-1-3
 
# Remove existing VirtualBox guest additions
/etc/init.d/virtualbox-ose-guest-utils stop
rmmod vboxguest
aptitude -y purge virtualbox-ose-guest-x11 virtualbox-ose-guest-dkms virtualbox-ose-guest-utils
aptitude -y install dkms
 
# Install the VirtualBox guest additions
VBOX_VERSION=$(cat /home/vagrant/.vbox_version)
VBOX_ISO=VBoxGuestAdditions_$VBOX_VERSION.iso
mount -o loop $VBOX_ISO /mnt
yes|sh /mnt/VBoxLinuxAdditions.run
umount /mnt
 
# ここを追加!
# ref: https://gist.github.com/AubreyHewes/9889323
if [ ! -d /usr/lib/VBoxGuestAdditions ]; then
    ln -s /opt/VBoxGuestAdditions-$VBOX_VERSION/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
fi
 
# Cleanup
rm $VBOX_ISO

再度 vagrant up

現在の VM を棄てて,改めて Packer で生成した box を add しなおして,再度 up:

% cd /path/to/myproj/vm/mysql
% vagrant destroy
...
% vagrant box add --name myproj.mysql --force ...
...
% vagrant up
Bringing machine 'server' up with 'virtualbox' provider...
==> server: Importing base box 'myproj.mysql'...
==> server: Matching MAC address for NAT networking...
==> server: Setting the name of the VM: myproj-dev.mysql
==> server: Clearing any previously set network interfaces...
==> server: Preparing network interfaces based on configuration...
    server: Adapter 1: nat
    server: Adapter 2: bridged
==> server: Forwarding ports...
    server: 22 => 2222 (adapter 1)
    server: 22 => 55022 (adapter 1)
    server: 3306 => 55306 (adapter 1)
==> server: Running 'pre-boot' VM customizations...
==> server: Booting VM...
==> server: Waiting for machine to boot. This may take a few minutes...
    server: SSH address: 127.0.0.1:2222
    server: SSH username: vagrant
    server: SSH auth method: private key
    server: Error: Connection timeout. Retrying...
==> server: Machine booted and ready!
GuestAdditions 4.3.10 running --- OK.
==> server: Checking for guest additions in VM...
==> server: Setting hostname...
==> server: Configuring and enabling network interfaces...
==> server: Mounting shared folders...
    server: /vagrant => /path/to/myproj/vm/mysql
==> server: Running provisioner: shell...
    server: Running: /var/folders/vk/959p08hd1fxckylcr4gcflm80000gn/T/vagrant-shell20140408-12599-1yptuwn
...

shared folder に関するエラーなし!

念のため中を覗いてみます:

% vagrant ssh
Welcome to Ubuntu 13.04 (GNU/Linux 3.8.0-19-generic x86_64)
 
 * Documentation:  https://help.ubuntu.com/
Your Ubuntu release is not supported anymore.
For upgrade information, please visit:
http://www.ubuntu.com/releaseendoflife
 
New release '13.10' available.
Run 'do-release-upgrade' to upgrade to it.
 
Last login: Tue Apr  8 13:50:35 2014 from 10.0.2.2
vagrant@myproj-mysql-vm-dev:~$ ls -l /usr/lib/VBoxGuestAdditions
lrwxrwxrwx 1 root root 53 Apr  8 13:21 /usr/lib/VBoxGuestAdditions -> /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions
vagrant@myproj-mysql-vm-dev:~$ ls /vagrant/
Vagrantfile  etc  home  provisioner
vagrant@myproj-mysql-vm-dev:~$

大丈夫っぽい!