quemu hooks
This commit is contained in:
parent
25078ab6d4
commit
01e4142cea
1 changed files with 69 additions and 0 deletions
|
@ -10,6 +10,75 @@
|
||||||
|
|
||||||
time.timeZone = "America/Los_Angeles";
|
time.timeZone = "America/Los_Angeles";
|
||||||
|
|
||||||
|
let
|
||||||
|
passthrough = pkgs.writeShellScript "pasthrough.sh" ''
|
||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
GUEST_NAME="$1"
|
||||||
|
HOOK_NAME="$2"
|
||||||
|
STATE_NAME="$3"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# For the windows 10 VM
|
||||||
|
if[$GUEST_NAME == 'win10']; then
|
||||||
|
|
||||||
|
# Prepare hook
|
||||||
|
if["$HOOK_NAME/$STATE_NAME" == "prepare/begin"]; then
|
||||||
|
|
||||||
|
# Remove Hyprland
|
||||||
|
pkill Hyprland
|
||||||
|
|
||||||
|
# Unbind VTconsoles
|
||||||
|
echo 0 > /sys/class/vtconsole/vtcon0/bind
|
||||||
|
echo 0 > /sys/class/vtconsole/vtcon1/bind
|
||||||
|
|
||||||
|
# Unbind EFI-Framebuffer
|
||||||
|
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
|
||||||
|
|
||||||
|
# Unload Modules
|
||||||
|
modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia
|
||||||
|
|
||||||
|
# Unbind the GPU from display driver
|
||||||
|
virsh nodedev-detach pci_0000_01_00_0
|
||||||
|
virsh nodedev-detach pci_0000_01_00_1
|
||||||
|
|
||||||
|
# Load VFIO Kernel Module
|
||||||
|
modprobe vfio_pci
|
||||||
|
|
||||||
|
elif["$HOOK_NAME/$STATE_NAME" == "release/end"]; then
|
||||||
|
|
||||||
|
# Re-Bind GPU to Nvidia Driver (replace the pci addresses with yours)
|
||||||
|
virsh nodedev-reattach pci_0000_01_00_0
|
||||||
|
virsh nodedev-reattach pci_0000_01_00_1
|
||||||
|
|
||||||
|
modprobe -r vfio-pci
|
||||||
|
|
||||||
|
#bind efi
|
||||||
|
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
|
||||||
|
|
||||||
|
# Reload nvidia modules
|
||||||
|
modprobe nvidia_drm
|
||||||
|
modprobe nvidia_modeset
|
||||||
|
modprobe nvidia_uvm
|
||||||
|
modprobe nvidia
|
||||||
|
|
||||||
|
# Rebind VT consoles
|
||||||
|
echo 1 > /sys/class/vtconsole/vtcon0/bind
|
||||||
|
echo 1 > /sys/class/vtconsole/vtcon1/bind
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
virtualization.libvirtd.hooks.qemu = {
|
||||||
|
passthrough = "${passthrough}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# Read the Docs before Changing
|
# Read the Docs before Changing
|
||||||
system.stateVersion = "23.05"; # Did you read the comment?
|
system.stateVersion = "23.05"; # Did you read the comment?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue