Hookscript - GPU (VM) switch

brightrgb

Active Member
Dec 26, 2021
112
5
38
39
Since I can't easily pass through two GPUs with my B550 motherboard, I'm looking for an alternative.

I'd like to create a hookscript that can do the following:
  • If VM1 is shut down, then start VM2.

    AND

  • If VM2 is shut down, then start VM1.
This way, both VMs could share the single passthrough GPU.

Are there any code examples for Proxmox hookscripts?
And do you think what I'm trying to do is possible?
 
Here is an example of a hookscipt that shuts down VM 100 (if it is running) before starting and starts VM 100 when it shuts down (and the host is not shutting down).
Bash:
#!/bin/bash
if [ "$2" == 'pre-start' ]
then
    if /usr/sbin/qm status "100" | grep -q running
    then
        /usr/sbin/qm shutdown 100
    fi
elif [ "$2" == 'post-stop' ]
then
    if systemctl is-system-running | grep -v -q 'running'
    then
        echo "System shutting down, don't start VMs"
    elif [ "$1" != "100" ]
    then
        nohup /usr/sbin/qm start 100 &>/dev/null &
    fi
fi
I'm sure you can adapt it and/or duplicate it for your purposes.
 
Here is an example of a hookscipt that shuts down VM 100 (if it is running) before starting and starts VM 100 when it shuts down (and the host is not shutting down).
Thank you.
Did you create this yourself?
Or is there an overview with code examples somewhere, and how I can ultimately integrate it in the proxmox host?