{"id":16991300,"url":"https://github.com/gmasse/gpu-pci-passthrough","last_synced_at":"2025-03-22T15:30:58.064Z","repository":{"id":98659579,"uuid":"77849766","full_name":"gmasse/gpu-pci-passthrough","owner":"gmasse","description":"Nvidia GTX GPU Passthrough with QEMU","archived":false,"fork":false,"pushed_at":"2017-09-02T17:43:56.000Z","size":236,"stargazers_count":49,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-01T17:11:18.471Z","etag":null,"topics":["nvidia-gpu","qemu","virtualization"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gmasse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-02T17:21:30.000Z","updated_at":"2024-12-13T12:42:09.000Z","dependencies_parsed_at":"2023-03-07T16:00:33.427Z","dependency_job_id":null,"html_url":"https://github.com/gmasse/gpu-pci-passthrough","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmasse%2Fgpu-pci-passthrough","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmasse%2Fgpu-pci-passthrough/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmasse%2Fgpu-pci-passthrough/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmasse%2Fgpu-pci-passthrough/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gmasse","download_url":"https://codeload.github.com/gmasse/gpu-pci-passthrough/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244227558,"owners_count":20419261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nvidia-gpu","qemu","virtualization"],"created_at":"2024-10-14T03:25:26.941Z","updated_at":"2025-03-22T15:30:58.058Z","avatar_url":"https://github.com/gmasse.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nvidia GTX GPU Passthrough with QEMU\n\n## I. Installation\n\n#### 1. Host preparation\n\nInstall your server with Ubuntu 16.04 LTS (with Ubuntu default Kernel)\n\n\n##### i. Update system\n```\n# sudo apt-get update\n# sudo apt-get dist-upgrade\n# sudo apt-get install iptables\n```\n\n##### ii. Enable firewall\n```\nsudo iptables -A INPUT -i lo -j ACCEPT\nsudo iptables -A INPUT -p icmp -j ACCEPT\nsudo iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT\nsudo iptables -A INPUT -s MY.OFFICE.IP.ADDR -j ACCEPT\nsudo iptables -P INPUT DROP\nsudo iptables -P FORWARD DROP\nsudo ip6tables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT\nsudo ip6tables -P INPUT DROP\nsudo ip6tables -P FORWARD DROP\n\nsudo apt-get install iptables-persistent\n```\n\n##### iii. intel_iommu\n`# sudo vi /etc/default/grub`\n\nAppend `intel_iommu=on` to `GRUB_CMDLINE_LINUX_DEFAULT` variable:\n\n`GRUB_CMDLINE_LINUX_DEFAULT=\"[...] intel_iommu=on\"`\n\n##### iv. loading modules at boot\n`# sudo vi /etc/modules`\n```\nvfio\nvfio_iommu_type1\nvfio_pci\nvfio_virqfd\nkvm\nkvm_intel\n```\n\n`# sudo sh -c 'echo \"options kvm ignore_msrs=1\" \u003e /etc/modprobe.d/kvm.conf'`\n\n\n##### v. disabling nvidia driver\n`# sudo sh -c 'echo -e \"\\nblacklist nouveau\" \u003e\u003e /etc/modprobe.d/blacklist.conf'`\n\n\n#### 2. GPU cards\n\n##### i. Finding NVIDIA devices ids\n`# sudo lspci -nn -d 10de:`\n\n```\n02:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n02:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n03:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n03:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n81:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n81:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n82:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n82:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n```\nIn this example, GTX 1080 id is `10de:1b80` and its Audio Controller is `10de:10f0`\n\n`# sudo sh -c 'echo \"options vfio-pci ids=10de:1b80,10de:10f0 disable_vga=1\" \u003e /etc/modprobe.d/vfio-pci.conf'`\n\n\n#### 3. Finish preparation\n\n```\n# sudo update-grub\n# sudo update-initramfs -u\n# sudo reboot\n```\n\n\n#### 4. Verification\n\n\n##### i. Is vfio enable?\n\n`# sudo lspci -nnk | grep -i nvidia -A2`\n```\n02:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n\tSubsystem: Device [196e:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: nvidiafb, nouveau\n02:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n\tSubsystem: Device [196e:119e]\n\tKernel driver in use: vfio-pci\n--\n03:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n\tSubsystem: NVIDIA Corporation Device [10de:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: nvidiafb, nouveau\n03:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n\tSubsystem: NVIDIA Corporation Device [10de:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: snd_hda_intel\n--\n81:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n\tSubsystem: NVIDIA Corporation Device [10de:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: nvidiafb, nouveau\n81:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n\tSubsystem: NVIDIA Corporation Device [10de:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: snd_hda_intel\n--\n82:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)\n\tSubsystem: NVIDIA Corporation Device [10de:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: nvidiafb, nouveau\n82:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)\n\tSubsystem: NVIDIA Corporation Device [10de:119e]\n\tKernel driver in use: vfio-pci\n\tKernel modules: snd_hda_intel\n```\n\n\n#### 5. QEMU\n\n```\nsudo apt-get install qemu-system-x86-64 numactl\nmkdir /home/vm\ncd /home/vm\nwget 'https://software-download.microsoft.com/pr/Win10_1607_..._x64.iso?t=...' -O Win10_1607_x64.iso\nwget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso\ngit clone https://github.com/gmasse/gpu-pci-passthrough.git\n```\n\n##### EFI\n```\nsudo apt-get install git build-essential uuid-dev nasm acpica-tools iasl\nmkdir src\ncd src\ngit clone https://github.com/tianocore/edk2.git\ncd edk2\nmake -C BaseTools/Source/C\nnice OvmfPkg/build.sh -a X64 -n $(getconf _NPROCESSORS_ONLN)\ncp Build/OvmfX64/DEBUG_GCC*/FV/OVMF.fd /home/vm/\n```\n\n\n\n## II. First VM boot\n\nEdit vm.sh according to your settings\n\n`# vi /home/vm/gpu-pci-passthrough/vm.sh `\n\n\nStart the VM number 1\n\n`# sh vm.sh 1`\n\n`# sudo screen -r vm-1`\n```\nQEMU 2.5.0 monitor - type 'help' for more information\n(qemu) change vnc password\nPassword: ******\n(qemu)\n```\nPress CTRL+A CTRL+D to quit screen\n\nStart a VNC client (port 5901). On OS X, you can directly type in Safari \"vnc://SERVERIP:5901\". It will launch the Screen Sharing application.\n\n(Optional) If the UEFI shell appears at first boot. Just type exit and select continue.\nThen press any key to boot from the CD.\n![Image](doc/uefi_shell.png?raw=true)![Image](doc/qemu_boot.png?raw=true)\n\nDuring Windows installation, load viostor and NetKVM drivers from virtio-win CD drive.\n![Image](doc/wininst_virtio.png?raw=true)\n\nAfter windows restart, you can activate RDP and connect via rdp://SERVERIP:4001\n\n\n\n\n\n\n\nSource:\n- https://www.evonide.com/non-root-gpu-passthrough-setup/\n- https://www.pugetsystems.com/labs/articles/Multiheaded-NVIDIA-Gaming-using-Ubuntu-14-04-KVM-585/\n- http://vfio.blogspot.fr/2015/05/vfio-gpu-how-to-series-part-3-host.html\n- https://wiki.ubuntu.com/UEFI/EDK2\n- https://www.microsoft.com/fr-fr/software-download/windows10ISO\n- https://phocean.net/tools/french-apple-macbook-keyboard-layout-for-windows\n- https://fedoraproject.org/wiki/Windows_Virtio_Drivers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmasse%2Fgpu-pci-passthrough","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgmasse%2Fgpu-pci-passthrough","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmasse%2Fgpu-pci-passthrough/lists"}