开启直通模式宿主机不需要再创建网桥,可直接在网卡上(比如eth0)设置IP
1.进入bios开启sr-iov
System BIOS——>Integrated Devices——>SR-IOV Global Enable
2.修改/etc/default/grub添加”intel_iommu=on”如最后一行
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="crashkernel=auto biosdevname=0 rhgb quiet console=ttyS0,115200"
GRUB_DISABLE_RECOVERY="true"
GRUB_CMDLINE_LINUX="intel_iommu=on ixgbe.allow_unsupported_sfp=1"
重新生成启动项:grub2-mkconfig -o
/boot/grub2/grub.cfg
注意:如果之前/etc/default/grub存在GRUB_CMDLINE_LINUX=”ixgbe.allow_unsupported_sfp=1″,那么将GRUB_CMDLINE_LINUX=”intel_iommu=on”加在GRUB_CMDLINE_LINUX=”ixgbe.allow_unsupported_sfp=1″之前,intel_iommu=on将不生效;若将其加在GRUB_CMDLINE_LINUX=”ixgbe.allow_unsupported_sfp=1″之后,那么ixgbe.allow_unsupported_sfp=1将不会生效,因此需要放在一起(猜测是由于两者都是ixgbe参数,需要一起设置)。
3.设置开机加载eth0的VF网卡,为虚拟出的VF网卡设置mac地址,Intel 82599最大支持63个VF,以下是虚拟出4个VF例子
echo ‘echo 4 > /sys/class/net/eth0/device/sriov_numvfs’
>> /etc/rc.d/rc.local
echo ‘ip link set eth0 vf 0 mac aa:bb:cc:11:22:30’
>> /etc/rc.d/rc.local
echo ‘ip link set eth0 vf 1 mac aa:bb:cc:11:22:31’
>> /etc/rc.d/rc.local
echo ‘ip link set eth0 vf 2 mac aa:bb:cc:11:22:32’
>> /etc/rc.d/rc.local
echo ‘ip link set eth0 vf 3 mac aa:bb:cc:11:22:33’
>> /etc/rc.d/rc.local
设置完如上步骤后重启机器
4.机器起来后,可通过cat /proc/cmdline|grep iommu来查询是否已开启直通
cat /proc/cmdline|grep iommu
BOOT_IMAGE=/vmlinuz-3.10.0-514.el7.x86_64 root=UUID=63f540c8-dd1b-46da-b28a-3b0a4d1814f8 ro intel_iommu=on iommu=pt ixgbe.allow_unsupported_sfp=1
5.为虚拟机添加VF网卡
可通过lspci|grep -i net查询VF的pcid,与需要添加VF网卡的虚拟机的xml配置文件关系如下:
6.启动进入虚拟机,可以查询如下(可在宿主机上通过virsh console 进入虚拟机)
lspci|grep -i net
00:03.0 Ethernet controller: Intel Corporation 82599 Ethernet Controller
Virtual Function (rev 01)
为其重命名——修改 /etc/udev/rules.d/70-persistent-net.rules文件,修改后内容如下。
SUBSYSTEMS==”pci”, ACTION==”add”, DRIVERS==”?*”, KERNELS==”0000:00:03.0″, NAME=”eth0″
然后进入/etc/sysconfig/network-scripts/为ifcfg-eth0添加IP,完成后重启虚拟机。
至此Intel 82599直通模式操作完毕。