らんだむな記憶

blogというものを体験してみようか!的なー

Vagrant やってみよ(2)

VAGRANT_HOME = D:\Vagrant\.vagrant.d にしてやり直し。

vagrant box add ubuntu-18.04 package.box

これがまた時間がかかる。途中で %VAGRANT_HOME%\tmp 以下が肥大していき、多分一時的に「package.box」の倍くらいのサイズにまで膨れているのではないだろうか・・・。

==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'ubuntu-18.04' (v0) for provider:
    box: Unpacking necessary files from: file://D:/Vagrant/Ubuntu18.04/package.box
    box: Progress: 100% (Rate: 40.8M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'ubuntu-18.04' (v0) for 'virtualbox'!

完了すると tmp の下が消滅した。代わりに %VAGRANT_HOME%\boxes\ubuntu-18.04\0\virtualbox なんてものが生成され、その下に元の「package.box」と同じくらいのサイズの「box-disk001.vmdk」が出来ていた。
う~ん、気分的には一連の長い作業は .vdi → package.box → .vmdk の変換をしていただけのような気がする。 VBoxManage clonehd --format VMDKVMWare に乗り換える気持ちで直接変換しても良いのかもしれないとさえ思えるが、それをどう Vagrant に戻すのか分からないので、こんなもんと思うことにする。 .box はきっと配布用の中間フォーマットなのだろう。
念のために VirtualBox マネージャーを見てみるが、この時点で .vmdk が登録されているということはない。

(5)

vagrant init ubuntu-18.04

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.

と出る。

(6) Vagrantfile を作ったディレクトリ直下で

vagrant up

する。・・・遅い・・・
もしやと思い VirtualBox VMs を見ると「Ubuntu 18.04 1」が増えているー\(^O^)/
.vdi 版と .vmdk 版が登録されているという滑稽な状態・・・。折角「ubuntu-18.04」という名前で box を追加したのに、VirtualBox に戻ってくる際には元の VM の名前で戻ってきたか・・・

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu-18.04'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: Ubuntu1804_default_1545529587892_77157
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    ...

気が付いたら進んでたけど、なんかリトライを続けている・・・
なんでもいいけど観察をしてみると VirtualBox マネージャーでさっき追加された .vmdk 版の仮想マシンが実行中になり、タスクマネージャーでは「VBoxHeadless.exe」のプロセスが幾つか立ち上がっている。やっぱり、ヘッドレス起動した仮想マシンssh で繋ぐって仕組みか・・・

The provider for this Vagrant-managed machine is reporting that it
is not yet ready for SSH. Depending on your provider this can carry
different meanings. Make sure your machine is created and running and
try again. Additionally, check the output of `vagrant status` to verify
that the machine is in the state that you expect. If you continue to
get this error message, please view the documentation for the provider
you're using.

(7)まぁ、色々エラー出ててダメなんだけど、

ssh xxx@127.0.0.1 -p 2222

したら入れた。ここで xxx は元々の .vdi のユーザー名。ssh のクライアントとしては「Git Bash」に同梱の ssh を使った。