Commit caf9008c authored by Yuri's avatar Yuri

Error fixing and improving the scritps

parent 652f3aa6
......@@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
---
## 2019/01/02
### Changed
- [scritps](/scripts)
- [config](/scripts/config)
- [macos.sh](/scripts/macos.sh)
- [macos-basic.sh](/scripts/macos-basic.sh)
- [macos-network.sh](/scripts/macos-network.sh)
- [macos-virsh.sh](/scripts/macos-virsh.sh)
- [windows.sh](/scripts/windows.sh)
- [windows-basic.sh](/scripts/windows-basic.sh)
- [windows-network.sh](/scripts/windows-network.sh)
- [windows-virsh.sh](/scripts/windows-virsh.sh)
- [README.md](/README.md)
## 2018/12/30
### Added
......@@ -45,7 +58,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- qemu@.service
- test-qemu.sh
- windows-install.sh
- Troubleshoot.md [Moved to wiki]()
- Install.md [Moved to wiki]()
---
- Troubleshoot.md [Moved to wiki](https://gitlab.com/YuriAlek/vfio/wikis/Troubleshoot)
- Install.md [Moved to wiki](https://gitlab.com/YuriAlek/vfio/wikis/Install)
# Single GPU passthrough
## Last Update
2018/12/30
2019/01/02
## Table of Contents
1. [Start here](#start-here)
......@@ -12,9 +12,9 @@
1. [TODO](#todo)
## Start here
- [How to use the script for Windows](https://gitlab.com/YuriAlek/vfio/wikis/Use/#windows).
- [How to use the script for MacOs](https://gitlab.com/YuriAlek/vfio/wikis/Use/#macos).
- [How to use the script for Linux](https://gitlab.com/YuriAlek/vfio/wikis/Use/#linux).
- [How to use the script for Windows VMs](https://gitlab.com/YuriAlek/vfio/wikis/Use/#windows).
- [How to use the script for MacOS VMs](https://gitlab.com/YuriAlek/vfio/wikis/Use/#macos).
- [How to use the script for Linux VMs](https://gitlab.com/YuriAlek/vfio/wikis/Use/#linux).
## What this is
A series of scripts that allows you to do GPU passthrough with only one GPU in the system by detaching the GPU from the host and passing it to the guest, usually a Windows VM.
......@@ -22,7 +22,7 @@ A series of scripts that allows you to do GPU passthrough with only one GPU in t
However, you may not use this method as it is tedious and having two GPUs allows you to do things like dual monitors (one running Linux and the other running Windows) or [LookingGlass][8].
## Wiki
[Check the wiki for more information and guides on how to make it work](https://gitlab.com/YuriAlek/vfio/wikis/Home).
[Check the wiki for more information and guides on how to make everything work](https://gitlab.com/YuriAlek/vfio/wikis/Home).
## Branches
I keep more than one branch for multiple purposes. [There is a personal branch][1] where I have my actual configuration; [a testing branch][2] where I push changes while I am testing new things, it is **NOT stable**; and [a testing-auto branch][3] where I **try** to make everything work automatically.
......@@ -36,17 +36,21 @@ MacOS High Sierra does not like USB hubs, therefore anything connected to a hub
Windows 10 Pro 1709 works for me, but 1803 does not (may be the UEFI). [I have read that the 1803 version comes with a Spectre patch and the performance is bad][4]. The Spectre patch can be disabled.
`windows-basic.sh` and `windows-virsh.sh` reports no connection but it works (except pings).
## TODO
- [ ] Audio.
- [ ] `smb.conf` and `dnsmasq.conf` using the `config` file.
- [ ] CPU pinning.
- [ ] Performance tunning for QEMU.
- [ ] [Automation][3]
- [ ] Find a way to restore the GPU without `nvidia-xconfig --query-gpu-info`.
- [ ] [Automation][3].
- [ ] Don't kill X server, [shifter and xpra may be the solution][5]. Also [uswsusp (userspace software suspend)][6]. [Source][7]
<!-- Links -->
[1]: /tree/personal "Personal branch"
[2]: /tree/testing "Testing branch"
[3]: /tree/testing-auto "Testing-auto branch"
[1]: https://gitlab.com/YuriAlek/vfio/tree/personal "Personal branch"
[2]: https://gitlab.com/YuriAlek/vfio/tree/testing "Testing branch"
[3]: https://gitlab.com/YuriAlek/vfio/tree/testing-auto "Testing-auto branch"
[4]: https://www.reddit.com/r/VFIO/comments/97unx4/passmark_lousy_2d_graphics_performance_on_windows/
[5]: https://www.linuxquestions.org/questions/linux-desktop-74/move-application-between-desktops-736982/#post4161705
[6]: https://wiki.archlinux.org/index.php/Uswsusp "uswsusp"
......
......@@ -52,6 +52,8 @@ WINDOWS_IMG=$IMAGES/windows.raw
MACOS_ISO=$IMAGES/mojave.iso
MACOS_IMG=$IMAGES/mojave.raw
MACOS_CLOVER=$IMAGES/clover.qcow2
MACOS_OVMF=$IMAGES/MACOS_OVMF_CODE.fd
MACOS_OVMF_VARS=$IMAGES/MACOS_OVMF_VARS.fd
MACOS_OPTIONS="+pcid,+ssse3,+sse4.2,+popcnt,+aes,+xsave,+avx,+xsaveopt,avx2,+smep,check"
## Ulimit
......
......@@ -11,6 +11,7 @@ source "${BASH_SOURCE%/*}/config"
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Remove the framebuffer and console
echo 0 > /sys/class/vtconsole/vtcon0/bind
......@@ -24,8 +25,6 @@ modprobe -r nvidia
modprobe -r snd_hda_intel
# Load the kernel module
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio-pci
## Detach the GPU
......@@ -53,8 +52,8 @@ qemu-system-x86_64 -runas $VM_USER -enable-kvm \
-netdev user,id=net0 \
-device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-drive if=pflash,format=raw,readonly,file=$OVMF \
-drive if=pflash,format=raw,file=$OVMF_VARS \
-drive if=pflash,format=raw,readonly,file=$MACOS_OVMF \
-drive if=pflash,format=raw,file=$MACOS_OVMF_VARS \
-smbios type=2 \
-device ide-drive,bus=ide.2,drive=Clover \
-drive id=Clover,if=none,snapshot=on,format=qcow2,file=$MACOS_CLOVER \
......
......@@ -51,6 +51,7 @@ source "${BASH_SOURCE%/*}/config"
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Remove the framebuffer and console
echo 0 > /sys/class/vtconsole/vtcon0/bind
......@@ -64,8 +65,6 @@ modprobe -r nvidia
modprobe -r snd_hda_intel
## Load vfio
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio-pci
## Detach the GPU
......@@ -97,8 +96,8 @@ qemu-system-x86_64 -runas $VM_USER -enable-kvm \
-netdev tap,id=net0,ifname=$TAP_INTERFACE,script=no,downscript=no \
-device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-drive if=pflash,format=raw,readonly,file=$OVMF \
-drive if=pflash,format=raw,file=$OVMF_VARS \
-drive if=pflash,format=raw,readonly,file=$MACOS_OVMF \
-drive if=pflash,format=raw,file=$MACOS_OVMF_VARS \
-smbios type=2 \
-device ide-drive,bus=ide.2,drive=Clover \
-drive id=Clover,if=none,snapshot=on,format=qcow2,file=$MACOS_CLOVER \
......
......@@ -7,13 +7,14 @@
source "${BASH_SOURCE%/*}/config"
## Check libvirtd
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && LIBVIRTD=STOPPED
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && sleep 1 && LIBVIRTD=STOPPED
## Memory lock limit
[[ $ULIMIT != $ULIMIT_TARGET ]] && ulimit -l $ULIMIT_TARGET
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Kill the console
echo 0 > /sys/class/vtconsole/vtcon0/bind
......@@ -21,12 +22,10 @@ echo 0 > /sys/class/vtconsole/vtcon1/bind
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
## Detach the GPU
virsh nodedev-detach $VIRSH_GPU
virsh nodedev-detach $VIRSH_GPU_AUDIO
virsh nodedev-detach $VIRSH_GPU > /dev/null 2>&1
virsh nodedev-detach $VIRSH_GPU_AUDIO > /dev/null 2>&1
## Load vfio
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio-pci
## QEMU (VM) command
......@@ -43,8 +42,8 @@ qemu-system-x86_64 -runas $VM_USER -enable-kvm \
-netdev user,id=net0 \
-device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-drive if=pflash,format=raw,readonly,file=$OVMF \
-drive if=pflash,format=raw,file=$OVMF_VARS \
-drive if=pflash,format=raw,readonly,file=$MACOS_OVMF \
-drive if=pflash,format=raw,file=$MACOS_OVMF_VARS \
-smbios type=2 \
-device ide-drive,bus=ide.2,drive=Clover \
-drive id=Clover,if=none,snapshot=on,format=qcow2,file=$MACOS_CLOVER \
......@@ -62,13 +61,13 @@ modprobe -r vfio_iommu_type1
modprobe -r vfio
## Reattach the GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO
virsh nodedev-reattach $VIRSH_GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO > /dev/null 2>&1
virsh nodedev-reattach $VIRSH_GPU > /dev/null 2>&1
## Reload the framebuffer
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
## Reload the framebuffer and console
echo 1 > /sys/class/vtconsole/vtcon0/bind
echo 1 > /sys/class/vtconsole/vtcon1/bind
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
## Reload the Display Manager
systemctl start lightdm
......
......@@ -47,13 +47,14 @@ samba_server(){
source "${BASH_SOURCE%/*}/config"
## Check libvirtd
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && LIBVIRTD=STOPPED
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && sleep 1 && LIBVIRTD=STOPPED
## Memory lock limit
[[ $ULIMIT != $ULIMIT_TARGET ]] && ulimit -l $ULIMIT_TARGET
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Remove the framebuffer and console
echo 0 > /sys/class/vtconsole/vtcon0/bind
......@@ -61,8 +62,8 @@ echo 0 > /sys/class/vtconsole/vtcon1/bind
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
## Detach the GPU
virsh nodedev-detach $VIRSH_GPU
virsh nodedev-detach $VIRSH_GPU_AUDIO
virsh nodedev-detach $VIRSH_GPU > /dev/null 2>&1
virsh nodedev-detach $VIRSH_GPU_AUDIO > /dev/null 2>&1
## Load vfio
modprobe vfio
......@@ -88,8 +89,8 @@ qemu-system-x86_64 -runas $VM_USER -enable-kvm \
-netdev tap,id=net0,ifname=$TAP_INTERFACE,script=no,downscript=no \
-device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-drive if=pflash,format=raw,readonly,file=$OVMF \
-drive if=pflash,format=raw,file=$OVMF_VARS \
-drive if=pflash,format=raw,readonly,file=$MACOS_OVMF \
-drive if=pflash,format=raw,file=$MACOS_OVMF_VARS \
-smbios type=2 \
-device ide-drive,bus=ide.2,drive=Clover \
-drive id=Clover,if=none,snapshot=on,format=qcow2,file=$MACOS_CLOVER \
......@@ -112,13 +113,13 @@ modprobe -r vfio_iommu_type1
modprobe -r vfio
## Reattach the GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO
virsh nodedev-reattach $VIRSH_GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO > /dev/null 2>&1
virsh nodedev-reattach $VIRSH_GPU > /dev/null 2>&1
## Reload the framebuffer and console
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
echo 1 > /sys/class/vtconsole/vtcon0/bind
echo 1 > /sys/class/vtconsole/vtcon1/bind
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
## Reload the Display Manager
systemctl start lightdm
......
......@@ -11,21 +11,20 @@ source "${BASH_SOURCE%/*}/config"
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Remove the framebuffer and console
echo 0 > /sys/class/vtconsole/vtcon0/bind
echo 0 > /sys/class/vtconsole/vtcon1/bind
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
# Unload the Kernel Modules that use the GPU
## Unload the nvidia drivers
modprobe -r nvidia_drm
modprobe -r nvidia_modeset
modprobe -r nvidia
modprobe -r snd_hda_intel
# Load the kernel module
modprobe vfio
modprobe vfio_iommu_type1
## Load vfio
modprobe vfio-pci
## Detach the GPU
......
......@@ -51,21 +51,20 @@ source "${BASH_SOURCE%/*}/config"
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Remove the framebuffer and console
echo 0 > /sys/class/vtconsole/vtcon0/bind
echo 0 > /sys/class/vtconsole/vtcon1/bind
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
## Unload the Kernel Modules that use the GPU
## Unload the nvidia drivers
modprobe -r nvidia_drm
modprobe -r nvidia_modeset
modprobe -r nvidia
modprobe -r snd_hda_intel
## Load vfio
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio-pci
## Detach the GPU
......
......@@ -7,13 +7,14 @@
source "${BASH_SOURCE%/*}/config"
## Check libvirtd
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && LIBVIRTD=STOPPED
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && sleep 1 && LIBVIRTD=STOPPED
## Memory lock limit
[[ $ULIMIT != $ULIMIT_TARGET ]] && ulimit -l $ULIMIT_TARGET
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Kill the console
echo 0 > /sys/class/vtconsole/vtcon0/bind
......@@ -21,12 +22,10 @@ echo 0 > /sys/class/vtconsole/vtcon1/bind
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
## Detach the GPU
virsh nodedev-detach $VIRSH_GPU
virsh nodedev-detach $VIRSH_GPU_AUDIO
virsh nodedev-detach $VIRSH_GPU > /dev/null 2>&1
virsh nodedev-detach $VIRSH_GPU_AUDIO > /dev/null 2>&1
## Load vfio
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio-pci
## QEMU (VM) command
......@@ -59,13 +58,13 @@ modprobe -r vfio_iommu_type1
modprobe -r vfio
## Reattach the GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO
virsh nodedev-reattach $VIRSH_GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO > /dev/null 2>&1
virsh nodedev-reattach $VIRSH_GPU > /dev/null 2>&1
## Reload the framebuffer
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
## Reload the framebuffer and console
echo 1 > /sys/class/vtconsole/vtcon0/bind
echo 1 > /sys/class/vtconsole/vtcon1/bind
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
## Reload the Display Manager
systemctl start lightdm
......
......@@ -47,13 +47,14 @@ samba_server(){
source "${BASH_SOURCE%/*}/config"
## Check libvirtd
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && LIBVIRTD=STOPPED
[[ $(systemctl status libvirtd | grep running) ]] || systemctl start libvirtd && sleep 1 && LIBVIRTD=STOPPED
## Memory lock limit
[[ $ULIMIT != $ULIMIT_TARGET ]] && ulimit -l $ULIMIT_TARGET
## Kill the Display Manager
systemctl stop lightdm
sleep 1
## Remove the framebuffer and console
echo 0 > /sys/class/vtconsole/vtcon0/bind
......@@ -61,12 +62,10 @@ echo 0 > /sys/class/vtconsole/vtcon1/bind
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
## Detach the GPU
virsh nodedev-detach $VIRSH_GPU
virsh nodedev-detach $VIRSH_GPU_AUDIO
virsh nodedev-detach $VIRSH_GPU > /dev/null 2>&1
virsh nodedev-detach $VIRSH_GPU_AUDIO > /dev/null 2>&1
## Load vfio
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio-pci
## Start the network
......@@ -75,7 +74,7 @@ dhcp_server start
samba_server start
## QEMU (VM) command
qemu-system-x86_64 -runas $USER -enable-kvm \
qemu-system-x86_64 -runas $VM_USER -enable-kvm \
-nographic -vga none -parallel none -serial none \
-m $RAM \
-cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=0xDEADBEEFFF \
......@@ -108,13 +107,13 @@ modprobe -r vfio_iommu_type1
modprobe -r vfio
## Reattach the GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO
virsh nodedev-reattach $VIRSH_GPU
virsh nodedev-reattach $VIRSH_GPU_AUDIO > /dev/null 2>&1
virsh nodedev-reattach $VIRSH_GPU > /dev/null 2>&1
## Reload the framebuffer and console
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
echo 1 > /sys/class/vtconsole/vtcon0/bind
echo 1 > /sys/class/vtconsole/vtcon1/bind
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
## Reload the Display Manager
systemctl start lightdm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment