memo.xight.org

日々のメモ

カテゴリ : vagrant

1ページ目 / 全1ページ

Macで vagrant + vagrant cloud

Summary

1. vagrant 1.5以降にupgrade
2. vagrant cloudのアカウント作成
3. vagrant cloudにログイン
4. vagrant cloudのboxをaddする

vagrant 1.5 以降にupgrade

% brew cask install vagrant

% vagrant -v
Vagrant 1.6.3

% vagrant plugin list
vagrant-login (1.0.1, system)
vagrant-share (1.1.0, system)

vagrant cloud のアカウント作成

vagrant cloud からアカウント作成


vagrant cloud にログイン

% vagrant login
In a moment we'll ask for your username and password to Vagrant Cloud.
After authenticating, we will store an access token locally. Your
login details will be transmitted over a secure connection, and are
never stored on disk locally.

If you don't have a Vagrant Cloud account, sign up at vagrantcloud.com

Username or Email: YOUR USERNAME
Password (will be hidden):
You're now logged in!

vagrant cloud の boxを追加

% vagrant box add chef/debian-7.4
vagrant box add chef/debian-7.4
==> box: Loading metadata for box 'chef/debian-7.4'
	box: URL: https://vagrantcloud.com/chef/debian-7.4
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) virtualbox
2) vmware_desktop

Enter your choice: 1
==> box: Adding box 'chef/debian-7.4' (v1.0.0) for provider: virtualbox
	box: Downloading: https://vagrantcloud.com/chef/debian-7.4/version/1/provider/virtualbox.box
==> box: Successfully added box 'chef/debian-7.4' (v1.0.0) for 'virtualbox'!

vagrant up する

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "chef/debian-7.4"
  config.vm.box_url = "https://vagrantcloud.com/chef/debian-7.4/version/1/provider/virtualbox.box"

  config.vm.network :forwarded_port, guest: 80, host: 8080
  config.vm.provision "shell", inline: <<-EOT
	aptitude update
	apt-get install -y apache2
	rm -rf /var/www
	ln -fs /vagrant /var/www
	echo "<h1>Hello, Vagrant Cloud.</h1>" > /vagrant/index.html
  EOT
end


% vagrant up

Reference

わすれっぽいきみえ - 2014-04-05 - vagrantのboxをvagrant cloudからもらってくる
http://kimikimi714.hatenablog.com/entry/2014/04/05

Qiita - Mac OS XでVagrantとChefを使った環境構築のまとめ
http://qiita.com/hamichamp/items/e27a0ecacc33482936c8

vagrant の Shared folder が共有できない

Summary

vagrant up の際、以下メッセージが表示される。
そして、vagrant の Shared folder が共有できない。

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mkdir -p /vagrant

Stdout from the command:



Stderr from the command:

sudo: no tty present and no askpass program specified

vbox の問題のようなので、 vbox をリビルドする。

# aptitude install build-essential module-assistant
# aptitude install linux-headers-amd64
# export KERN_DIR=/usr/src/linux-headers-X.X.X-X-amd64
# /etc/init.d/vboxadd setup
Removing existing VirtualBox non-DKMS kernel modules ...done.
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.

Building the main Guest Additions module ...done.
Building the shared folder support module ...done.
Building the OpenGL support module ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

しかし、改善されない。
未解決...

Reference

シドニーで働くプログラマーのBLOG - 2012-05-22 - Vagrantでmountエラーで、フォルダがShareされない
http://blog.mizoshiri.com/archives/1390

メモ超 - 2010-12-04 - CentOS5へのVBoxLinuxAdditionsインストール
http://d.hatena.ne.jp/calcul8/20101204/1291457686

VBoxGuestAdditions の update

Summary

VirtualBox と Guest Additions のバージョンに差異がある場合、
vagrant up 時に、以下の様なメッセージが表示される。

[default] The guest additions on this VM do not match the installed version of
VirtualBox! In most cases this is fine, but in rare cases it can
cause things such as shared folders to not work properly. If you see
shared folder errors, please update the guest additions within the
virtual machine and reload your VM.

Guest Additions Version: 4.1.8
VirtualBox Version: 4.2

/opt/VBoxGuestAdditions-4.1.8 と Guest Addtions のバージョンが古いようだ。
これを新しいバージョンに更新する。

ホスト側で VirtualBox.app 内の isoをマウント

/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso をコピー

ゲスト側で VBoxGuestAdditions.iso をマウント

$ sudo mount /dev/cdrom /media/cdrom
[sudo] password for vagrant:
mount: block device /dev/sr0 is write-protected, mounting read-only

これで ゲスト側の /media/cdrom 内から VBoxGuestAdditions.iso が参照できる。

VBoxGuestAdditions の更新

$ cd /media/cdrom0
$ ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.2.18 Guest Additions for Linux............
This program must be run with administrator privileges.  Aborting
vagrant@debian:/media/cdrom0$ sudo ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.2.18 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.1.8 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules ...done.
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.

Building the main Guest Additions module ...done.
Building the shared folder support module ...done.
Building the OpenGL support module ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

Installing the Window System drivers ...fail!
(Could not find the X.Org or XFree86 Window System.)

VBoxGuestAdditions の更新確認

$ ls /opt
VBoxGuestAdditions-4.2.18
$ /opt/VBoxGuestAdditions-4.2.18/bin/VBoxControl --version
4.2.18r88780

VirtualBoxの再起動

ホスト側で vagrant halt または ゲスト側で sudo shutdown -h now
ホスト側で vagrant up

これで、 VBoxGuestAdditions が更新できた。