nmtysh.log

Tech系のネタや日々の独り言などを書いています。

Vagrantのboxを作る(CentOS 6.5 x86_64 リメイク)

色々あって作り直し
Vagrant 1.4.xで作成しました

[構成]

CentOS 6.5 x86_64
 CentOS-6.5-x86_64-netinstall.iso
http://ftp.jaist.ac.jp/pub/Linux/CentOS/6.5/isos/x86_64/
・CPU 1コア
・MEM 768MB
・Disk
 ・Disk1 40GiB 可変
  ・/boot        500MiB ext4
  ・/(root)  36,363MiB ext4
  ・swap     4,096MiB
・ネットワーク
 ・NAT
  Intel PRO/1000 MT Desktop(8254OEM)


[設定]

・Domain
 localhost.localdomain
・Timezone
 Asia/Tokyo
 (System Clock UTC)
・言語
 Japanese
・キーボード
 US
・root
 vagrant


[パッケージ]

・日本語サポート
・ベースシステム


[OSインストール後]
1. アップデート

# yum update -y
# yum clean all
# shutdown -r now


2. vagrant ユーザー作成

# user add vagrant
# passwd vagrant
vagrant


3. sudoers

# visudo
vagrant ALL=(ALL) NOPASSWD: ALL

を追加 Defaults requiretty をコメントアウト

4. ssh keyを追加

# su - vagrant
$ mkdir .ssh
$ chmod 0700 .ssh
$ cd .ssh
$ wget https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O authorized_keys
$ chmod 0600 authorized_keys


5. sshd 設定

# vi /etc/ssh/sshd_config
UseDNS no
# /etc/init.d/sshd restart


6. grubタイムアウトを短くする

# vi /boot/grub/grub.conf
timeout=0


7. virtual box guest addon

# yum install kernel-devel gcc
# mount /dev/cdrom /media
# /media/VBoxLinuxAdditions.run
# umount /dev/cdrom


8. swapをなるべく使わない設定にする

# vi /etc/sysctl.conf
vm.swappiness = 0


9. SELinux無効化

# vi /etc/sysconfig/selinux
SELINUX=disabled
# shutdown -r now


10. 古いKernel削除

# package-cleanup --oldkernels --count=1
# package-cleanup --leaves
# yum remove libertas-usb8388-firemware-5.110.22.p23-3.1.el6.noarch


11. 履歴消去
(再ログイン)

# HISTIGNORE=*
# cat /dev/null > /home/vagrant/.bash_history
# cat /dev/null > ~/.bash_history


12. ゼロ埋め

# dd if=/dev/zero of=/zerofile
# rm -f /zerofile


13. 停止。ディスクファイル圧縮

# shutdown -h now
Hostで実行

$ VBoxManage modifyhd --compact "CentOS 6.5.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%


[boxを作成]

$ VBoxManage list vms
(省略)
"CentOS 6.5" {1e872bda-4127-4a4f-8947-00ba91d3decc}
$ vagrant package --base "CentOS 6.5" --output centos65.x86_64.20140301.box
[CentOS 6.5] Clearing any previously set forwarded ports...
[CentOS 6.5] Exporting VM...
[CentOS 6.5] Compressing package to: /Users/UserName/VirtualBox VMs/CentOS 6.5/centos65.x86_64.20140301.box


[test]

$ vagrant box add test "/Users/Username/VirtualBox VMs/CentOS6.5/centos65-x86_64_20131231.box"
$ vagrant init test
$ vagrant up



参考:
Creating a Base Box - Vagrant Documentation
vagrantでVirtualBox4.3用のbox作り方 (ubuntu13.10) - Qiita [キータ]