admin管理员组

文章数量:1567520

目录

PCI Passthrough技术介绍和KVM中配置

案例

内核启用

重新启动虚拟机实例


PCI Passthrough技术介绍和KVM中配置

PCI Passthrough技术是虚拟化网卡的终极解决方案,能够让虚拟机独占物理网卡,达到最优性能,可以在网卡性能要求非常高的场景会用。但是要想迁移虚拟机,就很困难。

                                                    

# lspci |grep Ethernet |grep Intel
03:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:00.2 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)

## 查看网卡的上一级pci信息,需要将哪个interface 给虚机直接使用,就查哪个接口

# virsh nodedev-list --tree|grep enp3s0f2 -B3
  |   |    
  |   +- pci_0000_03_00_2
  |   |   |
  |   |   +- net_enp3s0f2_0c_c4_7a_80_52_0a

## 根据上一步查到的PCI信息,获取XML配置

# virsh nodedev-dumpxml pci_0000_03_00_2
……
  <capability type='pci'>
    <domain>0</domain>
    <bus>3</bus>
    <slot>0</slot>
<function>2</function>
……

## 编辑deployment xml,加入PCI设备信息,使用virsh define 定义虚拟机

<hostdev mode=’subsystem’ type=’pci’ managed=’yes’>
  <source>
    <address domain=’0x0000’ bus=’0x03’ slot=’0x00’ function=’0x2’ />
  </source>
</hostdev>

案例

virsh define deployment.ldap05
virsh start LDAP05

error: unsupported configuration: host doesn't support passthrough of host PCI devices

为虚拟机实例配置网络透传,结果报错,提示不支持,那么如何解决呢?使用PCI Pass-through,需要硬件的支持:

1、主机需要支持Intel VT-d 或者 AMD IOMMU技术

egrep --color '(vmx|svm )' /proc/cpuinfo

2、在 Linux 内核需要启用 PCI Pass-through

cat /proc/cmdline |grep intel_iommu

内核启用

cp /etc/default/grub{,.bak}

把 intel_iommu=on iommu=pt 添加到 grub 配置文件的 GRUB_CMDLINE_LINUX 一行的最后。
vi /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet intel_iommu=on iommu=pt"

刷新 grub.cfg 文件并重启宿主机生效:
mv /boot/grub2/grub.cfg{,.bak}
grub2-mkconfig -o /boot/grub2/grub.cfg

reboot

重新启动虚拟机实例

virsh start LDAP05
Domain LDAP05 started

可以看到host的网卡被透传给了虚拟机LDAP05,并且对host机器该接口将不可见,通过ip add show查看将看不到这个网卡:上面部分是host主机透传的interface,下面ens5则是虚拟机实例中展示的透传过去的宿主机enp3s0f2。

                                

在虚拟机实例上,执行下面的命令验证:查看网卡类型

# lspci | grep -i ethernet
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:05.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)

本文标签: 模型网络kvmPCIpassthrough