Ubuntu 16.04 KVM中实现PCI Passthrough
来源:互联网 发布:windows nginx 子域名 编辑:程序博客网 时间:2024/06/06 11:39
确认环境
确认
/boot/config-XXXX
文件中与VFIO相关参数设置为y或者m。其中比较重要的是VGA、IOMMU相关参数。确认IOMMU开启,也就是BIOS与IOMMU相关选项打开 (Intel VT-d或者 AMD IOV)
# dmesg | grep IOMMU[ 0.000000] DMAR: IOMMU enabled[ 0.040828] DMAR-IR: IOAPIC id 2 under DRHD base 0xfed91000 IOMMU 1
- 确认CPU支持硬件虚拟化,有内容输入即可
# egrep -o '(vmx|svm)' /proc/cpuinfo
安装虚拟机相关软件
sudo apt-get install qemu-kvm libvirt-bin bridges-utils ovmf virt-manager uml-utilities
执行如下命令查看KVM是否安装成功
# kvm-ok输出如下为成功:INFO: /dev/kvm existsKVM acceleration can be used
查看kvm内核模块是否已加载
lsmod | grep kvm
IOMMU 开启
编辑 /etc/default/grub
中GRUB_CMDLINE_LINUX_DEFAULT
参数,将intel_iommu=on
添加在行位
使用sudo update-grub
来更新grub文件。
屏蔽Nouveau 驱动
参考 https://silenceu.me/ubuntu/disablenoveau.html
编辑/etc/modproble.d/blacklist.conf
文件,加入如下内容:
blacklist nouveaublacklist lbm-nouveauoptions nouveau modeset=0alias nouveau offalias lbm-nouveau offenter code here
然后运行以下命令禁用nouveau内核
# echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf# sudo update-initramfs -u
重启之后,使用dmesg | grep nouveau
查看,如果没有输出则成功禁止。
确认Passthrough的设备
使用lspci -nn
列出所有PCI设备和他们的地址,记录下GPU ids为 [10de:11c6] & [10de:0e0b]
查看这两个设备属于的IOMMU组,find /sys/kernel/iommu_groups/ -type l
。(如果没有显示任何内容,请确认BIOS中相应Intel VT 或 AMD IOV打开与否)查找之前记录的GPU IDS,属于group1。 如果在该组中化存在其他设备需要为kernel添加ACS Patch,相应的方法参见链接。如果只有一个组,则进行下一步。
Kernel 4.8 added better support for IOMMU group separation. If your GPU’s IOMMU group has another device in it with the address 00:01.0 then you don’t need the ACS patch.
配置PCI IDS
首先创建 /etc/modprobe.d/vfio.conf
文件,将相应的GPU PCI IDs 添加进去
options vfio-pci ids=10de:11c6,10de:0e0b
然后编辑 /etc/default/grub
中GRUB_CMDLINE_LINUX_DEFAULT
参数,将vfio-pci.ids=10de:11c6,10de:0e0b
添加在行位
使用sudo update-grub
来更新grub文件。
将vfio相关模块添加到initrd
编辑文件/etc/initramfs-tools/modules
vfiovfio_iommu_type1vfio_pcivfio_virqfd
保存,并且更新initrdsudo update-initramfs -u
qemu 配置文件中开启passthrough
编辑 /etc/libvirt/qemu.conf
取消改行的注释
nvram = [ "/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd"]
重启查看配置
查看vfio-pci.ids 是否设置成功dmesg | grep vfio-pci.ids
查看vfio相关模块是否加载成功
查看GPU驱动是否为vfio-pci(lspci -vv)
使用
- 为虚拟机添加PCI 设备时将GPU配置给VM
- 在VM中使用NVIDIA GPU时需要,将对VM的 配置文件进行修改。因为NVIDIA GPU 会阻止VM中的驱动加载到GPU上,所以需要在qemu中设置隐藏VM的状态,让GPU无法检测到时VM在控制GPU
<features> ... <kvm> <hidden state='on'/> </kvm> ... </features>
参考链接
https://forum.level1techs.com/t/play-games-in-windows-on-linux-pci-passthrough-quick-guide/108981?source_topic_id=110696
https://scottlinux.com/2016/08/28/gpu-passthrough-with-kvm-and-debian-linux/
http://www.firewing1.com/howtos/fedora-20/create-gaming-virtual-machine-using-vfio-pci-passthrough-kvm
- http://blog.csdn.net/c80486/article/details/42836169
- Ubuntu 16.04 KVM中实现PCI Passthrough
- fedora 18 kvm pci passthrough
- CentOS7 中Xen PCI passthrough
- PCI passthrough
- xen pci-passthrough 2
- pci passthrough with qemu
- xen pci-passthrough 2
- KVM中网络桥接(VEPA Bridge Privdge Passthrough)
- pci-passthrough of openstack havana
- qemu使用PCI passthrough设备
- VGA GPU passthrough 虚拟桌面pci穿透--Ubuntu与centos的内核升级步骤
- Question for KVM VGA-Passthrough
- Libvirt之vfio pci的passthrough
- Centos 7 + Openstack + PCI passthrough(透传)
- Libvirt之vfio pci的passthrough
- 【KVM】英特尔SR-IOV实现PCI硬件资源共享
- kvm qemu pci passthough
- Linux中PCI的实现
- caffe feathermap extract
- Android 设计模式——————单列模式——————简单的单列模式在项目中的运用
- java创建安全的单例模式
- get last success from jenkins's home page:获取jenkins的job的last success等数据。以及jenkins's api的介绍
- 判断是否有网络
- Ubuntu 16.04 KVM中实现PCI Passthrough
- C++ "#"的作用和用法
- 系统性能优化方案
- Mongodb连接失败问题的几种情况和解决方式
- Alexnet在android手机中的tensorflow和arm compute libraray的性能对比
- struts2启动错误Unable to load configuration.
- LORAWAN A B C
- websocket页面与后台会话
- wps将word文档转换为图片格式