diff --git a/README.md b/README.md index 420369d..3e5e3a2 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ ## Automated Setup -###### Not well-tested. Only supports systemd init system. Installs packages, enables iommu and creates libvirt hooks for now. -###### Halted till December. -###### TODO: upstart, openrc, sysv support. Automatic VM creation and passthrough support. Libvirt script for window managers. -```sh -make -sudo ./passthrough +###### UNTESTED.. DO NOT USE... +###### FEATURES: Enable IOMMU, Copy Libvirt scripts from scripts folder to libvirt hooks path.. +##### TODO: EVERYTHING -OR +##### Replace win10 to your domain name for VM.. +##### Configure scripts/qemu.d/win10/prepare/begin/begin.sh +##### Configure scripts/qemu.d/win10/release/end/end.sh -sudo make run +```sh +sudo ./setup.sh ``` ## Manual Setup @@ -42,7 +42,7 @@ sudo make run Install required tools ```sh - sudo pacman -S qemu libvirt edk2-ovmf virt-manager dnsmasq ebtables iptables + sudo pacman -S qemu libvirt edk2-ovmf virt-manager dnsmasq ebtables ``` @@ -257,4 +257,4 @@ sudo make run > [Single GPU Passthrough by joeknock90](https://github.com/joeknock90/Single-GPU-Passthrough)
> [Single GPU Passthrough by YuriAlek](https://gitlab.com/YuriAlek/vfio)
> [ArchLinux PCI Passthrough](https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF)
-> [Gentoo GPU Passthrough](https://wiki.gentoo.org/wiki/GPU_passthrough_with_libvirt_qemu_kvm)
\ No newline at end of file +> [Gentoo GPU Passthrough](https://wiki.gentoo.org/wiki/GPU_passthrough_with_libvirt_qemu_kvm)
diff --git a/grub b/grub new file mode 100644 index 0000000..c5a99b4 --- /dev/null +++ b/grub @@ -0,0 +1,3 @@ +KEYTWO="val1 val2 val3" +KEYTHREE="val1 val2 val3" +GRUB_CMDLINE_LINUX_DEFAULT="val1 val2 val3val4 val4" diff --git a/scripts/qemu b/scripts/qemu new file mode 100644 index 0000000..ee19314 --- /dev/null +++ b/scripts/qemu @@ -0,0 +1,19 @@ +#!/bin/bash + +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. + +if [ -f "$HOOKPATH" ]; then + eval \""$HOOKPATH"\" "$@" +elif [ -d "$HOOKPATH" ]; then + while read file; do + eval \""$file"\" "$@" + done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)" +fi diff --git a/scripts/qemu.d/win10/prepare/begin/begin.sh b/scripts/qemu.d/win10/prepare/begin/begin.sh new file mode 100755 index 0000000..351bb3a --- /dev/null +++ b/scripts/qemu.d/win10/prepare/begin/begin.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -x + +# Stop display manager +systemctl stop display-manager + +# Unbind EFI Framebuffer +echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind + +# Unload NVIDIA kernel modules +modprobe -r nvidia_drm nvidia_modeset nvidia_uvm nvidia + +# Unload AMD kernel module +# modprobe -r amdgpu + +# Detach GPU devices from host +# Use your GPU and HDMI Audio PCI host device +virsh nodedev-detach pci_0000_01_00_0 +virsh nodedev-detach pci_0000_01_00_1 + +# Load vfio module +modprobe vfio-pci diff --git a/scripts/qemu.d/win10/release/end/end.sh b/scripts/qemu.d/win10/release/end/end.sh new file mode 100755 index 0000000..097c7a7 --- /dev/null +++ b/scripts/qemu.d/win10/release/end/end.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -x + +# Unload vfio module +modprobe -r vfio-pci + +# Attach GPU devices to host +# Use your GPU and HDMI Audio PCI host device +virsh nodedev-reattach pci_0000_01_00_0 +virsh nodedev-reattach pci_0000_01_00_1 + +# Rebind framebuffer to host +echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind + +# Load NVIDIA kernel modules +modprobe nvidia_drm +modprobe nvidia_modeset +modprobe nvidia_uvm +modprobe nvidia + +# Load AMD kernel module +# modprobe amdgpu + +# Restart Display Manager +systemctl start display-manager diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..97e27ba --- /dev/null +++ b/setup.sh @@ -0,0 +1,33 @@ +if [[ -z lspcu | grep Virtualization ]]; then + echo "ERROR: Virtualization isn't supported in this system" + exit 1 +fi + +if [[ -z dmesg | grep 'IOMMU enabled' ]]; then + echo "IOMMU isn't enabled. Enabling IOMMU... " + if [[ -f /boot/grub/grub.cfg ]]; then + echo "Loading GRUB configuration.. " + config=/etc/default/grub + if [[ lscpu | grep GenuineIntel ]]; then + if [[ -z sed -n 's/^GRUB_CMDLINE_LINUX_DEFAULT=//p' $config | grep intel_iommu=on ]]; then + sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 intel_iommu=on"/' $config + fi + else + if [[ -z sed -n 's/^GRUB_CMDLINE_LINUX_DEFAULT=//p' $config | grep amd_iommu=on ]]; then + sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 amd_iommu=on"/' $config + fi + elif [[ -f /boot/loader/loader.conf ]]; then + echo "Loading systemd-boot configuration... " + echo "Add intel_iommu=on or amd_iommu=on depending on your CPU to options in boot entry.." + # TODO + fi + echo "IOMMU enabled.." + echo "Please reboot your system to continue.." + exit 1 +fi + +echo "COPYING LIBVIRT SCRIPTS" +cp scripts/* /etc/libvirt/hooks/ + +echo "CONFIGURATION FINISHED.." +# TODO MORE OPTIONS