Created
November 14, 2012 02:15
-
-
Save EntropyWorks/4069846 to your computer and use it in GitHub Desktop.
Just building KVM images for myself
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 | |
# Yazz Building KVM images | |
ubuntu="quantal" | |
name=(bm-installer) # Just add more seperated by a space to build | |
domain="example.com" | |
nic="eth0" | |
location="http://us.archive.ubuntu.com/ubuntu/dists/${ubuntu}/main/installer-amd64/" | |
preseed="http://192.168.41.89/preseed.cfg" | |
vm_disks="$HOME/kvm" | |
virt_type="kvm" | |
img_size="8" ; # in Gigs | |
ram="512" | |
os_variant="ubuntu${ubuntu}" | |
if [ -d ${vm_disks} ] ; then | |
mkdir -p ${vm_disks} | |
fi | |
x=0 | |
for kvm_name in ${name[@]} ; do | |
img_name=${kvm_name}.img | |
virsh destroy ${kvm_name} | |
virsh undefine ${kvm_name} | |
if [ -f ${vm_disks}/${img_name} ] ; then | |
rm -rf ${vm_disks}/${img_name} | |
fi | |
if [ -f /etc/libvirt/qemu/${kvm_name}.xml ] ; then | |
rm -rf /etc/libvirt/qemu/${kvm_name}.xml | |
fi | |
brctl delbr ${kvm_name}-${x} | |
brctl addbr ${kvm_name}-${x} | |
virt-install --name ${kvm_name} \ | |
--connect qemu:///system \ | |
--os-type linux \ | |
--os-variant ${os_variant} \ | |
--virt-type ${virt_type} \ | |
--ram ${ram} \ | |
--disk path="${vm_disks}/${img_name},size=${img_size},sparse=true" \ | |
--network network:default \ | |
--network bridge=${kvm_name}-${x} \ | |
--vnc \ | |
--location=${location} \ | |
--extra-args="url=${preseed} interface=${nic} hostname=${kvm_name} domain=${domain} DEBCONF_INTERFACE=noninteractive DEBCONF_DEBUG=5 auto=true" & | |
let "x=x+1" | |
echo "Completed ${kvm_name} ^G" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment