Skip to content

Instantly share code, notes, and snippets.

@cole-h
Created April 29, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cole-h/61a8ed0a9182e27a89411800f55530c3 to your computer and use it in GitHub Desktop.
Save cole-h/61a8ed0a9182e27a89411800f55530c3 to your computer and use it in GitHub Desktop.
touch /tmp/win10.log
chmod 777 /tmp/win10.log
# Stop graphical session
stop_session() {
while [[ $(systemctl show -p SubState --value display-manager.service) == "running" ]]
do
systemctl stop display-manager.service && echo "`date` Stopping display-manager" >> /tmp/win10.log
sleep 1
done
while [[ $(pgrep -x sway) ]]
do
SWAYSOCK=/run/user/$(id -u vin)/sway-ipc.$(id -u vin).$(pgrep -x sway).sock swaymsg exit \
&& echo "`date` Stopping sway" >> /tmp/win10.log
sleep 1
done
}
stop_session
sync && echo 3 /proc/sys/vm/drop_caches
echo "`date` Freed memory to speed up VM POST" >> /tmp/win10.log
# Unbind VTconsoles
echo 0 > /sys/class/vtconsole/vtcon0/bind
echo "`date` Unbound vtcon0" >> /tmp/win10.log
echo 0 > /sys/class/vtconsole/vtcon1/bind
echo "`date` Unbound vtcon1" >> /tmp/win10.log
# Unbind the GPU from display driver
virsh nodedev-detach pci_0000_01_00_0
echo "`date` Unbound GPU" >> /tmp/win10.log
while pkill -9 jackdbus; do sleep 1; done
echo "`date` Killed jackdbus" >> /tmp/win10.log
virsh nodedev-detach pci_0000_01_00_1
echo "`date` Unbound snd_hda_intel (HDMI audio)" >> /tmp/win10.log
virsh nodedev-detach pci_0000_00_1b_0
echo "`date` Unbound snd_hda_intel (front panel audio)" >> /tmp/win10.log
virsh nodedev-detach pci_0000_00_14_0
echo "`date` Unbound USB devices (M+KBD)" >> /tmp/win10.log
modprobe -r nouveau
echo "`date` Modprobe -r'd nouveau" >> /tmp/win10.log
# Load VFIO Kernel Module
modprobe vfio-pci
echo "`date` Modprobe'd vfio-pci" >> /tmp/win10.log
echo "`date` Start" >> /tmp/win10.log
# Unload VFIO-PCI Kernel Driver
modprobe -r vfio-pci
modprobe -r vfio_iommu_type1
modprobe -r vfio
echo "`date` Modprobe -r'd vfio-pci, vfio_iommu_type1, and vfio" >> /tmp/win10.log
modprobe nouveau
echo "`date` Modprobed nouveau" >> /tmp/win10.log
virsh nodedev-reattach pci_0000_00_14_0
echo "`date` Rebound USB devices (M+KBD)" >> /tmp/win10.log
virsh nodedev-reattach pci_0000_00_1b_0
echo "`date` Rebound snd_hda_intel (front panel audio)" >> /tmp/win10.log
virsh nodedev-reattach pci_0000_01_00_1
echo "`date` Rebound snd_hda_intel (HDMI audio)" >> /tmp/win10.log
# Re-Bind GPU to Nvidia Driver
virsh nodedev-reattach pci_0000_01_00_0
echo "`date` Rebound GPU" >> /tmp/win10.log
# Wait 1 second to avoid possible race condition
sleep 1
# Re-bind to virtual consoles
echo 1 > /sys/class/vtconsole/vtcon0/bind
echo "`date` Rebound vtcon0" >> /tmp/win10.log
echo 1 > /sys/class/vtconsole/vtcon1/bind
echo "`date` Rebound vtcon1" >> /tmp/win10.log
sleep 1
echo -e "`date` End\n\n" >> /tmp/win10.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment