Skip to content

Instantly share code, notes, and snippets.

@0xabe-io
Created October 7, 2014 12:47
Show Gist options
  • Save 0xabe-io/c4866ce14aa1d3d22c65 to your computer and use it in GitHub Desktop.
Save 0xabe-io/c4866ce14aa1d3d22c65 to your computer and use it in GitHub Desktop.
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script launches virt-install with the specified arguments.
OPTIONS:
-h Show this message
-n NAME VM's name
-r RAM Amount of RAM in MB
-c CPU Number of CPU
-d DISK The location of the disk
[-l LOCATION] The location of the installer
-v Verbose
EOF
}
NAME=
RAM=
CPU=
LOCATION="http://ftp.ch.debian.org/debian/dists/wheezy/main/installer-amd64/"
VERBOSE=
while getopts “hn:r:c:vl:d:” OPTION
do
case $OPTION in
h)
usage
exit
;;
n)
NAME=$OPTARG
;;
r)
RAM=$OPTARG
;;
c)
CPU=$OPTARG
;;
l)
LOCATION=$OPTARG
;;
d)
DISK=$OPTARG
;;
v)
VERBOSE="-d"
;;
?)
usage
exit 1
;;
esac
done
if [[ -z $NAME ]] || [[ -z $RAM ]] || [[ -z $CPU ]] || [[ -z $DISK ]]; then
usage
exit 2
fi
VIRT_INSTALL_BIN=$(which virt-install | sed -e 's/virt-install is //')
if [[ ! -x $VIRT_INSTALL_BIN ]]; then
echo virt-install not found
exit 3
fi
$VIRT_INSTALL_BIN \
--nographics \
--name $NAME \
--ram $RAM \
--vcpus $CPU \
--location $LOCATION \
--os-variant=debian7 \
--disk path=$DISK \
--network default \
--extra-args='console=tty0 console=ttyS0,115200n8' \
$VERBOSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment