-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare-vm-template.sh
40 lines (32 loc) · 1.48 KB
/
prepare-vm-template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--vmid) VMID="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [[ -z $VMID ]]; then
echo "VMID is required. Please provide a valid VMID using the --vmid option."
exit 1
fi
# Fetch a cloud-init image of Ubuntu
wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
# If you have multiple nodes and run a proxmox cluster, try and run this on the node with the maximum storage
# If you are not on a proxmox subscription, disable any enterprise repos( https://enterprise.proxmox.com/**) before running this script
# The enterprise repos can be disabled by clicking on the node name (For e.g. 'pve') and going into the 'Repositories' sections
apt update -y
apt install libguestfs-tools -y
virt-customize -a focal-server-cloudimg-amd64.img --install qemu-guest-agent
# Create a base VM with the right config for you
# Lable it with a unique and high ID so that the template doesn't show up on the top of your list
qm create $VMID --name "ubuntu-2204-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
qm importdisk $VMID focal-server-cloudimg-amd64.img local-lvm
qm set $VMID --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-$VMID-disk-0
qm set $VMID --boot c --bootdisk scsi0
qm set $VMID --ide2 local-lvm:cloudinit
qm set $VMID --serial0 socket --vga serial0
qm set $VMID --agent enabled=1
# Make it a template
qm template $VMID