Last active
May 28, 2020 20:07
-
-
Save bgulla/5b885d2a4ea878dbff295e59d3ee8c0a to your computer and use it in GitHub Desktop.
[Proxmox] Generates VMs via cloudinit.
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 | |
TEMPLATE_ID=9000 | |
DISK_EXPAND_SIZE="+10G" | |
VMID=301 | |
VMNAME=freetacos | |
VM_MEMORY=2048 | |
IP_GATEWAY="10.0.8.1" | |
IP_RANGE="10.0.8.223/24" | |
echo "directions from https://norocketscience.at/deploy-proxmox-virtual-machines-using-cloud-init/ | |
if [ ! -f "bionic-server-cloudimg-amd64.img" ]; then | |
wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img | |
cp ./bionic-server-cloudimg-amd64.img ./bionic-server-cloudimg-amd64.qcow2 | |
else | |
echo "[Skipped Download!] img already exists." | |
fi | |
qm stop ${TEMPLATE_ID} | |
qm destroy ${TEMPLATE_ID} | |
# Create the cloud-init template | |
qm create ${TEMPLATE_ID} --name "${VMNAME}-cloudinit" --memory ${VM_MEMORY} --net0 virtio,bridge=vmbr0 | |
qm importdisk ${TEMPLATE_ID} bionic-server-cloudimg-amd64.qcow2 local-lvm | |
qm set ${TEMPLATE_ID} --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-${TEMPLATE_ID}-disk-0 | |
qm set ${TEMPLATE_ID} --ide2 local-lvm:cloudinit | |
qm set ${TEMPLATE_ID} --boot c --bootdisk scsi0 | |
qm set ${TEMPLATE_ID} --serial0 socket --vga serial0 | |
qm template ${TEMPLATE_ID} | |
# Create the child VMs | |
qm clone ${TEMPLATE_ID} ${VMID} --name ${VMNAME} | |
qm resize ${VMID} scsi0 ${DISK_EXPAND_SIZE} | |
qm set ${VMID} --sshkey ~/.ssh/id_rsa.pub | |
qm set ${VMID} --ipconfig0 ip=${IP_RANGE},gw=${IP_GATEWAY} | |
qm start ${VMID} | |
echo "Done! Head over to the console and check out vm: ${VMID}" | |
echo "[note] you may notice some /dev/sda errors. No Worries, shit's good." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment