あれこれ試したけど、意外と簡単だったので記録しておく。
前提
- virtual boxインストール済み(5.1.16)
- vagrantインストール済み(1.9.2)
- sshが使える
※Windowsの場合、sshコマンドはこちらを使うと楽かと https://github.com/PowerShell/Win32-OpenSSH/releases
Ubuntuを使う
vagrant init bento/ubuntu-16.04-i386
vagrant up --provider virtualbox
vagrant ssh
他のOSを使うには
こちらから順に辿っていくと、initしてupするためのコマンドが書いてあります。
https://atlas.hashicorp.com/bento/boxes/
ubuntu16.04(をvirtual boxで使う)の場合は最終的にこんなページにたどり着きます。
https://atlas.hashicorp.com/bento/boxes/ubuntu-16.04-i386/versions/2.3.1
共有フォルダをマウントできないエラーへの対処
こんなメッセージが出る場合。
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=900,gid=900 vagrant /vagrant
virtual box側で共有フォルダ設定を見直す
一旦vmを止める
vagrant halt
共有フォルダ追加
- virtual box起動し、該当vmを右クリックする。
- メニューから「設定」を選び、「共有フォルダ」タブに切り替える。
- Windows側で適当なフォルダを作る
- 画面内右端の「+」を押し、共有フォルダとして指定する。
- 「自動マウントする」にチェックを入れる
- 「永続化する」にチェックを入れる
- OKを押して共有フォルダの追加画面を閉じる。
- 既存の共有フォルダを右クリックして「除去」する
vm起動
vagrant up
(参考:「【 Virtual Box 】共有フォルダを介して、ホストOS(Windows 7) と ゲストOS(Debian/ MathLibre)でファイルやりとりするための設定」 http://qiita.com/HirofumiYashima/items/6044cfc64cfa3e84f97c)
これでもエラーが出る場合は次へ
バージョン不一致の解消
(参考:「Vagrantで共有フォルダのマウントに失敗するときの対処方法」 http://qiita.com/ozawan/items/9751dcfd9bd4c470cd82)
vagrant plugin install vagrant-vbguest
vagrant vbguest --status
#=> [default] GuestAdditions versions on your host (5.1.16) and guest (5.0.26) do not match.
vagrant vbguest
vagrant reload default