IamReactor

Hooks

Jul 14th, 2025 (edited)
6
0
5 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | Help | 0 0
  1. /etc/libvirt/hooks/qemu
  2.  
  3. #!/usr/bin/env bash
  4. #
  5. # Author: SharkWipf
  6. #
  7. # Copy this file to /etc/libvirt/hooks, make sure it's called "qemu".
  8. # After this file is installed, restart libvirt.
  9. # From now on, you can easily add per-guest qemu hooks.
  10. # Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name.
  11. # For a list of available hooks, please refer to https://www.libvirt.org/hooks.html
  12. #
  13.  
  14. GUEST_NAME="$1"
  15. HOOK_NAME="$2"
  16. STATE_NAME="$3"
  17. MISC="${@:4}"
  18.  
  19. BASEDIR="$(dirname $0)"
  20.  
  21. HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME"
  22.  
  23. set -e # If a script exits with an error, we should as well.
  24.  
  25. # check if it's a non-empty executable file
  26. if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH" ] && [ -x "$HOOKPATH" ]; then
  27. eval \"$HOOKPATH\" "$@"
  28. elif [ -d "$HOOKPATH" ]; then
  29. while read file; do
  30. # check for null string
  31. if [ ! -z "$file" ]; then
  32. eval \"$file\" "$@"
  33. fi
  34. done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)"
  35. fi
  36.  
  37. --------------------------------------------------------------------------------------------------------------------
  38. /etc/libvirt/hooks/qemu.d/win11/prepare/begin/start.sh
  39.  
  40. set -x
  41.  
  42. source "/etc/libvirt/hooks/kvm.conf"
  43.  
  44. # systemctl stop display-manager
  45.  
  46. echo 0 > /sys/class/vtconsole/vtcon0/bind
  47. echo 0 > /sys/class/vtconsole/vtcon1/bind
  48.  
  49. #uncomment the next line if you're getting a black screen
  50. echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
  51.  
  52. sleep 10
  53.  
  54. modprobe -r amdgpu
  55. modprobe -r snd_hda_intel
  56.  
  57. virsh nodedev-detach $VIRSH_GPU_VIDEO
  58. virsh nodedev-detach $VIRSH_GPU_AUDIO
  59.  
  60. sleep 10
  61.  
  62. modprobe vfio
  63. modprobe vfio_pci
  64. modprobe vfio_iommu_type1
  65.  
  66. --------------------------------------------------------------------------------------------------------------------
  67. /etc/libvirt/hooks/qemu.d/win11/release/end/revert.sh
  68.  
  69. set -x
  70.  
  71. #reboot
  72.  
  73. source "/etc/libvirt/hooks/kvm.conf"
  74.  
  75. modprobe -r vfio
  76. modprobe -r vfio_pci
  77. modprobe -r vfio_iommu_type1
  78.  
  79. sleep 10
  80.  
  81. virsh nodedev-reattach $VIRSH_GPU_VIDEO
  82. virsh nodedev-reattach $VIRSH_GPU_AUDIO
  83.  
  84. echo 1 > /sys/class/vtconsole/vtcon0/bind
  85. echo 1 > /sys/class/vtconsole/vtcon1/bind
  86.  
  87. sleep 3
  88.  
  89. echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
  90.  
  91. modprobe amdgpu
  92. modprobe snd_hda_intel
  93.  
  94. sleep 3
  95.  
  96. # systemctl start display-manager
Advertisement
Add Comment
Please, Sign In to add comment