Guest User

Untitled

a guest
Oct 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. if [ "$#" -ne 2 ]; then
  6. echo "Usage: $0 <hostname> <cluster-name>"
  7. exit 1
  8. fi
  9.  
  10. set -x
  11.  
  12. NAME=$1
  13. CLUSTER=$2
  14. HOST=$1.$2
  15. OSVERSION=fedora-28
  16. OSVARIANT=fedora28
  17. ARCHITECTURE=x86_64
  18. DISK_SIZE=20G
  19. CPUS=2
  20. RAM=2048
  21. POOL=vms
  22. POOL_DIR=~/${POOL}
  23. IMAGE_FILE=${NAME}-${OSVERSION}-${ARCHITECTURE}-sda.qcow2
  24.  
  25. set +x
  26.  
  27. # build the vm pool if does not exists
  28. mkdir -p ${POOL_DIR}
  29.  
  30. if [ ! -f ${POOL_DIR}/${IMAGE_FILE} ]; then
  31. # build an image file and store into a local "vms" pool
  32. virt-builder ${OSVERSION} -o ${POOL_DIR}/${IMAGE_FILE} \
  33. --no-network --format qcow2 --arch ${ARCHITECTURE} --size ${DISK_SIZE} --root-password=password:fedora \
  34. --hostname ${HOST}
  35. fi
  36.  
  37. # refresh the pool
  38. virsh pool-refresh vms
  39.  
  40. # installl Fedora28 in that image
  41. # "hostpassthrough is defined so that nested VMs will be supported
  42. # "import" option to bypass actuall install
  43. # "extra-args" to allocate static IP
  44. virt-install -n ${NAME}-${OSVERSION}-${ARCHITECTURE} --vcpus ${CPUS} --cpu host-passthrough,cache.mode=passthrough \
  45. --arch ${ARCHITECTURE} --memory ${RAM} --import --os-variant ${OSVARIANT} --controller scsi,model=virtio-scsi \
  46. --disk vol=${POOL}/${IMAGE_FILE},device=disk,bus=scsi,discard=unmap \
  47. --network network=default,model=virtio \
  48. --graphics spice --channel unix,name=org.qemu.guest_agent.0 --noautoconsole --noreboot
Add Comment
Please, Sign In to add comment