Virtualboxはインストール済みとする。
インストールはhttp://www.vagrantup.com/のDOWNLOADSをクリックして最新のバージョンをインストールする。記述時点はv1.2.7。
作業用ディレクトリを作る。
$ mkdir getting_started $ cd getting_started
初期設定を行う。
$ vagrant init
Vagrantfileができる。
起動する仮想マシンをダウンロードする。ここではUbuntu precise64。
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
起動するため設定ファイルを修正する。
VirtualboxのホストオンリーアダプターでIPアドレス192.168.50.12にする。
$ vi Vagrantfile
config.vm.box = "precise64_20130831" config.vm.network :private_network, ip: "192.168.50.12"
起動する。
$ vagrant up
起動を確認する。
$ vagrant status Current machine states: default running (virtualbox)
仮想マシンにログインする。
$ vagrant ssh
アップデートする。
$ sudo apt-get update $ sudo apt-get upgrade
アップデートでカーネルモジュールに更新があった場合、VirtualBoxの共有フォルダのマウントが失敗するためGuest Additionsをいれなおす。makeがないと失敗するためmakeも入れる。
$ sudo apt-get install make $ sudo /etc/init.d/vboxadd setup
起動することを確認する。
$ exit $ vagrant halt $ vagrant up
更新した仮想マシンをbox化する。
$ vagrant package $ vagrant box add precise64_yyyymmdd package.box $ vagrant box list $ rm package.box $ vagrant destroy precise64 Are you sure you want to destroy the 'default' VM? [y/N] y [default] Forcing shutdown of VM... [default] Destroying VM and associated drives...
Pluginをインストールする。
$ vagrant plugin install sahara Installing the 'sahara' plugin. This can take a few minutes... Installed the plugin 'sahara (0.0.15)'! $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... [default] Importing base box 'precise64_20130831'... [default] Matching MAC address for NAT networking... [default] Setting the name of the VM... [default] Clearing any previously set forwarded ports... [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Preparing network interfaces based on configuration... [default] Forwarding ports... [default] -- 22 => 2222 (adapter 1) [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! [default] Configuring and enabling network interfaces... [default] Mounting shared folders... [default] -- /vagrant
sandboxを有効にする
$ vagrant sandbox on 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
最後にcommitかonしたときに戻る
$ vagrant sandbox rollback
状態変更を記録。haltしてからのほうがはやい。
$ vagrant sandbox commit
sandboxを解除。最後にcommitかonに戻る。
$ vagrant sandbox off