Vagrant 1.8.1@Windows でフォルダの同期に rsync を使う

この辺の記事を見て、やってみようと思ったまでは良かったんだけど、いろいろつまづいたのでメモ。

qiita.com

使ったソフトのバージョン

やったこと

Vagrantfile でフォルダ共有の設定を以下のようにした

config.vm.synced_folder "d:\\Development\\hoge", "/vagrant",
  owner: "vagrant", group: "www-data",
  type: "rsync", rsync__exclude: [".git/", ".otto/", "Appfile", "Vagrantfile"]

以下、つまづいたことと、解決または回避策。

つまづき1: sshが終わらない

以下のメッセージが出た後、反応がまったくなくなる。

default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key

VirtualBoxGUIでログを確認したところ、DLLの読み込みに失敗しているようだった。

DLLを調べたところ、ネットワークドライバのものらしい。
どうしようもないのでネットワークドライバをアンインストール...orz
ので、現在有線LANが使えない。

ちなみにドライバは "Qualcomm Atheros Killer Network Manager"
あとから最新バージョン入れてみよう。

⇒ 最新版を入れたら解決した!!!

Killer Networking - Driver Downloads

つまづき2: rsync がない

chocolateyでrsyncをインストール。

つまづき3: rsyncで No such file or directory (2)

以下のようなエラーが出た。

There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.
...(略)
rsync: change_dir "/d/Development/hoge" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) atmain.c(1165) [sender=3.1.1]

[Vagrantインストールフォルダ]\embedded\etc\fstab に以下を追加する。

 d:  /cygdrive/d

つまづき4: rsyncで良く分からんエラー(1)

以下のようなエラーがでる。

There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.
...(略)
mm_receive_fd: no message header
process_mux_new_session: failed to receive fd 0 from slave
mux_client_request_session: read from master failed: Connection reset by peer
Failed to connect to new control master
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.1.1]

以下の回避策を適用。

github.com

つまづき3: rsyncで良く分からんエラー(2)

以下のようなエラーが出る。

C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/util/io.rb:32:in `encode': "\x8A" followed by "%" on Windows-31J (Encoding::InvalidByteSequenceError)
...(以下、スタックトレース)

外部エンコーディングWindows-31Jになっているのが問題らしい。 環境変数 RUBYOPT を設定する方向で回避できないか試行錯誤してみたものの、できなかった。 ので、以下を参考に io.rb を修正して回避。

Windows + Vagrant + Rails の比較的快適な環境を作る - みかづきメモ

embedでリンクが上手くできなかった...。

io.rb:32 修正前

data << io.readpartial(READ_CHUNK_SIZE).encode("UTF-8", Encoding.default_external)

io.rb:32 修正後

data << io.readpartial(READ_CHUNK_SIZE).force_encoding("UTF-8")

つまづき4: rsyncで良く分からんエラー(3)

以下のようなエラーが出る。

C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/providers/virtualbox/driver/version_5_0.rb:380:in `split': invalid byte sequence in UTF-8 (ArgumentError)
...(以下、スタックトレース)

上記と同じようなエラーっぽいので、 version_5_0.rb を修正して回避。

version_5_0.rb:380 修正前

execute("list", "bridgedifs").split("\n\n").collect do |block|

version_5_0.rb:380 修正後

execute("list", "bridgedifs").force_encoding('ASCII-8BIT').split("\n\n").collect do |block|

ということで動くようになりましたよ。