Last active
August 29, 2015 14:11
-
-
Save youyo/624199b7f8516b195522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -u | |
if [ $# -ne 9 ]; then | |
echo -e "Usage:\t${0} HOSTNAME PASSWORD VCPU MEMORY SWAP DISK IPADDRESS NETMASK GATEWAY" | |
exit 99 | |
fi | |
HOSTNAME=${1?need hostname} | |
PASSWORD=${2?need password} | |
VCPU=${3?need vcpu} | |
MEMORY=${4?need memory} | |
SWAP=${5?need swap} | |
DISK=${6?need disk} | |
IPADDRESS=${7?need ipaddress} | |
NETMASK=${8?need netmask} | |
GATEWAY=${9?need gateway} | |
ISO='/var/lib/libvirt/images/CentOS-6.6-x86_64-bin-DVD1.iso' | |
XMLPATH='/etc/libvirt/qemu' | |
KS_URL="http://kickstart-sinatra.herokuapp.com/kickstart/${HOSTNAME}/${IPADDRESS}/${NETMASK}/${GATEWAY}/${PASSWORD}/${SWAP}" | |
virt-install \ | |
--connect qemu:///system \ | |
--name ${HOSTNAME} \ | |
--hvm \ | |
--virt-type kvm \ | |
--ram ${MEMORY} \ | |
--vcpus ${VCPU},maxvcpus=8 \ | |
--arch x86_64 \ | |
--os-type linux \ | |
--os-variant rhel6 \ | |
--disk path=/var/lib/libvirt/images/${HOSTNAME}.qcow2.img,size=${DISK},format=qcow2 \ | |
--network bridge=br0 \ | |
--graphics vnc,listen=127.0.0.1,keymap=ja \ | |
--serial pty \ | |
--console pty \ | |
--noautoconsole --wait -1 \ | |
--location=${ISO} \ | |
--extra-args "ks=${KS_URL} console=ttyS0,115200 keymap=ja ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} dns=8.8.4.4" \ | |
--noreboot \ | |
--autostart #--debug | |
while [ `LANG=C virsh dominfo ${HOSTNAME}|grep ^State:|awk '{print $2}'` = "running" ]; | |
do | |
sleep 1 | |
done | |
#sed -i "s|<source bridge='br0'/>|<source bridge='br0'/><filterref filter='clean-traffic'><parameter name='IP' value='${IPADDRESS}'/></filterref>|g" ${XMLPATH}/${HOSTNAME}.xml | |
#sleep 1 | |
#virsh define ${XMLPATH}/${HOSTNAME}.xml | |
#sleep 1 | |
virsh start ${HOSTNAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment