自动化kolla-ansible部署openstack+GPU透传方法
欢迎加QQ群:1026880196 进行交流学习
1. CentOS7.x-8.x系列为虚拟机配置GPU直通
1. 编辑文件vim /etc/modules, 添加以下内容:
pci_stub
vfio
vfio_iommu_type1
vfio_pci
kvm
kvm_intel
2. 在KVM主机上启用IOMMU
#对于Intel芯片:
GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on"
#对于AMD芯片:
GRUB_CMDLINE_LINUX_DEFAULT="iommu=pt iommu=1"
vim /etc/default/grub
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 rhgb quiet intel_iommu=on"
GRUB_DISABLE_RECOVERY="true"
3. 重新生成grub
EFI
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
非EFI
grub2-mkconfig -o /boot/grub2/grub.cfg
4. 将下列内容加入到blacklist中以避免被宿主机占用,编辑文件
vim /etc/modprobe.d/
blacklist.conf
blacklist snd_hda_intel
blacklist amd76x_edac
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
blacklist nvidia
5. 查找显卡的Product ID 以及 Vendor ID:
yum install pciutils -
y
lspci -nn |
grep NVIDIA
如下:
[root@stein-a ~
]#
03:
00.0 VGA compatible controller [
0300]: NVIDIA Corporation GP104GL [Quadro P4000] [10de:1bb1] (rev a1)
03:
00.1 Audio device [
0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)
6. 编辑
vim /etc/modprobe.d/
vfio.conf
# create new:
for [ids=***], specify [vendor-ID:device-
ID]
options vfio-pci ids=
10de:1bb1,10de:10f0
7. 写入到系统启动项
echo 'vfio-pci' > /etc/modules-load.d/vfio-
pci.conf
8. 重新生成initramfs
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -
r).img.bak
dracut -v /boot/initramfs-$(uname -r).img $(uname -
r)
9. 重启系统
reboot
10. 验证
lspci -nnk -
d 10de:1bb1
dmesg | grep -
i vfio
[root@stein-a ~]# lspci -nnk -
d 10de:1bb1
03:
00.0 VGA compatible controller [
0300]: NVIDIA Corporation GP104GL [Quadro P4000] [10de:1bb1] (rev a1)
Subsystem: NVIDIA Corporation Device [10de:11a3]
Kernel driver in use: vfio-
pci
Kernel modules: nouveau
[root@stein-a ~]# dmesg | grep -
i vfio
[ 2.503115] VFIO - User Level meta-driver version:
0.3
[ 2.515645] vfio_pci: add [10de:1bb1[ffff:ffff]]
class 0x000000/
00000000
[ 2.515752] vfio_pci: add [10de:10f0[ffff:ffff]]
class 0x000000/
00000000
[root@stein-a ~]#