Skip to content

Instantly share code, notes, and snippets.

@mpvasilis
Forked from Ruffo324/Hyper-V PCI-Passthroug.ps1
Created November 4, 2022 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpvasilis/b55d89d26644b6f51b5ae4d0fe7acc8f to your computer and use it in GitHub Desktop.
Save mpvasilis/b55d89d26644b6f51b5ae4d0fe7acc8f to your computer and use it in GitHub Desktop.
Hyper-V PCIe passthrough CheatSheet
# Change to name of TARGET-VM.
$vm='CHANGE_ME'
# Change to PCI device location (💡 Location).
$Location = 'CHANGE_ME'
# Enable CPU features.
Set-VM -GuestControlledCacheTypes $true -VMName $vm
# Host-Shutdown rule must be changed for the VM.
Set-VM -Name $vm -AutomaticStopAction TurnOff
# Change size to fit your requirements ("💡 Min required MMOU Space").
# (See https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/plan/plan-for-deploying-devices-using-discrete-device-assignment#mmio-space)
Set-VM -LowMemoryMappedIoSpace 3Gb -VMName $vm # 32bit
Set-VM -HighMemoryMappedIoSpace 6Gb -VMName $vm # 64bit
# Dismount device
Dismount-VMHostAssignableDevice -LocationPath $Location
Dismount-VMHostAssignableDevice -force -LocationPath $Location
Add-VMAssignableDevice -LocationPath $Location -VMName $vm
# Try start the VM in Hyper-V manager.
# ❓ Starting fails with: "A hypervisor feature is not available to the user." ❓
# See: https://social.technet.microsoft.com/Forums/ie/en-US/a7c2940a-af32-4dab-8b31-7a605e8cf075/a-hypervisor-feature-is-not-available-to-the-user?forum=WinServerPreview
# Reboot host.
bcdedit /set hypervisoriommupolicy enable
Restart-Computer -Confirm
# SOURCE: https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/plan/plan-for-deploying-devices-using-discrete-device-assignment#machine-profile-script
# 1. Get Powershell script-helper:
curl -o SurveyDDA.ps1 https://raw.githubusercontent.com/MicrosoftDocs/Virtualization-Documentation/live/hyperv-tools/DiscreteDeviceAssignment/SurveyDDA.ps1
# 2. Run the script.
.\SurveyDDA.ps1
# Find your device (must be enabled). See valid example:
#
#
# AMD PSP 3.0 Device <---- 💡 Device name
# Express Endpoint -- more secure.
# And its interrupts are message-based, assignment can work.
# And it requires at least: 2 MB of MMIO gap space <---- 💡 Min required MMOU Space
# PCIROOT(0)#PCI(0701)#PCI(0002) <---- 💡 Location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment