Table of Contents

Virtual machines

Create new VM

First upload the image via the Proxmox management console. Under the node, select the local storage, then ISO images. Upload the desired ISO image, with optional checksum.

After which, use the "Create new VM" button to create a new VM using the image. The usual VM configuration and provisioning applies, e.g. RAM, CPU, NIC. Note to enable the QEMU Agent. Follow this nice documentation.

sudo apt install qemu-guest-agent
sudo systemctl enable --now qemu-guest-agent

Preparing VM for template

Some disambiguation may be needed. I'm pretty sure I don't have it exactly down, but these should be sufficient to get up and running:

Proxmox uses QEMU and loads KVM whenever available, so in this context QEMU and KVM are generally synonymous with each other.

Installing the QEMU agent (ref):

vm:~# apt install qemu-guest-agent  # debian
vm:~# systemctl enable --now qemu-guest-agent
host:~$ qm set ${VM_ID} --agent 1
host:~$ qm reboot ${VM_ID}
host:~$ qm agent ${VM_ID} ping

Saw from Reddit or somewhere that virt-sysprep doesn't really cooperate with PVE...?

A long-ass QEMU and Proxmox cheatsheet, but nice nonetheless.

Template guide here, together with a more automated version. Here's another one. And another one. Note the concerns with machine ID. This is what branched me off: Reddit.

Scripts

For QM related instructions, referenced from script:

# Remove old templates and clone existing VMs
qm destroy 6000 --destroy-unreferenced-disks 1
qm clone 9000 6000 --name mytemplate --full 1
 
# Prepare VM templates
qm set 6000 --ipconfig0 ip=dhcp
qm start 6000
# run stuff here...
qm shutdown 6000
 
# Convert to template
qm set 6000 --template 1

Setup apt-cacherng for faster upgrades.

Monitor LVM thin pool storage usage: pvesm status | grep lvmthin | awk '{print $7}'

"Linked clone feature is not supported for drive 'scsi0'" occurs when cloning from a template. Note to change the drive type for future updates.

Templates are available by default, and can be accessed by pveam available. Updates are propagated via pveam update.

Consider reading this for cloud-init based setup: https://github.com/UntouchedWagons/Ubuntu-CloudInit-Docs

Get IP address of VM

The QEMU guest agent comes in handy here. We use the agent command network-get-interfaces to query the IP addresses.

host:~# qm agent 1000 network-get-interfaces | grep "\"ip-address\""
            "ip-address" : "127.0.0.1",
            "ip-address" : "::1",
            "ip-address" : "192.168.121.85",
            "ip-address" : "fe80::be24:11ff:fe0b:8d17",