HPCメモ

HPC(High Performance Computing)に関連したりしなかったりすることのメモ書き

vagrant で modernIE

「せっかくだから、俺はこの銀の弁当箱を選ぶぜ!」くらいの勢いでMac miniを導入した私ですが、初っ端からwindows環境のお客様が続いています・・・
MSDNを導入するには予算オーバーだし、Macを買ってそうそうにwindowsのパッケージを買うのも負けた感があるので、modern IEで配ってるVMを使ってテスト環境を作るのが一番手っ取り早いんですが*1、ちょっと前まではvagrantから使うには一手間必要でした。

Setup modern.ie vagrant boxes · GitHub

が、いつの間にかMicrosoftからvagrantの形式でダウンロードできるようになっていたようです。

developer.microsoft.com

"Virtual Machine"のドロップダウンリストから必要なブラウザ&OSの組み合わせを選び、select platformの方のドロップダウンリストから"Vagrant"を選んで、下にある"Download Zip"ボタンを押すとVMをダウンロードすることができます。ただし、帯域制限しているのかうちの環境のせいかは不明ですが、1〜2MB/sec程度の転送レートになっちゃうので、ダウンロードするのに1時間くらいはかかります。*2


ひととおり、ダウンロードしてzipファイルを解凍するとこんな感じになります。

$ ls -s1
total 103168888
5017546388 IE10 - Win7.box
5017546668 IE10.Win7.Vagrant.zip
7378661428 IE11 - Win81.box
7378661710 IE11.Win81.Vagrant.zip
4496872696 IE8 - Win7.box
4496872974 IE8.Win7.Vagrant.zip
4800376728 IE9 - Win7.box
4800377006 IE9.Win7.Vagrant.zip
4717767002 MSEdge.Win10_RS1.Vagrant.zip
4717766724 dev-msedge.box

圧縮の意味が無いのはお約束 :p


とりあえずMS Edge+Win10のものを起動してみましょう。
最初にbox addコマンドでboxを追加しておきます。

 vagrant box add MSEdgeWin10 ./dev-msedge.box 
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'MSEdgeWin10' (v0) for provider: 
    box: Unpacking necessary files from: file:///Users/sogo/modernIE/dev-msedge.box
==> box: Successfully added box 'MSEdgeWin10' (v0) for 'virtualbox'!

続いて、適当なディレクトリを作成してvagrant initでVagrantfileを作成します。

$ mkdir test
$ cd test
$ vagrant box list
MSEdgeWin10 (virtualbox, 0)
$ vagrant init MSEdgeWin10
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.

生成されたVagrantfileを編集して、中ほどにあるGUIの設定とメモリの設定を変更し、vramの設定を追加しておきます。
*3

config.vm.provider "virtualbox" do |vb|
  # Display the VirtualBox GUI when booting the machine
  vb.gui = true
  # Customize the amount of memory on the VM:
  vb.memory = "8192"
  vb.customize ["modifyvm", :id, "--vram", "256"]
end

でもってvagrant upするとvirtual boxのGUI画面が立ちあがって、そっちでWindows10が起動されます。
f:id:n_so5:20170113162619p:plain
コンソール側ではこんな感じで、延々とsshでのアクセスをしようとして失敗しタイムアウトしていますが、GUI使う分には問題無いです。気になる人は"config.vm.boot_timeout=5"とか適当に短いタイムアウト設定をVagrantfileに追加しておけば、コンソール側の処理も早く終わります。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'MSEdgeWin10'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: WORK_default_1484292217879_22020
==> 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: Running 'pre-boot' VM customizations...
==> 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...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

しかし、実はこのwindowsゲスト内では、sshdが上がっているようでコマンドプロンプトを開いてlocalhostsshすると入れます。
f:id:n_so5:20170113225238p:plain
せっかく用意してくれてるなら、使わないと申し訳ないので一旦vagrant haltしてVagrantfileに以下の設定を追加しましょう。

config.vm.guest = :windows
config.ssh.username = "IEUser"
config.ssh.password = "Passw0rd!"

vm.questの設定はsshの設定とは直接関係ありませんが、この設定を入れておかないとログインしてsudoしようとして次のようなエラーを吐いてこけます。

==> default: Mounting shared folders...
    default: /vagrant => /Users/n_so5/Google Drive
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mkdir -p /vagrant

Stdout from the command:



Stderr from the command:

sh: sudo: command not found

synced folderの設定くらいなら、使わなければ大丈夫なんですが、vagrant haltした時にはsudo shutdown -hしようとしてこけるので致命的です・・・

でもって、この設定を入れてvagrant upすると

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> 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: Running 'pre-boot' VM customizations...
==> 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: IEUser
    default: SSH auth method: password
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 5.0.20
    default: VirtualBox Version: 5.1
==> default: Mounting shared folders...
    default: /vagrant => /Users/n_so5/Google Drive
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.


最終的にできあがったVagrantfileはこんな感じになってます。

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "MSEdgeWin10"
  config.vm.guest = :windows

  config.ssh.username = "IEUser"
  config.ssh.password = "Passw0rd!"

  config.vm.provider "virtualbox" do |vb|
    vb.gui = true
    vb.memory = "8192"
    vb.customize ["modifyvm", :id, "--vram", "256"]
  end
end


ん、winrm? 何それ美味しいの?

*1:と思ってたけどAzureにもwindows7/8.1がテスト環境として用意されてるんですね。こっちでも良かったかもしれん・・・

*2:複数のVMを並行してダウンロードしてもこの転送レートになるので使う可能性があるなら全部ダウンロードしておいても良いかもしれません。

*3:vramの設定を入れておかないと、ゲストOSの画面をfull screenにした時に文句を言われます。