VMware ESXi 7
Sponsored Link

GPU Passthrough2023/03/15

 
This is the GPU Passthrough setting for Virtual Machine.
[1] To enable GPU Passthrough on shell access, configure like follows.
# switch system to the maintenance mode

[root@ctrl:~]
esxcli system maintenanceMode set --enable true
[root@ctrl:~]
lspci | grep -i nvidia

0000:02:00.0 VGA compatible controller: NVIDIA Corporation GK104 [GeForce GTX 770]
0000:02:00.1 Audio device: NVIDIA Corporation GK104 HDMI Audio Controller

# enable PCI Passthrough

[root@ctrl:~]
esxcli system settings kernel set --setting=disablePciPassthrough --value=FALSE

[root@ctrl:~]
esxcli system settings kernel list | grep disablePciPassthrough

disablePciPassthrough                    Bool    FALSE               FALSE                             FALSE               Disable PCI Passthrough

[root@ctrl:~]
esxcli hardware pci pcipassthru set --device-id=0000:02:00.0 --enable=true

[root@ctrl:~]
esxcli hardware pci pcipassthru set --device-id=0000:02:00.1 --enable=true

[root@ctrl:~]
esxcli hardware pci pcipassthru list

Device ID     Enabled
------------  -------
0000:00:19.0    false
0000:00:1a.0    false
0000:00:1b.0    false
0000:00:1d.0    false
0000:01:00.0    false
0000:02:00.0     true
0000:02:00.1     true
0000:04:00.0    false

# disable VGA driver
# *warning : after restaring System, physical console screen will not be displayed

[root@ctrl:~]
esxcli system settings kernel set --setting=vga --value=FALSE
# restart System

[root@ctrl:~]
esxcli system shutdown reboot --reason "Enable PCIpassthru"
# after restarting, unset maintenance mode

[root@ctrl:~]
esxcli system maintenanceMode set --enable false

[2] Assign GPU to a Virtual Machine.
[root@ctrl:~]
lspci | grep -i nvidia

0000:02:00.0 VGA compatible controller: NVIDIA Corporation GK104 [GeForce GTX 770]
0000:02:00.1 Audio device: NVIDIA Corporation GK104 HDMI Audio Controller

[root@ctrl:~]
lspci -n | grep 0000:02:00.0

0000:02:00.0 Class 0300: 10de:1184

[root@ctrl:~]
vim-cmd vmsvc/getallvms

Vmid          Name                                   File                                     Guest OS            Version   Annotation
2      Windows Server 2022   [VM-Data] Windows Server 2022/Windows Server 2022.vmx   windows2019srvNext_64Guest   vmx-19        
3      Ubuntu_22.04          [VM-Data] Ubuntu_22.04/Ubuntu_22.04.vmx                 ubuntu64Guest                vmx-19        

# for example, assign GPU to [Ubuntu_22.04]

[root@ctrl:~]
passthruid="0000:02:00.0"

[root@ctrl:~]
deviceId=$(lspci -n | grep ${passthruid} | awk '{print $4}' | cut -d':' -f2)

[root@ctrl:~]
vendorId=$(lspci -n | grep ${passthruid} | awk '{print $4}' | cut -d':' -f1)

[root@ctrl:~]
systemId=$(grep uuid /etc/vmware/esx.conf | awk '{print $3}')

[root@ctrl:~]
memsize=$(grep ^memSize /vmfs/volumes/VM-Data/Ubuntu_22.04/Ubuntu_22.04.vmx | awk '{print $3}')
# * impossible to set Nested Virtualization and GPU passthrough together

[root@ctrl:~]
sed -i -e '/^vhv.enable /d' /vmfs/volumes/VM-Data/Ubuntu_22.04/Ubuntu_22.04.vmx

[root@ctrl:~]
sed -i -e '/^sched.mem.minSize /d' /vmfs/volumes/VM-Data/Ubuntu_22.04/Ubuntu_22.04.vmx

[root@ctrl:~]
sed -i -e '/^sched.mem.min /d' /vmfs/volumes/VM-Data/Ubuntu_22.04/Ubuntu_22.04.vmx

[root@ctrl:~]
sed -i -e '/^sched.mem.pin /d' /vmfs/volumes/VM-Data/Ubuntu_22.04/Ubuntu_22.04.vmx
[root@ctrl:~] cat >> /vmfs/volumes/VM-Data/Ubuntu_22.04/Ubuntu_22.04.vmx <<EOF 
pciPassthru0.deviceId = "0x${deviceId}"
pciPassthru0.id = "${passthruid}"
pciPassthru0.present = "TRUE"
pciPassthru0.systemId = ${systemId}
pciPassthru0.vendorId = "0x${vendorId}"
sched.mem.pin = "TRUE"
sched.mem.min = ${memsize}
sched.mem.minSize = ${memsize}
hypervisor.cpuid.v0 = "FALSE"
EOF 

[root@ctrl:~]
vim-cmd vmsvc/reload 3

 
To enable on VMware Host Client, configure like follows.
[3] Move to [Management] - [Hardware] section and select devices you like to set passthrough, then click [Toggle passtrough] button.
[4] After enabling passthrough, [Passtrough] status turns to [Active] like follows.
After enabling it and when you would restart System, if [Passtrough] status turns to [Enabled / Needs Reboot], it needs to disable and enable setting again. Otherwise, disable default VGA driver with the command like [1] section.
[5] Set Passthrough to a Virtual Machine. Open the setting window of a Virtual Machine and click [Add other device] - [PCI device].
[6] Select a GPU device on PCI device field..
[7] On CPU setting, disable Nested Virtualization if it is enabled ([Hardware virtualization] section)
It's impossible to set Nested Virtualization and GPU passthrough together.
[8] On Memory setting, check a box [Reserve all guest memory (All locked)].
That's OK, close setting window.
[9] Start the Virtual Machine GPU Passthrough is enabled and verify it works normally.
Matched Content