当前位置:网站首页>KVM 显卡透传 —— 筑梦之路
KVM 显卡透传 —— 筑梦之路
2022-06-26 12:35:00 【筑梦之路】
前置条件
显卡直通依赖于一些虚拟化技术, 可能在你的机器上不可用, 必须先检查以下条件:
首先CPU必须支持硬件虚拟化(for KVM)和IOMMU(for 直通)
兼容的 Intel CPUs 列表 (Intel VT-x and Intel VT-d). 可以理解为 Intel VT-x 是CPU的虚拟化,VT-d 是 I/O 设备的虚拟化,两个东西不一样。
Bulldozer 及更高版本(包括 Zen)的所有 AMD CPU 都应该兼容。
主板必须支持 IOMMU
芯片组和 BIOS 必须都支持 IOMMU。很难直接看出来是否支持,但是有一个比较完整的列表供查询:Xen Wiki 和 Wikipedia:List of IOMMU-supporting hardware
GPU ROM 必须支持 UEFI。2012 年以后的 GPU 几乎都支持。
比较方便的检查方法就是在BIOS设置中找到并打开 VT-d (Intel) 或者 IOMMU (AMD)。如果没有这些选项,那就是不支持。
在KVM主机上启动IOMMU
# 首先编辑文件
$ vim /etc/default/grub
# 第6行: 添加 intel_iommu=on (如果是AMD CPU, 添加 [amd_iommu=on])
# 还应该添加参数 iommu=pt, 阻止 Linux 接触不能透传的设备
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet intel_iommu=on iommu=pt"
GRUB_DISABLE_RECOVERY="true"
$ grub2-mkconfig -o /boot/grub2/grub.cfg
$ reboot # 重启重启之后验证IOMMU是否启用:
$ dmesg | grep -E "DMAR|IOMMU"
[ 0.000000] ACPI: DMAR 00000000bf79e0d0 00118 (v01 AMI OEMDMAR 00000001 MSFT 00000097)
[ 0.000000] DMAR: IOMMU enabled
[ 0.069846] DMAR: Host address width 40
[ 0.069848] DMAR: DRHD base: 0x000000fbffe000 flags: 0x1
[ 0.069856] DMAR: dmar0: reg_base_addr fbffe000 ver 1:0 cap c90780106f0462 ecap f020fe
[ 0.069858] DMAR: RMRR base: 0x000000000ec000 end: 0x000000000effff
[ 0.069859] DMAR: RMRR base: 0x000000bf7ec000 end: 0x000000bf7fffff
[ 0.069861] DMAR: ATSR flags: 0x0
[ 0.069863] DMAR-IR: IOAPIC id 6 under DRHD base 0xfbffe000 IOMMU 0
[ 0.070128] DMAR-IR: Enabled IRQ remapping in xapic mode
[ 0.960840] DMAR: dmar0: Using Queued invalidation
[ 0.960860] DMAR: Setting RMRR:
[ 0.960890] DMAR: Setting identity map for device 0000:00:1a.0 [0xbf7ec000 - 0xbf7fffff]
[ 0.960925] DMAR: Setting identity map for device 0000:00:1a.1 [0xbf7ec000 - 0xbf7fffff]
[ 0.960958] DMAR: Setting identity map for device 0000:00:1a.2 [0xbf7ec000 - 0xbf7fffff]
[ 0.960994] DMAR: Setting identity map for device 0000:00:1a.7 [0xbf7ec000 - 0xbf7fffff]
[ 0.961031] DMAR: Setting identity map for device 0000:00:1d.0 [0xbf7ec000 - 0xbf7fffff]
[ 0.961064] DMAR: Setting identity map for device 0000:00:1d.1 [0xbf7ec000 - 0xbf7fffff]
[ 0.961100] DMAR: Setting identity map for device 0000:00:1d.2 [0xbf7ec000 - 0xbf7fffff]
[ 0.961132] DMAR: Setting identity map for device 0000:00:1d.7 [0xbf7ec000 - 0xbf7fffff]
[ 0.961153] DMAR: Setting identity map for device 0000:00:1a.0 [0xec000 - 0xeffff]
[ 0.961167] DMAR: Setting identity map for device 0000:00:1a.1 [0xec000 - 0xeffff]
[ 0.961182] DMAR: Setting identity map for device 0000:00:1a.2 [0xec000 - 0xeffff]
[ 0.961196] DMAR: Setting identity map for device 0000:00:1a.7 [0xec000 - 0xeffff]
[ 0.961210] DMAR: Setting identity map for device 0000:00:1d.0 [0xec000 - 0xeffff]
[ 0.961224] DMAR: Setting identity map for device 0000:00:1d.1 [0xec000 - 0xeffff]
[ 0.961238] DMAR: Setting identity map for device 0000:00:1d.2 [0xec000 - 0xeffff]
[ 0.961255] DMAR: Setting identity map for device 0000:00:1d.7 [0xec000 - 0xeffff]
[ 0.961270] DMAR: Prepare 0-16MiB unity mapping for LPC
[ 0.961287] DMAR: Setting identity map for device 0000:00:1f.0 [0x0 - 0xffffff]
[ 0.961424] DMAR: Intel(R) Virtualization Technology for Directed I/O启动 vfio-pci 内核模块
保留 RHEL/CentOS 官方提供的通用内核即可
$ uname -a
# 显示显卡的PCI认证数字和[供应商ID:设备ID]
$ lspci -nn | grep -i nvidia
3b:00.0 3D controller [0302]: NVIDIA Corporation GP104GL [Tesla P4] [10de:1bb3] (rev a1)
86:00.0 3D controller [0302]: NVIDIA Corporation GP104GL [Tesla P4] [10de:1bb3] (rev a1)
# 编辑vfio配置文件
$ vim /etc/modprobe.d/vfio.conf
# 创建一个新行,指定ids=供应商ID:设备ID
options vfio-pci ids=10de:1bb3,10de:1bb3
# 创建一个新文件,写入 vfio-pci
$ echo 'vfio-pci' > /etc/modules-load.d/vfio-pci.conf
$ reboot # 重启重启之后检查 vfio 是否加载
$ dmesg | grep -i vfio
[ 6.441900] VFIO - User Level meta-driver version: 0.3
[ 6.497125] vfio-pci: probe of 0000:3b:00.0 failed with error -22
[ 6.497163] vfio-pci: probe of 0000:86:00.0 failed with error -22
[ 6.497181] vfio_pci: add [10de:1bb3[ffff:ffff]] class 0x000000/00000000
[ 6.497233] vfio-pci: probe of 0000:3b:00.0 failed with error -22
[ 6.497249] vfio-pci: probe of 0000:86:00.0 failed with error -22
[ 6.497258] vfio_pci: add [10de:1bb3[ffff:ffff]] class 0x000000/00000000更新QEMU
# 查看QEMU版本
$ /usr/libexec/qemu-kvm -version
QEMU emulator version 1.5.3 (qemu-kvm-1.5.3-175.el7_9.3), Copyright (c) 2003-2008 Fabrice Bellard
# 升级新版
$ yum -y install centos-release-qemu-ev
Running transaction
Installing : centos-release-virt-common-1-1.el7.centos.noarch 1/2
Installing : centos-release-qemu-ev-1.0-4.el7.centos.noarch 2/2
Verifying : centos-release-qemu-ev-1.0-4.el7.centos.noarch 1/2
Verifying : centos-release-virt-common-1-1.el7.centos.noarch 2/2
Installed:
centos-release-qemu-ev.noarch 0:1.0-4.el7.centos
Dependency Installed:
centos-release-virt-common.noarch 0:1-1.el7.centos
# 关闭 CentOS-QEMU-EV
$ sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-QEMU-EV.repo
# 将 qemu-kvm 替换成 qemu-kvm-ev
$ yum --enablerepo=centos-qemu-ev -y install qemu-kvm-ev
$ systemctl restart libvirtd
# 查看 KVM 版本
$ /usr/libexec/qemu-kvm -version
QEMU emulator version 2.12.0 (qemu-kvm-ev-2.12.0-44.1.el7_8.1)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
# 验证是否包含了 q35
$ /usr/libexec/qemu-kvm -machine help | grep q35
q35 RHEL-7.6.0 PC (Q35 + ICH9, 2009) (alias of pc-q35-rhel7.6.0)
pc-q35-rhel7.6.0 RHEL-7.6.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.5.0 RHEL-7.5.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.4.0 RHEL-7.4.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.3.0 RHEL-7.3.0 PC (Q35 + ICH9, 2009)创建新虚拟机
$ virt-install \
--name centos7 \
--ram 8192 \
--disk path=ubuntu16.img,size=30 \
--vcpus 4 \
--os-type linux \
--os-variant ubuntu16.04 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location ubuntu-16.04.7-server-amd64.iso \
--extra-args 'console=ttyS0,115200n8 serial' \
--host-device 3b:00.0 \
--features kvm_hidden=on \
--machine q35
参数解释:
name 虚拟机名称
ram 内存大小
disk 指定存储设备及类型
vcpus 虚拟 CPU 个数
os-type 操作系统类型
os-variant 具体操作系统变体
network 连接宿主机的网桥或网络
graphics 虚拟机显示器访问接口,默认是 vnc
console ??
location 安装源, 支持 FTP、HTTP 及 NFS 等
extra-args 当执行从 –location 选项指定位置的客户机安装时,附加内核命令行参数到安装程序
host-device 附加物理设备到客户机
features kvm_hidden=on 从宿主机隐藏虚拟机状态
machine QEMU模拟的CPU架构边栏推荐
- 2022 edition of investment analysis and "fourteenth five year plan" development prospect forecast report of China's switchgear industry
- Scala-day06- pattern matching - Generic
- PHP generate order number
- Generate JDE dot train
- PHP unit conversion
- Spark-day03-core programming RDD operator
- NoSQL mongodb - 04 mongodb database and web service combination case
- MySQL optimization - index (what is an index?)
- Implementing mixins scheme in applet
- "Pinduoduo and short video speed version", how can I roast!
猜你喜欢

nvm安装教程

Tiger DAO VC产品正式上线,Seektiger生态的有力补充

Less than 40 lines of code to create a blocprovider
Adobe Acrobat阻止30款安全软件查看PDF文件 或存在安全风险

Microservice governance (nocas)

Configuring Apache digest authentication

Scala-day02- variables and data types

Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology

Realize microservice load balancing (ribbon)

软件测试 - 基础篇
随机推荐
Mongodb of NoSQL - 03 mongodb CRUD
Laravel subdomain accesses different routing files and different modules
洛谷P3426 [POI2005]SZA-Template 题解
2022 edition of China's energy and chemical industry market in-depth investigation and investment feasibility analysis report
NFS shared storage service installation
710. 黑名单中的随机数
小程序中控件里面的内容较多,让其支持滚动的良好方案
Is it safe to open a securities account in general
Iframe usage and contentwindow, parent and PostMessage communication methods
Thinkphp5 query report: sqlstate[hy093]: invalid parameter number
Spark-day03-core programming RDD operator
.NET MAUI 性能提升
Php+laravel5.7 use Alibaba oss+ Alibaba media to process and upload image / video files
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
Vscode solves the problem of Chinese garbled code
班主任让开股票账户,在挖财理财开户安全吗?
The loss of female scientists
Redis cannot connect to the server through port 6379
TSMC Samsung will mass produce 3nm chips in 2022: will the iPhone be the first?
栈,后入先出