azukipochette's weblog

memory dump (mini)

Vagrant + VMWare Provider を Windows で動かすまでの記録

Vagrant を Windows で実行する人はいろいろブログで見かけるが、VMWare Provider を使っている人はあまり見かけない。 公式プロバイダーなのだから、きっとアッサリ動くだろうと思ったらエラーがでてどはまりしてしまった。 同じシチュエーションになってしまう方もいると思うので、調査方法、回避策などを記録として書いておきたい。

エラーが文字化けで分からない

vagrant up をするとエラーが表示されるのだが、トーフが表示されて実際のエラー内容が分からない (要するに文字化け)。

Stdout: Error: ▯▯▯▯▯▯▯▯▯▯▯

Windows の言語が日本語なので、エラーは日本語で表示されているものの、文字コードの変換が正しくなく化けているようだ。 Vagrant は JRuby を使っているので、Java と JRuby の両方で日本語文字の表示方法を探すも、どうもコードを直さないと駄目なようなので断念。 素直に英語の言語バックを入れて、表示言語を変更。すると、次のエラーが出ていたことが分かる。

Stdout: Error: The operation was canceled

Michell Hashimoto 氏曰く、それは VMWare の問題

このエラーで Vagrant の Issue を探していると、下記の質問に当たる。

https://github.com/mitchellh/vagrant/issues/2944

Vagrant 作者の Michell Hashimoto 氏が次のように回答している。

Ah! I am very annoyed that VMware said it is my problem. The "The operation was canceled" error (fantastic in its vagueness), has always been a VMware problem to date. It can mean a variety of things, I've found out, none of which Vagrant can really detect or do anything about, especially because the error is so vague: - Virtualization extensions aren't enabled on the CPU - Your trial has expired or the application requires a license key - Permission problems on the install (corrupted install) - You need to fill out some form data in the GUI.

要するに曖昧なエラーなので原因は分からないが、VMWare 側の問題で発生しているよ、Vagrant のエラーじゃないよ、ということ。 考えられる原因が列挙されているも、どれも該当しているようには思えない。

VMWare のことは VMWare.log に聞け

VMware はログを生成しており、Vagrant の場合は .Vagrant フォルダ (隠しフォルダ) の配下にある VMX ファイルが置かれているフォルダと同じ場所に vmware.log ファイルが生成されている。 このファイルを開くと、次のエラーが記録されていることが分かる。

[msg.vmx.nestedHyperV] VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation.

簡単に訳せば "VMWare と Hyper-V には互換性はありません。VMWare の実行前にシステムから Hyper-V の役割を削除してください" という意味。 つまり、Hyper-V が有効になっていると、ホスト OS も仮想化されるため、その環境では VMWare は動作しない。VMWare を動かしたければ、その前に Hyper-V を止める必要があるというわけだ。

Hyper-V を止める

止める方法はいろいろあるが、Hyper-V を使うときもあるので Hyper-V の役割を削除したくはない。そこで、次のコマンドを実行してハイパーバイザを無効にすることにする。 コマンドの実行には管理者権限でコマンドプロンプトを起動する。

bcdedit /set hypervisorlaunchtype off

実行完了後、再起動して再度vagrant upをする。

PS C:\Vagrant> vagrant up
Bringing machine 'default' up with 'vmware_workstation' provider...
==> default: Checking if box 'alphainternational/centos-6.5-x64' is up to date...
==> default: Verifying vmnet devices are healthy...
==> default: Preparing network adapters...
==> default: Starting the VMware VM...
==> default: Waiting for the VM to finish booting...
==> default: The machine is booted and ready!
==> default: Forwarding ports...
    default: -- 22 => 2222
==> default: Configuring network adapters within the VM...
==> default: Waiting for HGFS kernel module to load...
==> default: Enabling and configuring shared folders...
    default: -- C:/Vagrant: /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.

動いた! ちなみに、ハイパーバイザーを戻すには次のコマンドを実行する必要がある。

bcdedit /set hypervisorlaunchtype auto