How to Use Virtual Machine Hardware Passthrough?
Hardware passthrough is a virtualization technology that allows a virtual machine to directly access physical hardware devices on the host, rather than through an emulated virtualization layer. This enables the virtual machine to directly control the hardware for higher performance and lower latency. Common use cases include but are not limited to:
- GPU Passthrough: Supports physical display output and improves graphics processing performance.
- Sound Card Passthrough: Enables high-quality audio output through speakers or headphones.
- USB Device Passthrough: Facilitates reading USB storage devices or connecting other USB devices.
- Network Card Passthrough: Meets network acceleration and complex home networking needs.
[Risks and Limitations of Hardware Passthrough]
Hardware passthrough may introduce certain risks and limitations. Incorrect configuration may cause device conflicts or system crashes. Before proceeding, please fully understand the following risks, including but not limited to:
- Storage Passthrough Risk: Incorrectly passing through SATA, NVMe, or USB storage devices may damage data on the host, and this is irreversible. Please back up your data beforehand.
- Network Card Passthrough Risk: Ensure the host retains an available network card; otherwise, the host may lose network connectivity and become inaccessible.
- GPU Passthrough Risk: GPU passthrough has a relatively low success rate and may cause the host to crash. Proceed with caution.
Hardware passthrough is not recommended for non-professional users. If you proceed, please take precautions including but not limited to: backing up important data in advance, stopping services that depend on the corresponding hardware, and avoiding enabling auto-start for the virtual machine until stability is confirmed.
[Complexity and Success Rate of Hardware Passthrough]
Passing through PCI devices requires certain prerequisites. Users need to perform the following configuration steps, including but not limited to:
- Enable VT-x (Intel) / AMD-V (AMD) and IOMMU (Intel VT-d / AMD-Vi) hardware virtualization support in the host's BIOS settings.
- Declare IOMMU enabled in the host's GRUB configuration, update the GRUB configuration, restart, and verify.
- Configure the host to prevent driver loading for the passthrough devices to avoid resource competition, including but not limited to vfio, blacklist, and other modules.
- Assign appropriate IOMMU groups for devices on the host to ensure resource isolation.
Whether passthrough succeeds depends on multiple factors. Common reasons for failure include but are not limited to:
- Hardware compatibility: Some older or incompatible devices may not support passthrough.
- System compatibility: The operating system or version running in the virtual machine may not fully support hardware passthrough.
- Resource competition: Resource competition between the host and virtual machine for the device may cause the host or virtual machine to crash.
- Driver compatibility: The hardware device driver may not work correctly in the virtual machine, resulting in successful passthrough but inability to use the device.
In comparison, USB device passthrough does not require prerequisites, but caution is still needed to avoid damaging data on USB storage devices.
1. Enable Hardware Passthrough
Open the Virtual Machine app, click Hardware in the sidebar, find the Hardware Passthrough option, and click the Enable button. After carefully reading the Hardware Passthrough Technology Disclaimer, click Confirm Enable.

2. Configure Hardware Passthrough for Virtual Machine
In the create or edit virtual machine interface, the Add Device button becomes active after the Hardware Passthrough option is enabled.

2.1 Add USB Device
Click the Add Hardware button, then click Add USB Device.

You will see all USB devices on the current host. Select the USB device you want to pass through to the virtual machine and click the Add button.

Finally, click the Confirm button to save, then you can start the virtual machine to verify the passthrough.

2.2 Add PCI Device
Click the Add Hardware button, then click Add PCI Device.

You will see all PCI devices on the current host. Select the PCI device you want to pass through to the virtual machine from the list, then click the Select button in the lower right corner.

Since PCI devices are memory-isolated by IOMMU groups, all PCI devices in the same IOMMU group must be passed through together. After confirming, click the Add button.

Finally, click the OK button to save, then you can start the virtual machine to verify the passthrough.

3. Virtual Machine Detailed Log Guide
Due to various factors, the virtual machine may fail to start. You can check the detailed reason in the logs.
Log path: /var/apps/trim.vm/var/log/error.log
You can also copy the System Diagnosis Log to Files.


