首先编辑GRUB配置文件:

root@pve:~# vim /etc/default/grubroot@pve:~#root@pve:~# cat /etc/default/grub# If you change this file, run 'update-grub' afterwards to update# /boot/grub/grub.cfg.# For full documentation of the options in this file, see:#   info -f grub -n 'Simple configuration'GRUB_DEFAULT=0GRUB_TIMEOUT=5GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on video=efifb:off"GRUB_CMDLINE_LINUX=""# Uncomment to enable BadRAM filtering, modify to suit your needs# This works with Linux (no patch required) and with any kernel that obtains# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"# Uncomment to disable graphical terminal (grub-pc only)#GRUB_TERMINAL=console# The resolution used on graphical terminal# note that you can use only modes which your graphic card supports via VBE# you can see them in real GRUB with the command `vbeinfo'#GRUB_GFXMODE=640x480# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux#GRUB_DISABLE_LINUX_UUID=true# Uncomment to disable generation of recovery mode menu entries#GRUB_DISABLE_RECOVERY="true"# Uncomment to get a beep at grub start#GRUB_INIT_TUNE="480 440 1"root@pve:~#开启IOMMU反对:GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on video=efifb:off"如果是AMD的CPU:GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on video=efifb:off"

更新GRUB:

root@pve:~# update-grubGenerating grub configuration file ...Found linux image: /boot/vmlinuz-5.11.22-5-pveFound initrd image: /boot/initrd.img-5.11.22-5-pveFound linux image: /boot/vmlinuz-5.11.22-4-pveFound initrd image: /boot/initrd.img-5.11.22-4-pveFound memtest86+ image: /boot/memtest86+.binFound memtest86+ multiboot image: /boot/memtest86+_multiboot.bindoneroot@pve:~#

增加所需的零碎模块(驱动):

root@pve:~#root@pve:~# echo "vfio" >> /etc/modulesroot@pve:~# echo "vfio_iommu_type1" >> /etc/modulesroot@pve:~# echo "vfio_pci" >> /etc/modulesroot@pve:~# echo "vfio_virqfd" >> /etc/modulesroot@pve:~#root@pve:~# cat /etc/modules# /etc/modules: kernel modules to load at boot time.## This file contains the names of kernel modules that should be loaded# at boot time, one per line. Lines beginning with "#" are ignored.# Generated by sensors-detect on Fri Sep 24 17:22:44 2021# Chip driverscoretempvfiovfio_iommu_type1vfio_pcivfio_virqfd

接着增加模块(驱动)黑名单,即让GPU设施在下次系统启动之后不应用这些驱动,把设施腾出来给vfio驱动用:

Intel核显:

echo "blacklist snd_hda_intel" >> /etc/modprobe.d/pve-blacklist.confecho "blacklist snd_hda_codec_hdmi" >> /etc/modprobe.d/pve-blacklist.confecho "blacklist i915" >> /etc/modprobe.d/pve-blacklist.conf

N卡/A卡:

echo "blacklist nouveau" >> /etc/modprobe.d/pve-blacklist.confecho "blacklist radeon" >> /etc/modprobe.d/pve-blacklist.conf

如果是N卡还须要退出上面的配置到kvm.conf(据老外说是防止一些莫名其妙的谬误):

echo "options kvm ignore_msrs=1" > /etc/modprobe.d/kvm.conf
root@pve:~# echo "blacklist nouveau" >> /etc/modprobe.d/pve-blacklist.confroot@pve:~# echo "blacklist radeon" >> /etc/modprobe.d/pve-blacklist.confroot@pve:~#root@pve:~# cat /etc/modprobe.d/pve-blacklist.conf# This file contains a list of modules which are not supported by Proxmox VE# nidiafb see bugreport https://bugzilla.proxmox.com/show_bug.cgi?id=701blacklist nvidiafbblacklist nouveaublacklist radeonroot@pve:~#root@pve:~# echo "options kvm ignore_msrs=1" > /etc/modprobe.d/kvm.confroot@pve:~#root@pve:~# cat /etc/modprobe.d/kvm.confoptions kvm ignore_msrs=1

更新内核:

root@pve:~# update-initramfs -uupdate-initramfs: Generating /boot/initrd.img-5.11.22-5-pveRunning hook script 'zz-proxmox-boot'..Re-executing '/etc/kernel/postinst.d/zz-proxmox-boot' in new private mount namespace..No /etc/kernel/proxmox-boot-uuids found, skipping ESP sync.root@pve:~#

重启机器:

root@pve:~\# reboot

重启上来之后查看模块是否失常加载:

root@pve:~# lsmod | grep vfiovfio_pci               57344  1vfio_virqfd            16384  1 vfio_pciirqbypass              16384  11 vfio_pci,kvmvfio_iommu_type1       36864  1vfio                   36864  5 vfio_iommu_type1,vfio_pciroot@pve:~#

查看显卡

root@pve:~# lspci -nn | grep NV86:00.0 3D controller [0302]: NVIDIA Corporation TU104GL [Tesla T4] [10de:1eb8] (rev a1)root@pve:~#root@pve:~#

查看显卡ID,写入到配置中

root@pve:~# lspci -n -s 86:0086:00.0 0302: 10de:1eb8 (rev a1)root@pve:~#root@pve:~#root@pve:~# echo "options vfio-pci ids=10de:1eb8" > /etc/modprobe.d/vfio.confroot@pve:~#

https://blog.csdn.net/qq_3392...

https://my.oschina.net/u/3981543

https://www.zhihu.com/people/...

https://segmentfault.com/u/hp...

https://juejin.cn/user/331578...

https://space.bilibili.com/35...

https://cloud.tencent.com/dev...

知乎、CSDN、开源中国、思否、掘金、哔哩哔哩、腾讯云

本文应用 文章同步助手 同步