Parallels Desktopの環境でVagrantをインストール(失敗込み)

ホントよく分からずやってますm(_ _)m
参考:VagrantをParallelsで使う - ペリャウドのプログラミングとか(第2期)

Vagrant インストール

Download Vagrant - Vagrant
からインストール。 8/17 現在では 1.6.3 。

Parallels で使うための Parallels provider をインストール

Vagrant Parallels Provider Documentation
に従ってやっていく。

Since the Parallels provider is a Vagrant plugin, installing it is easy:

$ vagrant plugin install vagrant-parallels

The Vagrant plugin installer will automatically download and install vagrant-parallels plugin.
Installing Vagrant - Vagrant Parallels Provider Documentation

とのことなのでやってみる。

$ vagrant plugin install vagrant-parallels
Installing the 'vagrant-parallels' 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
of libxml2.

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
	- 0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch
	- 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-parallels (1.2.0)'!

なんか nokogiri のインストールがうるさいですね。
でもこれで Parallels provider のインストールが終わったようです。

Vagrant の provider として Parallels を使うように環境変数設定

Setting as default provider

You can use the VAGRANT_DEFAULT_PROVIDER environment variable to specify the default provider. Just set it to parallels and then it will not be necessary to add the --provider flag to vagrant commands.

export VAGRANT_DEFAULT_PROVIDER=parallels

You can also add this command to the ~/.bashrc file (or ~/.zshrc if your shell is Zsh) to make this setting permanent.
Usage - Vagrant Parallels Provider Documentation

ということで .bashrc に書いておきます。

新しい project を立ち上げる(Parallels の設定ミスで失敗)

New project setup

Create a new directory and init the new Vagrant project in it:

$ mkdir new_vagrant_project
$ cd new_vagrant_project
$ vagrant init parallels/centos-6.5
$ vagrant up --provider=parallels

Vagrant will automatically download and import the box and create a new virtual machine form it. The virtual machine will then be configured and started.
When the virtual machine is up and running, you can log in to it via SSH:

$ vagrant ssh

You can use any of the available vagrant commands to control your virtual machine.
For example, you can run vagrant halt to gracefully shut it down, or vagrant destroy to remove it completely.
Getting Started - Vagrant Parallels Provider Documentation

これに愚直に従って CentOS 6.5 を入れてみましょうかね。
なお、公式の Box(と呼ぶのが正しいのかな?)は

