Skip to content

Instantly share code, notes, and snippets.

@gbluma
Created January 30, 2022 01:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbluma/1dea9144019980344620ca88a730ad96 to your computer and use it in GitHub Desktop.
Save gbluma/1dea9144019980344620ca88a730ad96 to your computer and use it in GitHub Desktop.
A short script to queue up a start job in proxmox, so that once the FROM vm is fully off, the TO vm is started. It's useful for swapping between GPU passthrough virtual machines without having to use another computer to start the next vm.
#!/bin/bash
FROM=$1
TO=$2
if [ -z "$FROM" ]; then echo "Usage: ./switch_vm.sh <current_vmid> <next_vmid>"; exit 1; fi
if [ -z "$TO" ]; then echo "Usage: ./switch_vm.sh <current_vmid> <next_vmid>"; exit 1; fi
echo "waiting for $FROM to shutdown, then starting $TO"
while : ; do
# read status for starting VM from qemu
status=$(qm status $FROM)
echo "$FROM = $status"
# if the vm reaches a stopped state
if [[ "$status" == *"stopped"* ]]; then
# ... start the next VM
echo "starting $TO..."
qm start $TO
echo "started."
# and exit
exit 0
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment