====== Proxmox 8 How to use CLI only to create and spin up new Linux VMs (qemu) ====== :!: **UNDER CONSTRUCTION:** Util now this page is just some sort of a collection of notes. --- //[[axel.werner.1973@gmail.com|Axel Werner]] 2024-07-20 08:16// ===== Important paths and files: ===== * Boot ISOs can be found in Proxmox storage named: **zfsjbod** ( physical: **%%/zpool-jbod/proxmox/template/iso/%%** ) * Valid ISO files: * zfsjbod:iso/debian-12.0.0-amd64-DVD-1.iso * **zfsjbod:iso/debian-12.0.0-amd64-netinst.iso** * zfsjbod:iso/rescuezilla-2.4.2-64bit.jammy.iso * zfsjbod:iso/SLE-15-SP5-Full-x86_64-GM-Media1.iso * fixme **%%fixme%%** * fixme **%%fixme%%** * fixme **%%fixme%%** ===== CLI navigation: ===== - List available VMs (NOT lxc containers!) and status:\\ qm list - Destroy/Remove/Delete existing VM:\\ qm destroy vmId - List all available Proxmox storages:\\ pvesm status - List all content of a specific PM storage:\\ pvesm list storageId - Show detailed configuration settings for a specific VM ID 666:\\ qm config 666 - Set/Change the RAM amount for VM ID 666:\\ qm set 666 --memory 1024 - Sets/Overwrites all TAGS of a VM. **WARNING: Will replace any existing tags!** :\\ qm set 666 --tags dmz,testing,db qm set 666 --tags '' # removes all tags - Set nameservers using Cloud-Init feature. (Cloud Init must be enabled for this VM to work!) :\\ qm set 666 --nameserver 8.8.8.8,1.1.1.1 - Stopping/Starting/Restarting a VM:\\ qm shutdown 666 # gracefull shutdown (via guest tools) qm shutdown 666 --timeout 60 # with timeout for a hard stop qm stop 666 # hard stop/pull plug/crash qm start 666 qm reboot 666 # gracefully reboot using guest tools qm reboot 666 --timeout 60 # same but with HARD STOP after timeout - List all available snapshots of a VM:\\ qm listsnapshot 666 - Delete a named snapshot of a VM:\\ qm delsnapshot 666 snapshotName - Delete ALL SNAPSHOTS of this VM:\\ vmid=666 qm listsnapshot "$vmid" |\ grep -v "You are here" |\ awk '{print $2}' |\ xargs -n1 qm delsnapshot "$vmid" - Create a new 'named' **UNSAFE ONLINE** snapshot (no RAM/**unsafe crashed state**):\\ qm snapshot 666 snapshotName - Create a new 'named' **OFFLINE** snapshot (no RAM/safe state):\\ qm shutdown 666 qm snapshot 666 snapshotName qm start 666 - Create a new 'named' **ONLINE snapshot** (with RAM+state):\\ qm snapshot 666 snapshotName --vmstate - Switch/Revert/Rollback to a specific named snapshot of this VM:\\ qm rollback 666 snapshotName qm rollback 666 snapshotName --start # with autostart - Set/Reset the ROOT (user) password via installed guest addons:\\ qm guest passwd 666 root --password moreThan5Chars - FIXME:\\ FIXME - FIXME:\\ FIXME - FIXME:\\ FIXME - FIXME:\\ FIXME - FIXME:\\ FIXME - Clone (quick) existing VM:\\ qm clone existingVmId newVmId \ --name 'newVms.fqdn.lan' \ --storage targetStorageId \ # optional ===== Create basic 1 Disk Linux UEFI VM with Cloud-Init capabilities: ===== - Create UEFI/Cloud-Init VM using Debian netboot ISO:\\ # define new VM id and your # PVE storage volume # of choice. # vmId=666 pveStorage=local qm stop "$vmId" qm destroy "$vmId" qm create "$vmId" \ --name newHostname.lan \ --description "once uppon a time..." \ --cores 4 \ --memory 2048 \ --cdrom zfsjbod:iso/debian-12.0.0-amd64-netinst.iso \ --virtio0 "$pveStorage":50,backup=1,discard=on,format=qcow2 \ --ciuser root \ --cipassword 12345 \ --ipconfig0 ip=dhcp,ip6=auto \ --net0 virtio,bridge=vmbr0 \ --sshkeys ssh-public-key-file.pub \ --ostype l26 \ --agent 1 \ --citype nocloud \ --ciupgrade 1 \ --serial0 socket \ --storage local \ --tags someTag \ --scsihw virtio-scsi-single \ --bios ovmf \ --efidisk0 "$pveStorage":1 \ --ide0 "$pveStorage":cloudinit,media=cdrom \ # qm status 666 - SSH into new VM and install some vital packages needed for cloud-init. Also we make sure that we can SSH login as root in the future:\\ ssh user@newHostname.lan su - # no sudo just yet # enter 'user' password apt update \ && apt install -y \ cloud-init \ qemu-guest-agent echo "PermitRootLogin yes" >>/etc/ssh/sshd_config reboot - FIXME:\\ FIXME - FIXME:\\ FIXME - FIXME:\\ FIXME - FIXME:\\ FIXME - FIXME:\\ FIXME