You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.0 KiB

4 years ago
  1. #!/bin/sh
  2. _usage() {
  3. echo "
  4. Usage: $0 <storage>
  5. <storage> : should be a valid (active, supporting VM image) PVE storage
  6. "
  7. }
  8. [ -z "$1" ] && _usage && return
  9. _storage=$1
  10. pvesm status --enabled --target localhost --content images |awk {'print $1'} |tail +2 |grep "$_storage" > /dev/null 2>&1
  11. if [ "$?" -ne "0" ]; then
  12. echo "Storage $_storage does not seems to exists. Use 'pvesm status' to find a usable storage"
  13. exit 1
  14. fi
  15. /usr/sbin/qm status 9999 > /dev/null 2>&1
  16. if [ "$?" -ne "2" ]; then
  17. echo "VM9999 already exists, aborting"
  18. exit 1
  19. fi
  20. echo "Storage $_storage is valid and VM does not exists, let's get the latest Ubuntu-minimal image from repo"
  21. # Fetching the last Ubuntu 20.04 cloud-image
  22. curl --progress-bar -o ubuntu-20.04-server-cloudimg-amd64.img http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img
  23. # Silently download public SSH key
  24. curl -s -o support@altinea.fr.pub https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/support@altinea.fr.pub
  25. # Create VM, import cloud-image and configure storage
  26. /usr/sbin/qm create 9999 --memory 1024 --net0 virtio,bridge=vmbr0
  27. /usr/sbin/qm importdisk 9999 ubuntu-20.04-server-cloudimg-amd64.img $_storage
  28. /usr/sbin/qm set 9999 --scsihw virtio-scsi-pci --scsi0 $_storage:vm-9999-disk-0,discard=on
  29. /usr/sbin/qm set 9999 --ide2 $_storage:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0
  30. /usr/sbin/qm resize 9999 scsi0 +2748M
  31. # Convert VM to template
  32. /usr/sbin/qm template 9999
  33. # Adjust VM settings (based on best practices)
  34. /usr/sbin/qm set 9999 --args "-cpu 'kvm64,+ssse3,+sse4.1,+sse4.2,+x2apic'" --ciuser root --ipconfig0 ip=dhcp,ip6=dhcp --sshkeys support@altinea.fr.pub --name "Ubuntu20.04" --agent enabled=1 --numa 1 --hotplug network,disk,cpu,memory,usb --cores 8 --vcpus 1 --machine q35
  35. # Delete temporary files
  36. rm ubuntu-20.04-server-cloudimg-amd64.img
  37. rm support@altinea.fr.pub
  38. echo "All done, you can now clone VM9999 (Ubuntu20.04) from PVE interface"