LoginSignup
8
8

More than 5 years have passed since last update.

リモート環境(LinuxへSSHしてNoGUIモード)でVeeweeを使ってのVirtualBox + Vagrant用のBoxの作成方法

Last updated at Posted at 2014-02-07

環境:

ホストOS : Debian wheezy
ゲストOS : FreeBSD 9.1

手順

1) Ruby 1.9.3p484 (rvmよりインストール)

2) Veewee (gem install veeweeよりインストール)

3) FreeBSD9.1をVirtualBOXへインストール

3-1) freebsd-9.1のveeweeテンプレートファイル初期化

veewee vbox define freebsd91 'freebsd-9.1-RELEASE-amd64'

3-2) definition.rb にてHDD, Memory, CPU等の設定を行う

3-3) veeweeのfreebsd-9.1のtemplate設定を変更しないとエラーになるので、以下をコメントアウト

vi definitions/freebsd91/definition.rb
#  :sudo_cmd => "cat '%f' | su -",
  :shutdown_cmd => "shutdown -p now",
#  :postinstall_files => [ "postinstall.csh"], :postinstall_timeout => "10000"

3-4) -n(noguiモード)でVirtualBoxへfreebsd-9.1をインストール

veewee vbox build -n freebsd91 

注意:veewee インストール失敗した場合

設定を変えて試みる場合
veewee vbox build -n -f freebsd91 

一旦消して試みる場合
veewee vbox destroy freebsd91 

3-5) インストールの確認

GuestOSへログインする

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 7222 -l vagrant 127.0.0.1

3-6) suモード移行時にパスワードなしを設定

pw usermod vagrant -G wheel

cat /etc/pam.d/su | sed "s/requisite/sufficient/" > tmp

mv tmp /etc/pam.d/su

注意:

  • VeeweeからGUIなしのGuestOSの起動は -n オプションを付けること
veewee vbox up -n freebsd91
  • GuesOS終了はsuモード移行時にパスワードなし設定しておくこと、設定後以下を実行
veewee vbox halt freebsd91

4) Boxファイルをexportする

veewee vbox export freebsd91

5) VirtualBoxへログインしてテンプレートのpostinstall.cshをインストール(オプション)

5-1)
ホストOSからpostinstall.cshをGuestOS FreeBSD9.1へcopyする

veewee vbox copy freebsd91 postinstall.csh .  

5-2) postinstallを実行する

su -

sh postinstall.csh

注意:

  • そのままインストールするとログインできなくなるので、sshの設定を確認すること

6) Vagrantに移行

6-1) vagrant typeのboxに移行

exportされたboxを登録

vagrant box add 'freebsd91' '/home/xxx/veewee/freebsd91.box'

6-2) vagrant初期化、VM起動、VMへ接続

vagrant init 'freebsd91'
vagrant up
vagrant ssh

設定しておくと便利なこと

  • vagrant sshパスワードなしでログインする

鍵生成

ssh-keygen -t rsa 

公開鍵をGuestOSに転送し、ファイル名をauthorized_keysにして, 600に設定

chmod 600 ~/.ssh/authorized_keys 

~/.vagrant.d/boxes/freebsd91/Vagrantfile に秘密鍵のpathを登録

Vagrant::Config.run do |config|
  # This Vagrantfile is auto-generated by `vagrant package` to contain
  # the MAC address of the box. Custom configuration should be placed in
  # the actual `Vagrantfile` in this box.
  config.vm.base_mac = "XXXXXXXXXXXX"
  config.ssh.private_key_path = "~/.ssh/id_rsa" 
end

その他

  • エラーがおきた場合にlog出力しておくと原因がわかるかも
VAGRANT_LOG=DEBUG vagrant up
8
8
0

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
8
8