Quickly Deploy VMs in PVE Environment Using cloud-img Images
Create Virtual Machine
qm create 9991 --name Debian-10-01template --net0 virtio,bridge=vmbr0 --ostype l26 --memory 2048 --cpu host
Import Disk Image
qm importdisk 9991 debian-10-generic-amd64-20230917-1506.qcow2 local-ssd -format qcow2
Attach Imported Disk to Controller
qm set 9991 --scsihw virtio-scsi-single --scsi0 local-ssd:vm-9991-disk-0
Configure cloud-init Drive
qm set 9991 --ide2 local-ssd:cloudinit
Configure Boot Disk
qm set 9991 --boot order=scsi0
Enable QEMU Guest Agent
qm set 9991 --agent enabled=1 (default = 0 disabled)
Configure UEFI or Legacy BIOS
qm set 9991 --bios ovmf <ovmf | seabios> (default = seabios)
Configure CPU Cores
qm set 9991 --cores 2 (1 - N, default = 1)
Configure Memory Size
qm set 9991 --memory 512 (default = 512, unit in MB)
Configure OS Type
qm set 9991 --ostype l26 <l24 | l26=Linux2.6-6.x | other | solaris | w2k | w2k3 | w2k8 | win10 | win11 | win7 | win8 | wvista | wxp> (Note: This command cannot set Linux type, may be a bug, parameters 124 and 126 will report errors in CLI)
GPU Passthrough Example (e.g., RX 580 2048SP)
- First example shows passthrough with visible ROM to guest:
qm set 9991 -hostpci0 0000:02:00,pcie=1,x-vga=1,romfile=rx5802048sp.rom,rombar=1
Download GPU ROM
- If needing to override IDs, download corresponding ROM that can drive after override (e.g., 2048SP overridden as 2304SP)
- Available options include vendor-id, device-id, sub-vendor-id and sub-device-id
- Example overriding hardware IDs:
qm set 9991 -hostpci0 000:02:00,vendor-id=0x1002,device-id=0x67df,pcie=1,x-vga=1,romfile=rx580234sp.rom,rombar=1
Add Serial Console
qm set 9991 --serial0 socket --vga serial0
Convert to Template
qm template 9991
Clone Virtual Machine
qm clone 9991 103 --name debian-10
- Clone command explanation: qm clone TemplateVMID NewVMID --name NewName
Configure CPU Mode (host provides best performance)
qm set 9991 --cpu host
Configure cloud-init Data
- Add UEFI disk with pre-enrolled keys for secure boot support
qm set 9991 -efidisk0 local-lvm:1,format=raw,efitype=4m,pre-enrolled-keys=1
- Add TPM 2.0 support
qm set 9991 -tpmstate0 local-lvm:1,version=v2.0
- Add public key for password-less login (supports RSA etc.)
qm set 9991 --sshkey ~/.ssh/id_ed25519.pub
- Configure network, gateway and IP
qm set 9991 --ipconfig0 ip=10.0.10.123/24,gw=10.0.10.1,ip6=auto
- Configure username and password (will be configured in VM by cloud-init)
qm set 9991 --ciuser ymwl --cipassword 123456
- Configure whether to update system packages after boot (default
1
enabled,0
disabled)
qm set 9991 --ciupgrade 1
- Set custom DNS server
qm set 9991 --nameserver 8.8.8.8