で確認することが出来ます。8/17 現在だと parallels/ubuntu-14.04 とか parallels/centos-6.5 とか。
…いや、非公式を含めると
[https://vagrantcloud.com/search?provider=parallels:title=Vagrant Cloud]
が Parallels 用の全リストになるのか。

さて。
入れるフォルダは /Volumes/new_exthdd/Vagrant/new_vagrant_project/ に作ってあるとします。

/Volumes/new_exthdd/Vagrant/new_vagrant_project/ $ vagrant init parallels/centos-6.5
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

さきほど環境変数を設定したので vagrant up のオプションは付けずに実行してみます。

/Volumes/new_exthdd/Vagrant/new_vagrant_project/ $ vagrant up
Bringing machine 'default' up with 'parallels' provider...
==> default: Box 'parallels/centos-6.5' could not be found. Attempting to find and install...
    default: Box Provider: parallels
    default: Box Version: >= 0
==> default: Loading metadata for box 'parallels/centos-6.5'
    default: URL: https://vagrantcloud.com/parallels/centos-6.5
==> default: Adding box 'parallels/centos-6.5' (v0.2.0) for provider: parallels
    default: Downloading: https://vagrantcloud.com/parallels/centos-6.5/version/2/provider/parallels.box
  :(ここでダウンロード)
==> default: Successfully added box 'parallels/centos-6.5' (v0.2.0) for 'parallels'!
==> default: Importing base box 'parallels/centos-6.5'...
There was an error while command execution. The command and stderr is shown below.

Command: ["prlctl", "clone", "484d97d9-55a4-441d-a70b-9d853e25a4a7", "--name", "centos64-veewee_1408288308282_86506"]

Stderr: 
Failed to clone the VM: The folder "/Volumes/old_exthdd/Parallels" used to store the virtual machine files is not available. Make sure that this folder exists and the device where it is located is connected to your Mac.

…外付けHDDのフォルダに入れたのがマズかったようですね。

いや、old_exthdd(プライバシー保護のため名前を変えてます)はこれ以前に使っていた外付けHDDの名前だ。
ということは Parallels Desktop の設定に問題がある。
Parallels Desktop 9 の「環境設定>一般>仮想マシンのフォルダ」を /Volumes/new_exthdd/Parallels/ に変更してみよう。というか、なぜ変更してなかったんだ>俺。そして /Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/ で作業しましょう。

仕切り直し(Parallels Toolsのエラーは出ているがいちおう動いた)

/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/ $ vagrant up
Bringing machine 'default' up with 'parallels' provider...
==> default: Importing base box 'parallels/centos-6.5'...
==> default: Checking if box 'parallels/centos-6.5' is up to date...
==> default: Setting the name of the VM: new_vagrant_project_default_1408288944865_26668
==> default: Preparing network interfaces based on configuration...
    default: Adapter 0: shared
==> default: Clearing any previously set network interfaces...
==> default: Setting power consumption mode: "Longer battery life"
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 10.211.55.12:22
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!
==> default: Checking for Parallels Tools installed on the VM...
==> default: Parallels Tools installed on this VM are outdated! In most cases
==> default: this is fine but in rare cases it can cause things such as shared
==> default: folders to not work properly. If you see shared folder errors,
==> default: please update Parallels Tools within the virtual machine and 
==> default: reload your VM.
==> default: Mounting shared folders...
    default: /vagrant => /Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project

だめだった。でもいま入れたばかりの VM なのに

Parallels Tools installed on this VM are outdated!

って何でよ。あと shared folder も使えてない。(← shared folder の意味が分かってなかった)

Parallels Tools Auto-Update 設定を Vagrant ファイルに追加

Parallels Tools Auto-Update

Parallels Tools is a set of Parallels utilities that ensures a high level of integration between the host and the guest operating systems (read more: Parallels Tools Overview).
By default, the Parallels provider checks the status of Parallels Tools after booting the machine. If they are outdated or newer, a warning message will be displayed.
You can configure the Parallels provider to update Parallels Tools automatically:

config.vm.provider "parallels" do |v|
  v.update_guest_tools = true
end

This option is disabled by default because of Parallels Tools installation takes a significant time (2-6 minutes). Anyway, it runs only when there is a version mismatch.

Vagrant ファイルの末尾に

config.vm.provider "parallels" do |v|
  v.update_guest_tools = true
end

を追加してみた。

$ vagrant up
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.

Path: /Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/Vagrantfile
Message: undefined local variable or method `config' for main:Object

そうか、もともとの

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  :
end

のブロックの中に入れなきゃダメですね^^;
ではブロック末尾に

config.vm.provider "parallels" do |v|
  v.update_guest_tools = true
end

を追加。

$ vagrant up
Bringing machine 'default' up with 'parallels' provider...
==> default: Checking if box 'parallels/centos-6.5' is up to date...
==> default: Parallels Desktop VM is already running.

あれ?既に立ち上がってる?ってことは…いちおう Parallels Tools の問題はあったけども、さっきから起動していたのね。
では vagrant ssh で動作確認。

$ vagrant ssh
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ pwd
/home/vagrant
[vagrant@localhost ~]$ date
2014年  8月 18日 月曜日 00:47:35 JST
[vagrant@localhost ~]$ logout
Connection to 10.211.55.12 closed.

うん、動いてる。
では落としてみよう。

$ vagrant halt
==> default: Attempting graceful shutdown of VM...

落ちてるはずなので vagrant ssh はエラーが出るはず。

$ vagrant ssh
==> default: VM is not currently running. Please, first bring it up with `vagrant up` then run this command.

うん、エラーだ。
では再度起動させよう。

$ vagrant up
Bringing machine 'default' up with 'parallels' provider...
==> default: Checking if box 'parallels/centos-6.5' is up to date...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 0: shared
==> default: Clearing any previously set network interfaces...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 10.211.55.12:22
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection refused. Retrying...
==> default: Machine booted and ready!
==> default: Checking for Parallels Tools installed on the VM...
==> default: Parallels Tools installed on this VM are outdated! In most cases
==> default: this is fine but in rare cases it can cause things such as shared
==> default: folders to not work properly. If you see shared folder errors,
==> default: please update Parallels Tools within the virtual machine and 
==> default: reload your VM.
==> default: Installing the proper version of Parallels Tools. This may take a few minutes...
==> default: Mounting shared folders...
    default: /vagrant => /Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

Parallels Tools のインストールに時間が掛かったけど、これでエラーなく動きました。

不可視フォルダ .vagrant の中身

/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/ $ ls -alF
total 16
drwxr-xr-x  4 riocampos  staff   136  8 18 00:05 ./
drwxr-xr-x  4 riocampos  staff   136  8 18 00:04 ../
drwxr-xr-x  3 riocampos  staff   102  8 18 00:05 .vagrant/
-rw-r--r--@ 1 riocampos  staff  4906  8 18 00:41 Vagrantfile
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/ $ cd .vagrant/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/ $ ls -alF
total 0
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 ./
drwxr-xr-x  4 riocampos  staff  136  8 18 00:05 ../
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 machines/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/ $ cd machines/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/machines/ $ ls -alF
total 0
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 ./
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 ../
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 default/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/machines/ $ cd default/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/machines/default/ $ ls -alF
total 0
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 ./
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 ../
drwxr-xr-x  7 riocampos  staff  238  8 18 00:22 parallels/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/machines/default/ $ cd parallels/
/Volumes/new_exthdd/Parallels/Vagrant/new_vagrant_project/.vagrant/machines/default/parallels/ $ ls -alF
total 40
drwxr-xr-x  7 riocampos  staff  238  8 18 00:22 ./
drwxr-xr-x  3 riocampos  staff  102  8 18 00:05 ../
-rw-r--r--  1 riocampos  staff   40  8 18 00:22 action_provision
-rw-r--r--  1 riocampos  staff   10  8 18 00:22 action_set_name
-rw-r--r--  1 riocampos  staff   36  8 18 00:22 id
-rw-r--r--  1 riocampos  staff   32  8 18 00:22 index_uuid
-rw-r--r--  1 riocampos  staff  136  8 18 00:52 synced_folders

vagrant ssh で VM 内をうろつく

 $ vagrant ssh
Last login: Mon Aug 18 00:46:50 2014 from 10.211.55.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ ls
[vagrant@localhost ~]$ ls -alF
合計 28
drwx------  3 vagrant vagrant 4096  8月 18 00:47 2014 ./
drwxr-xr-x. 5 root    root    4096  4月 19 05:51 2014 ../
-rw-------  1 vagrant vagrant   14  8月 18 00:47 2014 .bash_history
-rw-r--r--  1 vagrant vagrant   18  7月 18 22:19 2013 .bash_logout
-rw-r--r--  1 vagrant vagrant  176  7月 18 22:19 2013 .bash_profile
-rw-r--r--  1 vagrant vagrant  124  7月 18 22:19 2013 .bashrc
drwx------  2 vagrant root    4096  4月 19 05:51 2014 .ssh/
[vagrant@localhost ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr(中略)+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key
[vagrant@localhost ~]$ cd /
[vagrant@localhost /]$ ls -alF
合計 102
dr-xr-xr-x. 23 root    root     4096  8月 18 00:48 2014 ./
dr-xr-xr-x. 23 root    root     4096  8月 18 00:48 2014 ../
-rw-r--r--   1 root    root        0  8月 18 00:48 2014 .autofsck
-rw-r--r--   1 root    root        0  4月 19 05:49 2014 .autorelabel
dr-xr-xr-x.  2 root    root     4096  4月 19 05:50 2014 bin/
dr-xr-xr-x.  5 root    root     1024  8月 18 00:51 2014 boot/
drwxr-xr-x  18 root    root     3680  8月 18 00:49 2014 dev/
drwxr-xr-x. 66 root    root     4096  8月 18 00:52 2014 etc/
drwxr-xr-x.  5 root    root     4096  4月 19 05:51 2014 home/
dr-xr-xr-x.  8 root    root     4096  4月 19 05:50 2014 lib/
dr-xr-xr-x.  9 root    root    12288  4月 19 05:51 2014 lib64/
drwx------.  2 root    root    16384  4月 19 05:46 2014 lost+found/
drwxr-xr-x.  4 root    root     4096  4月 19 05:52 2014 media/
drwxr-xr-x.  2 root    root     4096  9月 23 20:50 2011 mnt/
drwxr-xr-x.  3 root    root     4096  4月 19 05:50 2014 opt/
dr-xr-xr-x  92 root    root        0  8月 18 09:48 2014 proc/
dr-xr-x---.  3 root    root     4096  4月 19 05:50 2014 root/
dr-xr-xr-x.  2 root    root    12288  4月 19 05:51 2014 sbin/
drwxr-xr-x.  2 root    root     4096  4月 19 05:46 2014 selinux/
drwxr-xr-x.  2 root    root     4096  9月 23 20:50 2011 srv/
drwxr-xr-x  13 root    root        0  8月 18 09:48 2014 sys/
drwxrwxrwt.  4 root    root     4096  8月 18 00:52 2014 tmp/
drwxr-xr-x. 13 root    root     4096  4月 19 05:46 2014 usr/
drwxr-xr-x   1 vagrant vagrant   136  8月 18 00:05 2014 vagrant/
drwxr-xr-x. 17 root    root     4096  4月 19 05:46 2014 var/
[vagrant@localhost /]$ cd vagrant/
[vagrant@localhost vagrant]$ ls -alF
合計 4
drwxr-xr-x   1 vagrant vagrant  136  8月 18 00:05 2014 ./
dr-xr-xr-x. 23 root    root    4096  8月 18 00:48 2014 ../
drwxr-xr-x   1 vagrant vagrant  102  8月 18 00:05 2014 .vagrant/
-rw-r--r--   1 vagrant vagrant 4906  8月 18 00:41 2014 Vagrantfile

なるほど VM の /vagrant が Mac の Vagrantfileがあるディレクトリと共有してるわけか。理解できんかったorz

vagrant の Box はどこに

参考:vagrantのboxとか、vagrantコマンド周りがよくわからなくなった | もふもふ技術部
~/.vagrant.d/boxes/ 以下にありました。

~/.vagrant.d/boxes/ $ ls -alF
total 0
drwxr-xr-x   3 riocampos  staff  102  8 18 00:11 ./
drwxr-xr-x  10 riocampos  staff  340  8 18 01:00 ../
drwxr-xr-x   4 riocampos  staff  136  8 18 00:11 parallels-VAGRANTSLASH-centos-6.5/
~/.vagrant.d/boxes/ $ du -sh parallels-VAGRANTSLASH-centos-6.5/
2.1G	parallels-VAGRANTSLASH-centos-6.5/
$ vagrant box list
parallels/centos-6.5 (parallels, 0.2.0)

Box を内蔵 HDD の中に置きたくないんだけどなぁ…

vagrant halt

では終了します。

$ vagrant halt
==> default: Attempting graceful shutdown of VM...