Windows系统下如何通过Qemu实现USB设备(含U盘)直通?
Alright, let's break down how to pass through USB devices (including USB drives) from your Windows host to a QEMU guest. I’ve tinkered with this plenty of times, so here’s the reliable step-by-step guide:
First, make sure you’ve got these squared away:
- Install the latest version of QEMU for Windows (older versions might have wonky USB passthrough support).
- Grab your USB device’s VID (Vendor ID) and PID (Product ID)—you’ll need these to target the right device. Here’s how to find them:
- Open Device Manager (right-click Start → Device Manager).
- Expand the "Universal Serial Bus devices" section, find your USB device (e.g., your flash drive).
- Right-click it → Properties → Details tab.
- From the dropdown, select "Hardware Ids". You’ll see something like
USB\VID_1234&PID_5678—note down the1234and5678values (we’ll use them as0x1234and0x5678later).
This is my go-to method because it gives full control. When launching your QEMU VM, add one of these parameters to the command line:
Option A: Target by VID/PID (Recommended)
This works even if your USB device’s bus/port changes (super handy for portable drives). Add this line to your QEMU launch command:
-device usb-host,vendorid=0xYYYY,productid=0xZZZZ
Replace 0xYYYY with your device’s VID and 0xZZZZ with its PID. For example:
qemu-system-x86_64 -hda my_vm_disk.qcow2 -m 4G -device usb-host,vendorid=0x1234,productid=0x5678
Option B: Target by Bus/Port
If you prefer targeting the physical bus/port (good for fixed devices), first find the bus and address:
- Open Command Prompt as Administrator and run:
This will list all connected USB devices with theirqemu-system-x86_64 -device usb-host,list=truehostbusandhostaddrvalues. - Add this parameter to your launch command:
Replace-device usb-host,hostbus=X,hostaddr=YXandYwith the numbers from the list.
Pro tip: If you’re passing through a USB 3.0 device, add a USB 3.0 controller to your VM first to get full speed:
-device nec-usb-xhci,id=xhci
If you hate typing commands, use a QEMU GUI like QEMU Manager or QuickEMU (Windows-compatible):
- Open your GUI tool and load your existing VM configuration.
- Navigate to the "USB" or "Peripherals" settings section.
- Click "Add USB Device" and select your target USB drive/device from the dropdown list.
- Save the configuration and start the VM—your device should show up in the guest OS automatically.
If things don’t work right away, try these fixes:
- Run QEMU as Administrator: USB passthrough requires elevated permissions—right-click your QEMU shortcut/command prompt and select "Run as administrator".
- Eject the USB device first: If your drive is mounted in Windows, safely eject it before starting the VM. Windows locks mounted drives, so QEMU can’t grab them.
- Check for conflicting software: Some antivirus or USB management tools might block QEMU from accessing USB devices. Temporarily disable them to test.
- Verify controller compatibility: If your USB 3.0 device isn’t detected, make sure you added the
nec-usb-xhcicontroller to your VM command (as mentioned earlier).
内容的提问来源于stack exchange,提问作者david moheban

