Last active
April 1, 2019 01:20
-
-
Save danquack/435353c79bd081b1aaf5dc436963d6af to your computer and use it in GitHub Desktop.
A script to build libvirt images, attach to bond0, and run an initial script on startup
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
# A script to build libvirt images, attach to bond0, and run an initial playbook on startup | |
# ex. Linux 4x4 | |
# ./create -s hostname -r 4096 -d 50 -c 4 | |
while getopts 's:r:d:c:' flag; do | |
case "${flag}" in | |
s) server="${OPTARG}" ;; | |
r) ram=${OPTARG} ;; | |
d) disk=${OPTARG} ;; | |
c) vcpu=${OPTARG} ;; | |
*) exit 1 ;; | |
esac | |
done | |
if [[ -z $server ]]; then | |
echo "no server name provided" | |
exit 1 | |
fi | |
echo "building $server...." | |
sudo virt-builder centos-7.6 --format qcow2 --output /var/lib/libvirt/images/$server.qcow2 --size ${disk:-50}G --root-password file:/root/password --hostname $server --firstboot /root/init.sh || exit 127 | |
echo "importing $server...." | |
sudo virt-install --name $server --vcpus ${vcpu:-2} --ram ${ram:-4096} --disk path=/var/lib/libvirt/images/$server.qcow2,format=qcow2,cache=writeback --import --wait 0 --os-variant=rhel7 || exit 127 | |
echo "attaching bridged interface...." | |
number=`sudo virsh list --all | grep $server | awk '{print $1;}'` | |
sudo virsh attach-interface $server --type direct --source br0 --model virtio --config --live |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment