kvm 显卡直通

参考:
主要: https://mathiashueber.com/windows-virtual-machine-gpu-passthrough-ubuntu/

创建虚拟机参考: https://www.server-world.info/en/note?os=Ubuntu_18.04&p=kvm&f=11

lspci | grep -i nvidia

01:00.0 VGA compatible controller: NVIDIA Corporation GV102 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 10f7 (rev a1)
01:00.2 USB controller: NVIDIA Corporation Device 1ad6 (rev a1)
01:00.3 Serial bus controller [0c80]: NVIDIA Corporation Device 1ad7 (rev a1)

dmesg | grep iommu | grep 01:00

[ 0.445789] iommu: Adding device 0000:01:00.0 to group 1
[ 0.445793] iommu: Adding device 0000:01:00.1 to group 1
[ 0.445797] iommu: Adding device 0000:01:00.2 to group 1
[ 0.445801] iommu: Adding device 0000:01:00.3 to group 1

dmesg | grep "group 1"

[ 0.445702] iommu: Adding device 0000:00:01.0 to group 1
[ 0.445789] iommu: Adding device 0000:01:00.0 to group 1
[ 0.445793] iommu: Adding device 0000:01:00.1 to group 1
[ 0.445797] iommu: Adding device 0000:01:00.2 to group 1
[ 0.445801] iommu: Adding device 0000:01:00.3 to group 1

lspci -nn | grep 01:00

01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GV102 [10de:1e07] (rev a1)
01:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:10f7] (rev a1)
01:00.2 USB controller [0c03]: NVIDIA Corporation Device [10de:1ad6] (rev a1)
01:00.3 Serial bus controller [0c80]: NVIDIA Corporation Device [10de:1ad7] (rev a1)

注意右侧中括号中的id,因此我们需要预留的设备id列表为:

10de:1e07,10de:10f7,10de:1ad6,10de:1ad7

GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on pci-stub.ids=10de:1e07,10de:10f7,10de:1ad6,10de:1ad7"

记得要sudo update-grub和重启电脑
sudo update-grub

完成预留后,我们需要确保预留的设备被正确的预留了
lspci -nnv | grep -E "(^\S|Kernel driver in use)" | grep 01:00 -A 1

01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GV102 [10de:1e07] (rev a1) (prog-if 00 [VGA controller])
Kernel driver in use: nvidia
01:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:10f7] (rev a1)
01:00.2 USB controller [0c03]: NVIDIA Corporation Device [10de:1ad6] (rev a1) (prog-if 30 [XHCI])
Kernel driver in use: xhci_hcd
01:00.3 Serial bus controller [0c80]: NVIDIA Corporation Device [10de:1ad7] (rev a1)
02:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 15)

virt-install
--name centos7
--ram 8192
--disk /disk1/kvm/centos7.qcow2,size=100
--disk /disk1/kvm/CentOS-7-x86_64-DVD-2009.iso,device=cdrom,bus=ide
--cpu=host
--vcpus 8
--os-type linux
--host-device 01:00.0
--host-device 01:00.1
--host-device 01:00.2
--host-device 01:00.3
--features kvm_hidden=on
--graphics vnc,listen=0.0.0.0 &

你可能感兴趣的:(kvm 显卡直通)