Win11 VM running (shutdown) Issue using GPU Pass through

matrixx

New Member
May 19, 2023
5
0
1
what is the best way to write a script that will force shutdown a windows 11 vm with passthrough and then invoke the post-stop section in the hookscript? I have tried several ways and cant keep to get the vm to stop after shutdown. Here is what my hookscript looks like.

Code:
#!/usr/bin/perl

# Exmple hook script for PVE guests (hookscript config option)
# You can set this via pct/qm with
# pct set <vmid> -hookscript <volume-id>
# qm set <vmid> -hookscript <volume-id>
# where <volume-id> has to be an executable file in the snippets folder
# of any storage with directories e.g.:
# qm set 100 -hookscript local:snippets/hookscript.pl

use strict;
use warnings;

print "GUEST HOOK: " . join(' ', @ARGV). "\n";

# First argument is the vmid

my $vmid = shift;

# Second argument is the phase

my $phase = shift;

if ($phase eq 'pre-start') {

    # Stop display manager
    system("systemctl stop display-manager.service");

    # Unbind Consoles
    system("echo 0 > /sys/class/vtconsole/vtcon0/bind");
    system("echo 0 > /sys/class/vtconsole/vtcon1/bind");

    # Avoid a Race condition by waiting 2 seconds. This can be calibrated to be>
    sleep 2;

    # Remove AMDGPU Kernel Module
    system("modprobe -r amdgpu");

    # Unbind the GPU from display driver
    system("virsh nodedev-detach pci_0000_03_00_0");
    system("virsh nodedev-detach pci_0000_03_00_1");

    #Make the System Sleep 5 Seconds to give PC time to detach correctly
    system("rtcwake -m mem -s 5");

    # Load VFIO Kernel Module
    system("modprobe vfio");
    system("modprobe vfio_pci");
    system("modprobe vfio_iommu_type1");
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!