Last active
October 18, 2018 06:25
-
-
Save yuvalif/452e918b773197541255a33ead597513 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 | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <hostname> <cluster-name>" | |
exit 1 | |
fi | |
NAME=$1 | |
CLUSTER=$2 | |
HOST=$1.$2 | |
OSVERSION=centos-7.5 | |
OSVARIANT=centos7.0 | |
ARCHITECTURE=x86_64 | |
DISK_SIZE=20G | |
CPUS=2 | |
RAM=2048 | |
# build the vm pool if does not exists | |
mkdir -p ~/vms | |
# build an image file and store into a local "vms" pool | |
virt-builder ${OSVERSION} -o ~/vms/${NAME}-${OSVERSION}-${ARCHITECTURE}-sda.qcow2 \ | |
--no-network --format qcow2 --arch ${ARCHITECTURE} --size ${DISK_SIZE} --root-password=password:centos \ | |
--hostname ${HOST} | |
if [ ! $? -eq 0 ]; then | |
exit 1 | |
fi | |
# refresh the pool | |
virsh pool-refresh vms | |
if [ ! $? -eq 0 ]; then | |
exit 1 | |
fi | |
# installl CentOS7.5 in that image | |
# "hostpassthrough is defined so that nested VMs will be supported | |
# "import" option to bypass actuall install | |
# "extra-args" to allocate static IP | |
virt-install -n ${NAME}-${OSVERSION}-${ARCHITECTURE} --vcpus ${CPUS} --cpu host-passthrough,cache.mode=passthrough \ | |
--arch ${ARCHITECTURE} --memory ${RAM} --import --os-variant ${OSVARIANT} --controller scsi,model=virtio-scsi \ | |
--disk vol=vms/${NAME}-${OSVERSION}-${ARCHITECTURE}-sda.qcow2,device=disk,bus=scsi,discard=unmap \ | |
--network network=default,model=virtio \ | |
--graphics spice --channel unix,name=org.qemu.guest_agent.0 --noautoconsole --noreboot | |
if [ ! $? -eq 0 ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment