diff options
| author | Seth Flynn <[email protected]> | 2021-11-24 02:02:25 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2022-08-04 04:40:17 -0400 |
| commit | 944b6db89ae715d93d0804a6a2358dcab88f1c07 (patch) | |
| tree | 5244d9f5ddf4f8a661e17c184fbadf2e553dbd43 /.local/share/libvirt-hooks | |
initial bare repo commit
Diffstat (limited to '.local/share/libvirt-hooks')
| -rwxr-xr-x | .local/share/libvirt-hooks/qemu | 34 | ||||
| -rwxr-xr-x | .local/share/libvirt-hooks/qemu.d/win11/prepare/begin/start.sh | 32 | ||||
| -rwxr-xr-x | .local/share/libvirt-hooks/qemu.d/win11/release/end/revert.sh | 28 |
3 files changed, 94 insertions, 0 deletions
diff --git a/.local/share/libvirt-hooks/qemu b/.local/share/libvirt-hooks/qemu new file mode 100755 index 0000000..155ec57 --- /dev/null +++ b/.local/share/libvirt-hooks/qemu @@ -0,0 +1,34 @@ +#!/bin/bash +# +# Author: Sebastiaan Meijer ([email protected]) +# +# Copy this file to /etc/libvirt/hooks, make sure it's called "qemu". +# After this file is installed, restart libvirt. +# From now on, you can easily add per-guest qemu hooks. +# Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name. +# For a list of available hooks, please refer to https://www.libvirt.org/hooks.html +# + +GUEST_NAME="$1" +HOOK_NAME="$2" +STATE_NAME="$3" +MISC="${@:4}" + +BASEDIR="$(dirname $0)" + +HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME" + +set -e # If a script exits with an error, we should as well. + +# check if it's a non-empty executable file +if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH"] && [ -x "$HOOKPATH" ]; then + eval \"$HOOKPATH\" "$@" +elif [ -d "$HOOKPATH" ]; then + while read file; do + # check for null string + if [ ! -z "$file" ]; then + eval \"$file\" "$@" + fi + done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)" +fi + diff --git a/.local/share/libvirt-hooks/qemu.d/win11/prepare/begin/start.sh b/.local/share/libvirt-hooks/qemu.d/win11/prepare/begin/start.sh new file mode 100755 index 0000000..10dc07a --- /dev/null +++ b/.local/share/libvirt-hooks/qemu.d/win11/prepare/begin/start.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# for debugging +set -x + +# stop sddm +systemctl stop sddm.service + +# unbind vt console +echo 0 > /sys/class/vtconsole/vtcon0/bind +echo 0 > /sys/class/vtconsole/vtcon1/bind + +# avoid race condition +sleep 10 + +# unload gpu modules +modprobe -r amdgpu +modprobe -r gpu_sched +modprobe -r ttm +modprobe -r drm_kms_helper +modprobe -r drm_ttm_helper +modprobe -r i2c_algo_bit +modprobe -r drm + +# unbind gpu +virsh nodedev-detach pci_0000_06_00_0 +virsh nodedev-detach pci_0000_06_00_1 + +# load vfio modules +modprobe vfio +modprobe vfio-pci +modprobe vfio_iommu_type1 diff --git a/.local/share/libvirt-hooks/qemu.d/win11/release/end/revert.sh b/.local/share/libvirt-hooks/qemu.d/win11/release/end/revert.sh new file mode 100755 index 0000000..502ed39 --- /dev/null +++ b/.local/share/libvirt-hooks/qemu.d/win11/release/end/revert.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# debug +set -x + +# unload vfio modules +modprobe -r vfio_pci +modprobe -r vfio_iommu_type1 +modprobe -r vfio + +# rebind vt console +echo 1 > /sys/class/vtconsole/vtcon0/bind +echo 1 > /sys/class/vtconsole/vtcon1/bind + +# rebind gpu +virsh nodedev-reattach pci_0000_06_00_1 +virsh nodedev-reattach pci_0000_06_00_0 + +# reload gpu modules +modprobe amdgpu +modprobe gpu_sched +modprobe ttm +modprobe drm_kms_helper +modprobe drm_ttm_helper +modprobe i2c_algo_bit +modprobe drm + +# restart sddm +systemctl start sddm.service |
