vagrant基本操作メモ (編集中)
こちらに記載されている内容を参考しました。
http://blog.raqda.com/vagrant/cli/index.html
vagrantコマンド一覧 - Qiita
Vagrantの使い方とコマンド一覧のまとめ - Qiita
Vagrant のコマンドをメモしておく - Programming log - Shindo200
■バージョン確認
$ vagrant --version Vagrant 1.7.2
■作成/編集/削除
$ vagrant reload $ vagrant destroy
■BOXサブコマンド
$ vagrant box add CentOS6.6 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box ダウンロードした実体は以下に格納される。 $HOME/.vagrant.d/boxes/
$ vagrant box -h Usage: vagrant box <subcommand> [<args>] Available subcommands: add list outdated remove repackage update For help on any individual subcommand run `vagrant box <subcommand> -h`
$ vagrant box list hashicorp/precise32 (virtualbox, 1.0.0) chef/centos-6.5 (virtualbox, 1.0.0) chef/centos-7.1 (virtualbox, 1.0.0)
$ vagrant box remove hashicorp/precise32 Box 'hashicorp/precise32' (v1.0.0) with provider 'virtualbox' appears to still be in use by at least one Vagrant environment. Removing the box could corrupt the environment. We recommend destroying these environments first: default (ID: 5b58c53dbf674efb872117bb6047f3ce) Are you sure you want to remove this box? [y/N] y Removing box 'hashicorp/precise32' (v1.0.0) with provider 'virtualbox'...
■ログイン/ログアウト
$ pwd /home/manatee/VagrantTest/testcentos65 $ vagrant ssh Last login: Sun Jul 5 23:03:31 2015 from 10.0.2.2 $ exit logout Connection to 127.0.0.1 closed.
■起動/停止/状態確認
$ pwd /home/manatee/VagrantTest/testcentos65 $ vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`. >|| $ vagrant suspend ==> default: Saving VM state and suspending execution... $ vagrant status Current machine states: default saved (virtualbox) To resume this VM, simply run `vagrant up`. $ vagrant halt ==> default: Discarding saved state of VM... $ vagrant status Current machine states: default poweroff (virtualbox) The VM is powered off. To restart the VM, simply run `vagrant up` $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'chef/centos-6.5' is up to date... ==> 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: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ==> 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: Connection timeout. Retrying... default: Warning: Remote connection disconnect. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /home/manatee/VagrantTest/testcentos65 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
「Failed to mount folders in Linux guest. This is usually because...」のエラーについては、以下情報を参考にして解消させました。
対応するまでデフォルト設定となっているゲストOSとの共有が有効になっていませんでした。
$ rpm -qf /etc/init.d/vboxadd-service ファイル /etc/init.d/vboxadd-service はどのパッケージにも属していません。 [vagrant@localhost ~]$ sudo /etc/init.d/vboxadd setup Removing existing VirtualBox non-DKMS kernel modules [ OK ] Building the VirtualBox Guest Additions kernel modules The headers for the current running kernel were not found. If the following module compilation fails then this could be the reason. The missing package can be probably installed with yum install kernel-devel-2.6.32-504.23.4.el6.x86_64 Building the main Guest Additions module [失敗] (Look at /var/log/vboxadd-install.log to find out what went wrong) Doing non-kernel setup of the Guest Additions [ OK ] $ sudo yum install kernel-devel-2.6.32-504.23.4.el6.x86_64 $ rpm -qa |grep kernel dracut-kernel-004-356.el6_6.2.noarch kernel-2.6.32-504.23.4.el6.x86_64 kernel-headers-2.6.32-504.23.4.el6.x86_64 kernel-firmware-2.6.32-504.23.4.el6.noarch kernel-devel-2.6.32-504.23.4.el6.x86_64 kernel-2.6.32-431.el6.x86_64 $ 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 [ OK ] Doing non-kernel setup of the Guest Additions [ OK ] Starting the VirtualBox Guest Additions [ OK ]
ネットワークの変更を行った後に起動
$ vim Vagrantfile $ vagrant reload ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'chef/centos-7.1' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Fixed port collision for 22 => 2222. Now on port 2200. ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 => 2200 (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2200 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /home/manatee/VagrantTest/testcentos71 ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: to force provisioning. Provisioners marked to run always will still run.