LoginSignup
5

More than 5 years have passed since last update.

Vagrant-vmware_fusionのboxを作るメモ

Last updated at Posted at 2013-06-08

作業しながら書いています。動作確認中。


独自のBoxを作ってみる。

VMWareFusionが想定以上にうまくいかないので、先にVirtualBoxでやってみる。

ベースVMの生成

VirtualBox側の設定

  • インストールメディア: CentOS-6.4-x86_64-netinstall.iso
  • ディスク: root.vmdk 8GB,分割なし
  • ネットワークアダプタ: 自動検出
  • プリンタ: 削除

CentOSのインストール設定

  • タイムゾーン: JST-9
  • キーボードレイアウト: jp106
  • minimumパッケージ
  • kerne-devel, gcc, make, perl: GuestAddinのために。
  • openssh-client, system-config-network-tui
  • ユーザー名 vagrant でユーザー生成、鍵もgithubのを配置。

トラブル

Box化して vagrant init & vagrant up すると eth0 が無効のまま起動。
=> sshが繋がらずハングしたようになる。

VirtualBoxから直接起動するとeth0のデバイスがない。

eth1として再構成してからpoweroffした後に vagrant up すると繋がった。

Box化して=>vagrant upした後にネットワークアダプタがうまく起動しない模様。謎。


ベースVMの生成

VMWareFusion側の設定

  • VM名: centos_6.4_x86_64_with_chef.vmwarevm
  • インストールメディア: CentOS-6.4-x86_64-netinstall.iso
  • ディスク: root.vmdk 8GB,分割なし
  • ネットワークアダプタ: 自動検出
  • プリンタ: 削除

CentOSのインストール設定

  • タイムゾーン: JST-9
  • キーボードレイアウト: jp106
  • minimumパッケージ

起動直後の設定

以下、VMが 192.168.228.133 で起動していると仮定。

ユーザーの追加

  • EC2に合わせてec2-userで作成。
  • .ssh/authorized_keysへ公開鍵をコピー

/etc/sudoersの変更

  • ssh経由のsudoを許可
  • ec2-userにpasswordなしのsudoを許可

sshdの設定

  • rootログインを禁止
  • passwordログインを禁止

VMWate Toolsのインストール

VMWareFusionのメニューから「VMWate Toolsのインストール」を選んでから:

[guest]$ mount /dev/cdrom /mnt
[guest]$ yum install -y perl
[guest]$ tar xf /mnt/VMWareTools-9.2.2-893683.tar.gz
[guest]$ cd vmware-tools-distrib
[guest]$ yes ""| ./vmware-install.pl

chef-clientのインストール

[guest]$ curl -L https://www.opscode.com/chef/install.sh | bash

vagrantで入れるなら

Vagrant.configure("2") do |config|
  :
  config.vm.provision :shell do |shell|
    shell.inline =<<-__SHELL__
curl -L https://www.opscode.com/chef/install.sh | bash
    __SHELL__
  end
end

しかしprovision毎にDownloadを含めて実行されて、ウザい。

Boxの生成

このへんを参考に

VMDiskの整理

[host]$ export PATH=/Applications/VMware\ Fusion.app/Contents/Library:$PATH
[host]$ cd centos_6.4_x86_64_with_chef.vmwarevm
[host]$ vmware-vdiskmanager -d root.vmdk
[host]$ vmware-vdiskmanager -k root.vmdk

metadata.jsonを記述

centos_6.4_x86_64_with_chef.vmwarevm/metadata.json
{
  "provider": "vmware_fusion"
}

Boxファイルの作成

[host]$ cd centos_6.4_x86_64_with_chef.vmwarevm
[host]$ tar cvzf ~/centos_6.4_x86_64_with_chef.box ./*

Boxの登録

[host]$ vagrant box add my_centos centos_6.4_x86_64_with_chef.box
[host]$ $ vagrant box list
my_centos (vmware_fusion)

起動

いまここ。

$ vagrant up --provider=vmware_fusion
Bringing machine 'default' up with 'vmware_fusion' provider...
[default] Verifying vmnet devices are healthy...
The VMware network device 'vmnet1' can't be started because
its routes collide with another device: 'en0'. Please
either fix the settings of the VMware network device or stop the
colliding device. Your machine can't be started while VMware
networking is broken.
$ open .vagrant/machines/default/vmware_fusion/vm.vmwarevm

とすると起動するしその後も

$ vagrant status
Current machine states:

default                  running (vmware_fusion)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down, or you can run `vagrant suspend` to simply suspend
the virtual machine. In either case, to restart it again, run
`vagrant up`.

と出る。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5