虚拟机设置参数 (仅必须参数)

  • 安全
    • 启用受信任的平台模块

      虚拟机操作系统为 Windows 11 时需要

  • 内存
    • 启用动态内存
  • 检查点
    • 启用检查点
  • 自动启动操作
  • 自动停止操作 强行关闭虚拟机

虚拟机分配 VGPU

在虚拟机关机状态下执行命令, 以管理员身份在 PowerShell 运行

来自 https://zhuanlan.zhihu.com/p/659002027 评论区, 仅供参考
只有这两条命令是必须的
Set-VM -HighMemoryMappedIoSpace 32GB -VMName <虚拟机名称>
(可根据需要调整, 默认值的情况下无法初始化虚拟显卡)
Add-VMGpuPartitionAdapter -VMName <虚拟机名称>
(添加 GPU 分区适配器)
其余命令都是可选的, 可以按需要调整.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 查看物理机支持 VGPU 的 GPU 信息
# 注意以下参数: Name (VEN_8086 为 Intel, VEN_1002 为 AMD, VEN_10DE 为NVIDIA)
# MinPartitionVRAM
# MaxPartitionVRAM
# OptimalPartitionVRAM
# MinPartitionEncode
# MaxPartitionEncode
# OptimalPartitionEncode
# MinPartitionDecode
# MaxPartitionDecode
# OptimalPartitionDecode
# MinPartitionCompute
# MaxPartitionCompute
# OptimalPartitionCompute
Get-VMHostPartitionableGpu

# 查看虚拟机详细设置参数
Get-VM -Name "test" | Format-List *

# 查看虚拟机已分配的 VGPU
Get-VMGpuPartitionAdapter -VMName "test"

# 删除虚拟机所有已分配的 VGPU
Remove-VMGpuPartitionAdapter -VMName "test"

# 启用 GuestControlledCacheTypes, 优化性能
Set-VM -GuestControlledCacheTypes $true -VMName "test"

# 设置低内存映射 I / O 空间为 1GB
Set-VM -LowMemoryMappedIoSpace 1GB -VMName "test"

# 设置高内存映射 I / O 空间为 1 + (虚拟机分配的内存大小) GB
Set-VM -HighMemoryMappedIoSpace 9GB -VMName "test"

# 虚拟机分配 VGPU
# Add-VMGpuPartitionAdapter
# [-VMName] <String[]>
# [-InstancePath <String>]
# [-MinPartitionVRAM <UInt64>]
# [-MaxPartitionVRAM <UInt64>]
# [-OptimalPartitionVRAM <UInt64>]
# [-MinPartitionEncode <UInt64>]
# [-MaxPartitionEncode <UInt64>]
# [-OptimalPartitionEncode <UInt64>]
# [-MinPartitionDecode <UInt64>]
# [-MaxPartitionDecode <UInt64>]
# [-OptimalPartitionDecode <UInt64>]
# [-MinPartitionCompute <UInt64>]
# [-MaxPartitionCompute <UInt64>]
# [-OptimalPartitionCompute <UInt64>]

# 实际命令
Add-VMGpuPartitionAdapter -VMName "test" -InstancePath "xxxxxxx"

虚拟机安装显卡驱动

  1. 物理机 windows键 + R 运行 dxdiag, 点击保存所有信息, 在 Display Devices 查找显卡驱动位置, 比如 C:\WINDOWS\System32\DriverStore\FileRepository\xxxx, 将该文件夹复制到虚拟机的 C:\Windows\System32\HostDriverStore\FileRepository\ 位置.
  2. 将物理机的 C:\Windows\System32\nvapi64.dll 复制到虚拟机的相同位置.
  3. 重启虚拟机

一些问题的解决方案

虚拟显示器可以用 Virtual Display Driver, 模拟声卡可以用 vb-audio, 串流可以用 moonlight + sunshine

参考链接