├── virtualbox.sh ├── Vagrantfile ├── README.md ├── vagrant.sh ├── .gitignore ├── cleanup.sh ├── LICENSE ├── packer.json └── ks.cfg /virtualbox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mount -o loop /home/vagrant/VBoxGuestAdditions.iso /mnt 4 | /mnt/VBoxLinuxAdditions.run 5 | umount /mnt 6 | rm -rf VBoxGuestAdditions.iso 7 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | config.vm.box = "centos7" 6 | config.vm.box_url = "./centos7.box" 7 | end 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | packer-centos-7 2 | === 3 | 4 | ``` 5 | vagrant init hfm4/centos7 6 | vagrant up 7 | ``` 8 | 9 | ### Box url 10 | 11 | - https://atlas.hashicorp.com/hfm4/boxes/centos7 12 | 13 | Build box 14 | --- 15 | 16 | ``` 17 | packer build packer.json 18 | ``` 19 | -------------------------------------------------------------------------------- /vagrant.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | install -v -o vagrant -g vagrant -m 0700 -d /home/vagrant/.ssh 5 | curl -o /home/vagrant/.ssh/authorized_keys -kL 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub' 6 | chown vagrant:vagrant /home/vagrant/.ssh/authorized_keys 7 | chmod 600 /home/vagrant/.ssh/authorized_keys 8 | 9 | cat <<'EOF' > /home/vagrant/.bash_profile 10 | [ -f ~/.bashrc ] && . ~/.bashrc 11 | export PATH=$PATH:/sbin:/usr/sbin:$HOME/bin 12 | EOF 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### https://raw.github.com/github/gitignore/170b9f808b34c9df63cbefb50c6b3517270755ec/Global/vagrant.gitignore 2 | 3 | .vagrant/ 4 | 5 | 6 | ### https://raw.github.com/github/gitignore/170b9f808b34c9df63cbefb50c6b3517270755ec/packer.gitignore 7 | 8 | # Cache objects 9 | packer_cache/ 10 | 11 | # For built boxes 12 | *.box 13 | 14 | 15 | ### https://raw.github.com/github/gitignore/170b9f808b34c9df63cbefb50c6b3517270755ec/Global/osx.gitignore 16 | 17 | .DS_Store 18 | .AppleDouble 19 | .LSOverride 20 | 21 | # Icon must ends with two \r. 22 | Icon 23 | 24 | # Thumbnails 25 | ._* 26 | 27 | # Files that might appear on external disk 28 | .Spotlight-V100 29 | .Trashes 30 | 31 | 32 | -------------------------------------------------------------------------------- /cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Remove Linux headers 4 | yum -y remove gcc kernel-devel kernel-headers perl cpp 5 | yum -y clean all 6 | 7 | # Remove Virtualbox specific files 8 | rm -rf /usr/src/vboxguest* /usr/src/virtualbox-ose-guest* 9 | rm -rf *.iso *.iso.? /tmp/vbox /home/vagrant/.vbox_version 10 | 11 | # Cleanup log files 12 | find /var/log -type f | while read f; do echo -ne '' > $f; done; 13 | 14 | # remove under tmp directory 15 | rm -rf /tmp/* 16 | 17 | # remove interface persistent 18 | rm -f /etc/udev/rules.d/70-persistent-net.rules 19 | 20 | for ifcfg in $(ls /etc/sysconfig/network-scripts/ifcfg-*) 21 | do 22 | if [ "$(basename ${ifcfg})" != "ifcfg-lo" ] 23 | then 24 | sed -i '/^UUID/d' /etc/sysconfig/network-scripts/ifcfg-enp0s3 25 | sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-enp0s3 26 | fi 27 | done 28 | 29 | dd if=/dev/zero of=/EMPTY bs=1M 30 | rm -rf /EMPTY 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Okumura Takahiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packer.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders": [ 3 | { 4 | "vm_name": "centos7", 5 | "guest_os_type": "RedHat_64", 6 | "iso_checksum_type": "sha256", 7 | "iso_checksum": "9ed9ffb5d89ab8cca834afce354daa70a21dcb410f58287d6316259ff89758f5", 8 | "iso_url": "http://ftp.riken.jp/Linux/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1511.iso", 9 | "type": "virtualbox-iso", 10 | "ssh_password": "vagrant", 11 | "ssh_username": "vagrant", 12 | "ssh_wait_timeout": "50000s", 13 | "headless": "true", 14 | "vboxmanage": [ 15 | [ 16 | "modifyvm", 17 | "{{.Name}}", 18 | "--memory", 19 | "2048" 20 | ], 21 | [ 22 | "modifyvm", 23 | "{{.Name}}", 24 | "--cpus", 25 | "2" 26 | ] 27 | ], 28 | "http_directory": ".", 29 | "boot_command": [ 30 | " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" 31 | ], 32 | "shutdown_command": "echo 'vagrant' | sudo -S /sbin/halt -h -p" 33 | } 34 | ], 35 | "provisioners": [ 36 | { 37 | "type": "shell", 38 | "scripts": [ 39 | "vagrant.sh", 40 | "virtualbox.sh", 41 | "cleanup.sh" 42 | ], 43 | "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'" 44 | } 45 | ], 46 | "post-processors": [ 47 | { 48 | "type": "vagrant", 49 | "compression_level": 9, 50 | "output": "centos7.box" 51 | } 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /ks.cfg: -------------------------------------------------------------------------------- 1 | install 2 | url --url http://ftp.riken.jp/Linux/centos/7/os/x86_64/ 3 | 4 | lang en_US.UTF-8 5 | keyboard us 6 | timezone Asia/Tokyo 7 | 8 | network --device=em0 --bootproto=dhcp --ipv6=auto 9 | firewall --enable --ssh 10 | 11 | authconfig --enableshadow --passalgo=sha512 12 | selinux --disabled 13 | rootpw vagrant 14 | 15 | text 16 | skipx 17 | 18 | clearpart --all --initlabel 19 | zerombr 20 | autopart 21 | bootloader --location=mbr 22 | 23 | firstboot --disabled 24 | reboot 25 | 26 | %packages 27 | @Core 28 | bzip2 29 | gcc 30 | kernel-devel 31 | kernel-headers 32 | -avahi 33 | -bluez-utils 34 | -dogtail 35 | -kudzu 36 | -ipw2100-firmware 37 | -ipw2200-firmware 38 | -ivtv-firmware 39 | %end 40 | 41 | %post 42 | # disable unnecessary services 43 | chkconfig acpid off 44 | chkconfig auditd off 45 | chkconfig blk-availability off 46 | chkconfig bluetooth off 47 | chkconfig certmonger off 48 | chkconfig cpuspeed off 49 | chkconfig cups off 50 | chkconfig haldaemon off 51 | chkconfig ip6tables off 52 | chkconfig lvm2-monitor off 53 | chkconfig messagebus off 54 | chkconfig mdmonitor off 55 | chkconfig rpcbind off 56 | chkconfig rpcgssd off 57 | chkconfig rpcidmapd off 58 | chkconfig yum-updateonboot off 59 | 60 | # vagrant 61 | groupadd vagrant -g 1001 62 | useradd vagrant -g vagrant -G wheel -u 1001 63 | echo "vagrant" | passwd --stdin vagrant 64 | 65 | # sudo 66 | yum install -y sudo 67 | echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant 68 | sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers 69 | %end 70 | --------------------------------------------------------------------------------