Created
August 14, 2011 23:05
-
-
Save DamianZaremba/1145430 to your computer and use it in GitHub Desktop.
virt-install wrapper
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 | |
# | |
# Little virt-install wrapper to save typing, supports the following: | |
# centos - Centos network install with optional ks | |
# fedora - Fedora network install with optional ks | |
# debian - Debian network install with optional ks | |
# ubuntu - Ubuntu network instal with option ks | |
# pxe - Boot a vm and tell it try PXE | |
# | |
# Setup: | |
# Bridged networking using br0 | |
# | |
# Notes: | |
# I doubt this will be expanded on much as I'm writing a "better" version, | |
# the new system will pxeboot all machines and installs will be specified in the pxe config. | |
# | |
# This means we can boot vms intro recovary images far easier as well as installs, | |
# look on github for the current configs for this. | |
# | |
# It will alwo allow us to install older and newer versions far easier. | |
# | |
# ---------- ---------- | |
# This was written for my desktop to save typing, don't expect it to not blow up in your face. | |
# My production management system is seperate and written in perl not bash! | |
# | |
# KS base | |
KS_ADDR='http://10.44.200.5/kickstarts/' | |
# Where we store the vm images | |
DS='/home/kvm/VMHDD' | |
# My local mirror is a little out of date - use bytemark until I get around to resyncing it | |
#REPOSERVER='http://10.44.200.5/repos | |
REPOSERVER='http://mirror.bytemark.co.uk' | |
# We need these | |
if [ -z $2 ] || [ -z $3 ] || [ -z $4 ]; | |
then | |
echo "Usage: $0 {centos|fedora|debian|ubuntu|pxe} {Disk Size} {Ram Allocation} {Name} {Kickstart}"; | |
exit 2; | |
fi | |
# Figure out what distro | |
case "$1" in | |
centos) | |
# Stuff we pass to the kernel | |
extra="auto=true hostname=$4 domain='' console=ttyS0" | |
# If we had a KS file specified add that as well | |
if [ ! -z $5 ]; then | |
extra="$extra ks=$KS_ADDR/centos_$5.ks" | |
fi | |
# Little info | |
echo "Installing vm $4 with $2G disk and $3 ram allocation passing kernel arguments '$extra'" | |
# repo path for virt to pull the kernel/initrd files from | |
location="$REPOSERVER/centos/5.6/os/x86_64/" | |
# Run the command! | |
virt-install --connect qemu:///system --name $4 --ram $3 --hvm --file $DS/$4 --file-size $2 --vnc --location=$location --bridge=br0 --extra="$extra" --noautoconsole | |
virsh console $4 | |
;; | |
fedora) | |
# Stuff we pass to the kernel | |
extra="auto=true hostname=$4 domain='' console=ttyS0" | |
# If we had a KS file specified add that as well | |
if [ ! -z $5 ]; then | |
extra="$extra ks=$KS_ADDR/fedora_$5.ks" | |
fi | |
# Little info | |
echo "Installing vm $4 with $2G disk and $3 ram allocation passing kernel arguments '$extra'" | |
# repo path for virt to pull the kernel/initrd files from | |
location="$REPOSERVER/fedora/linux/releases/15/Fedora/x86_64/os/" | |
# Run the command! | |
virt-install --connect qemu:///system --name $4 --ram $3 --hvm --file $DS/$4 --file-size $2 --vnc --location=$location --bridge=br0 --extra="$extra" --noautoconsole | |
virsh console $4 | |
;; | |
debian) | |
# Stuff we pass to the kernel | |
extra="auto=true hostname=$4 domain='' console=ttyS0" | |
# If we had a KS file specified add that as well | |
if [ ! -z $5 ]; then | |
extra="$extra url=$KS_ADDR/debian_$5.ks" | |
fi | |
# Little info | |
echo "Installing vm $4 with $2G disk and $3 ram allocation passing kernel arguments '$extra'" | |
# repo path for virt to pull the kernel/initrd files from | |
location="http://mirror.bytemark.co.uk/debian/dists/squeeze/main/installer-amd64/" | |
# Run the command! | |
virt-install --connect qemu:///system --name $4 --ram $3 --hvm --file $DS/$4 --file-size $2 --vnc --location=$location --noautoconsole --bridge=br0 --extra="$extra" --noautoconsole | |
virsh console $4 | |
;; | |
ubuntu) | |
# Stuff we pass to the kernel | |
extra="auto=true hostname=$4 domain='' console=ttyS0" | |
# If we had a KS file specified add that as well | |
if [ ! -z $5 ]; then | |
extra="$extra url=$KS_ADDR/ubuntu_$5.ks" | |
fi | |
# Little info | |
echo "Installing vm $4 with $2G disk and $3 ram allocation passing kernel arguments '$extra'" | |
# repo path for virt to pull the kernel/initrd files from | |
location="http://mirror.bytemark.co.uk/ubuntu/dists/natty/main/installer-amd64/" | |
# Run the command! | |
virt-install --connect qemu:///system --name $4 --ram $3 --hvm --file $DS/$4 --file-size $2 --vnc --location=$location --bridge=br0 --extra="$extra" --noautoconsole | |
virsh console $4 | |
;; | |
pxe) | |
# Little info | |
echo "Installing vm $4 with $2G disk and $3 ram allocation." | |
# Run the command | |
virt-install --connect qemu:///system --name $4 --ram $3 --hvm --file $DS/$4 --file-size $2 --vnc --pxe --bridge=br0 | |
virsh console $4 | |
;; | |
*) | |
echo "Unknown distro requested"; | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment