Es Durの前立腺

支離滅裂

Vagrant簡単メモ

簡単に仮想環境が作れるツールVagrant
Rubyで作られてます。


Box追加

vagrant box add [box_name] [url]

boxはhttps://github.com/chef/bentoなどから取得



box一覧

vagrant box list


box削除

vagrant box remove [box_name]

仮想マシン起動

vagrant init [box_name]
vagrant up

vagrant initでカレントディレクトリにvagrantfileができる。
vagrant upで仮想サーバが起動する。


仮想マシンに接続

vagrant ssh

仮想マシン削除

vagrant destroy


仮想マシンシャットダウン

vagrant halt


仮想マシン再起動

vagrant reload


仮想マシン保留状態に

vagrant suspend

仮想マシンの保留状態解除

vagrant resume


仮想マシンIPアドレス設定
vagrantfileを修正します。

vim vagrantfile
...

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
   config.vm.network "private_network", ip: "111.222.33.44"

...

エラーが出る
yum updateしたらどうやらvagrantfile修正したらエラーが出るっぽい。
Vagrant 1.8.1

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

vagrant sshは可能だけど、ls /vagrantすると空っぽ。。。
本来ならホストOSのカレントディレクトリが共有されるから、vagrantfileが見えないと行けないんだけど、見えないってことは共有が出来てない。
ゲスト側のマウント関係が壊れたっぽいんで、再構築します。

sudo yum -y install kernel-devel
sudo yum -y install gcc
sudo /etc/init.d/vboxadd setup
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Building the OpenGL support module                         [失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions              [  OK  ]

OpenGLは失敗でも問題ないみたいなんで、再度vagrant reloadしてみてエラーが出なかったら、
ゲストOSにログインしてls /vagrantでvagrantfileがあればOK!


【追記】
CentOS 7.2ではvboxaddは以下。
「5.0.26」の部分は変わるみたい。

sudo /opt/VBoxGuestAdditions-5.0.26/init/vboxadd setup

あと、kernelをアップデートするほうが良いかもしれない。
結果としてよかった。

sudo yum update kernel*