diff --git a/README.md b/README.md index b10f01e..3c75102 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,12 @@ Scripts for passing a single GPU from a Linux host to a Windows VM and back. -1. Change PCI ids in the vfio-startup and teardown script. -2. Change the VM name in qemu if not already win10 -3. Run the install.sh script as root +1. Change the VM name in qemu if not already win10 +2. Run the install_hooks.sh script as root + +Note the PCI ids and display manager should be detected automatically. If you are using an unsupported display manager that is not listed in the hooks/vfio-startup.sh script, feel free to contact us on the Discord server and we shall add your display manager. + +If using startx, add a line `killall -u user_name` to qemu/vfio-startup.sh script towards the beginning and you can add a line to vfio-teardown.sh to start your window manager/ desktop environment again. Don't just add startx because it will be run as root. Instead add `su -s /bin/bash -c "/usr/bin/startx" -g username username` replacing username with your username to the end of the vfio-teardown.sh script. For suggestions or support, join us on Discord at: https://discord.gg/bh4maVc diff --git a/hooks/qemu b/hooks/qemu new file mode 100755 index 0000000..c68007c --- /dev/null +++ b/hooks/qemu @@ -0,0 +1,20 @@ +#!/bin/bash + +OBJECT="$1" +OPERATION="$2" + +if [[ $OBJECT == "win10" ]]; then + case "$OPERATION" in + "prepare") + systemctl start libvirt-nosleep@"$OBJECT" 2>&1 | tee -a /var/log/libvirt/custom_hooks.log + /bin/vfio-startup.sh 2>&1 | tee -a /var/log/libvirt/custom_hooks.log + ;; + + "release") + systemctl stop libvirt-nosleep@"$OBJECT" 2>&1 | tee -a /var/log/libvirt/custom_hooks.log + /bin/vfio-teardown.sh 2>&1 | tee -a /var/log/libvirt/custom_hooks.log + ;; + esac +fi + + diff --git a/vfio-startup.sh b/hooks/vfio-startup.sh similarity index 100% rename from vfio-startup.sh rename to hooks/vfio-startup.sh diff --git a/vfio-teardown.sh b/hooks/vfio-teardown.sh similarity index 100% rename from vfio-teardown.sh rename to hooks/vfio-teardown.sh diff --git a/install.sh b/install.sh deleted file mode 100755 index a858630..0000000 --- a/install.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -mv /etc/libvirt/hooks/qemu /etc/libvirt/hooks/qemu_last_backup -mv /bin/vfio-startup.sh /bin/vfio-startup.sh.bkp -mv /bin/vfio-teardown.sh /bin/vfio-teardown.sh.bkp - -cp vfio-startup.sh /bin/vfio-startup.sh -cp vfio-teardown.sh /bin/vfio-teardown.sh -cp qemu /etc/libvirt/hooks/qemu - -chmod +x /bin/vfio-startup.sh -chmod +x /bin/vfio-teardown.sh -chmod +x /etc/libvirt/hooks/qemu diff --git a/install_hooks.sh b/install_hooks.sh new file mode 100755 index 0000000..dd49621 --- /dev/null +++ b/install_hooks.sh @@ -0,0 +1,22 @@ +#!/bin/bash +if test -e /etc/libvirt/hooks/qemu then + mv /etc/libvirt/hooks/qemu /etc/libvirt/hooks/qemu_last_backup +fi +if test -e /bin/vfio-startup.sh then + mv /bin/vfio-startup.sh /bin/vfio-startup.sh.bkp +fi +if test -e /bin/vfio-teardown.sh then + mv /bin/vfio-teardown.sh /bin/vfio-teardown.sh.bkp +fi +if test -e /etc/systemd/system/libvirt-nosleep@.service then + rm /etc/systemd/system/libvirt-nosleep@.service +fi + +cp systemd-no-sleep/libvirt-nosleep@.service /etc/systemd/system/libvirt-nosleep@.service +cp hooks/vfio-startup.sh /bin/vfio-startup.sh +cp hooks/vfio-teardown.sh /bin/vfio-teardown.sh +cp hooks/qemu /etc/libvirt/hooks/qemu + +chmod +x /bin/vfio-startup.sh +chmod +x /bin/vfio-teardown.sh +chmod +x /etc/libvirt/hooks/qemu diff --git a/qemu b/qemu deleted file mode 100755 index 9426d70..0000000 --- a/qemu +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Script for win10 -if [[ $1 == "win10" ]]; then - if [[ $2 == "prepare" ]]; then - /bin/vfio-startup.sh 2>&1 | tee -a /var/log/libvirt/custom_hooks.log - fi - - if [[ $2 == "release" ]]; then - /bin/vfio-teardown.sh 2>&1 | tee -a /var/log/libvirt/custom_hooks.log - fi -fi - diff --git a/systemd-no-sleep/libvirt-nosleep@.service b/systemd-no-sleep/libvirt-nosleep@.service new file mode 100755 index 0000000..9c740f4 --- /dev/null +++ b/systemd-no-sleep/libvirt-nosleep@.service @@ -0,0 +1,6 @@ +[Unit] +Description=Preventing sleep while libvirt domain "%i" is running + +[Service] +Type=simple +ExecStart=/usr/bin/systemd-inhibit --what=sleep --why="Libvirt domain \"%i\" is running" --who=%U --mode=block sleep infinity