xengineer’s diary

結果、メモ的な内容になっています。

vagrantでvirtualboxのGuestAdditionを自動的にインストールするplugin

f:id:xengineer:20141005143410p:plain

vagrant!お世話になっております。
事の発端は、

$ vagrant ssh

して、

$ ls /vagrant

したら、ディレクトリが空っぽだったことにあるわけです。
あら?マウントされてないね。

と、思いまして。

どうやら、GuestAdditionがインストールされてなかったぽ。
これ、毎度インストールはめんどくさい・・・と思って、先生に問い合わせ。

"vagrant guest addition auto install"

で検索。
はい、答えどん!どどーん!!


dotless-de/vagrant-vbguest · GitHub

これを使います。
vagrant up時に、自動的にGuestAdditionに更新がないか確認して、
自動的にインストールしてくれるぷらぎん。

まず、

$ vagrant -v
Vagrant 1.6.3

version >= 1.1 なので、

$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
	- 0001-Fix-parser-local-buffers-size-problems.patch
	- 0002-Fix-entities-local-buffers-size-problems.patch
	- 0003-Fix-an-error-in-previous-commit.patch
	- 0004-Fix-potential-out-of-bound-access.patch
	- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
	- 0006-Do-not-fetch-external-parsed-entities.patch
	- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
	- 0008-Improve-handling-of-xmlStopParser.patch
	- 0009-Fix-a-couple-of-return-without-value.patch
	- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
	- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

However, note that nokogiri does not necessarily support all versions
 + all.sh
of libxml2.
 + ../Vagrantfile

For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Building libxslt-1.1.28 for nokogiri with the following patches applied:
	- 0001-Adding-doc-update-related-to-1.1.28.patch
 ~/.v/Vagrantfile
	- 0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch
 + ../Vagrantfile
	- 0003-Initialize-pseudo-random-number-generator-with-curre.patch
	- 0004-EXSLT-function-str-replace-is-broken-as-is.patch
	- 0006-Fix-str-padding-to-work-with-UTF-8-strings.patch
	- 0007-Separate-function-for-predicate-matching-in-patterns.patch
	- 0008-Fix-direct-pattern-matching.patch
	- 0009-Fix-certain-patterns-with-predicates.patch
	- 0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch
	- 0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch
	- 0014-Fix-for-bug-436589.patch
	- 0015-Fix-mkdir-for-mingw.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxslt.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install
************************************************************************
Installed the plugin 'vagrant-vbguest (0.10.0)'!

でインストールできます。
ワラワラでてきてるのは、nokogiriをビルドしてるからぽい。
僕の場合は気にしなくて大丈夫そうなので、待つ。

待ち時間がそこそこあったので、疲れ目に下記patchをあてつつ待つ。

元気になったので続き。

いくつか設定があるので設定。
まず、自動的に毎回チェックされるのはうざいので、グローバル設定を下記に突っ込んで、
デフォルトはチェックしない、にする。

~/.vagrant.d/Vagrantfile

Vagrant.configure("2") do |config|
  config.vbguest.auto_update = false
end

で、チェックしたいプロジェクトには、Vagrantfileに下記を突っ込む。

config.vbguest.auto_update = true

これで、vagrant reloadでもすればおっけい。

$ vagrant reload
==> wordpress01: Checking if box 'hashicorp/precise64' is up to date...
==> wordpress01: Clearing any previously set network interfaces...
==> wordpress01: Preparing network interfaces based on configuration...
    wordpress01: Adapter 1: nat
    wordpress01: Adapter 2: hostonly
==> wordpress01: Forwarding ports...
    wordpress01: 80 => 8080 (adapter 1)
    wordpress01: 22 => 2222 (adapter 1)
==> wordpress01: Running 'pre-boot' VM customizations...
==> wordpress01: Booting VM...
==> wordpress01: Waiting for machine to boot. This may take a few minutes...
    wordpress01: SSH address: 127.0.0.1:2222
    wordpress01: SSH username: vagrant
    wordpress01: SSH auth method: private key
    wordpress01: Warning: Connection timeout. Retrying...
==> wordpress01: Machine booted and ready!
GuestAdditions versions on your host (4.3.14) and guest (4.2.0) do not match.
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  fakeroot linux-headers-3.2.0-23 make
Suggested packages:
  make-doc
The following NEW packages will be installed:
  dkms fakeroot linux-headers-3.2.0-23 linux-headers-3.2.0-23-generic make
0 upgraded, 5 newly installed, 0 to remove and 162 not upgraded.
Need to get 12.6 MB of archives.
After this operation, 68.3 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main make amd64 3.81-8.1ubuntu1.1 [119 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main dkms all 2.2.0.3-1ubuntu3.2 [72.6 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise/main fakeroot amd64 1.18.2-1 [87.2 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ precise/main linux-headers-3.2.0-23 all 3.2.0-23.36 [11.4 MB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ precise/main linux-headers-3.2.0-23-generic amd64 3.2.0-23.36 [947 kB]
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Fetched 12.6 MB in 12s (1,044 kB/s)
Selecting previously unselected package make.
(Reading database ... 60110 files and directories currently installed.)
Unpacking make (from .../make_3.81-8.1ubuntu1.1_amd64.deb) ...
Selecting previously unselected package dkms.
Unpacking dkms (from .../dkms_2.2.0.3-1ubuntu3.2_all.deb) ...
Selecting previously unselected package fakeroot.
Unpacking fakeroot (from .../fakeroot_1.18.2-1_amd64.deb) ...
Selecting previously unselected package linux-headers-3.2.0-23.
Unpacking linux-headers-3.2.0-23 (from .../linux-headers-3.2.0-23_3.2.0-23.36_all.deb) ...
Selecting previously unselected package linux-headers-3.2.0-23-generic.
Unpacking linux-headers-3.2.0-23-generic (from .../linux-headers-3.2.0-23-generic_3.2.0-23.36_amd64.deb) ...
Processing triggers for man-db ...
Setting up make (3.81-8.1ubuntu1.1) ...
Setting up dkms (2.2.0.3-1ubuntu3.2) ...
Setting up fakeroot (1.18.2-1) ...
update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode.
Setting up linux-headers-3.2.0-23 (3.2.0-23.36) ...
Setting up linux-headers-3.2.0-23-generic (3.2.0-23.36) ...
Examining /etc/kernel/header_postinst.d.
run-parts: executing /etc/kernel/header_postinst.d/dkms 3.2.0-23-generic /boot/vmlinuz-3.2.0-23-generic
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: warning: /mnt seems to be mounted read-only.
Installing Virtualbox Guest Additions 4.3.14 - guest version is 4.2.0
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.14 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.2.0 of VirtualBox Guest Additions...
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 4.3.14. 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
==> wordpress01: Checking for guest additions in VM...
==> wordpress01: Setting hostname...
==> wordpress01: Configuring and enabling network interfaces...
==> wordpress01: Mounting shared folders...
    wordpress01: /vagrant => /Users/nemoto_hideaki/work/vagrant/project_ansible_wordpress
==> wordpress01: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> wordpress01: to force provisioning. Provisioners marked to run always will still run.

ログインして、インストールされてるかチェック。

$ ls /opt/
vagrant_ruby  VBoxGuestAdditions-4.3.14

ちなみに、僕は一発目は怒られた。

# less /var/log/vboxadd-install.log
(色々省略)
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (            \
        echo;                                                           \
        echo "  ERROR: Kernel configuration is invalid.";               \
        echo "         include/linux/autoconf.h or include/config/auto.conf are missing.";      \
        echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
        echo;                                                           \
        /bin/false)
(色々省略)

autoconf/automakeがインストールされてないと怒られるので、
bootstrapのshellに下記を突っ込んで解決。

apt-get install -y automake autoconf

うむ。完了。