Skip to content

Instantly share code, notes, and snippets.

@tankibaj
Created January 29, 2021 20:14
Show Gist options
  • Save tankibaj/91b73af9e2179933f7fb7b984e059ab7 to your computer and use it in GitHub Desktop.
Save tankibaj/91b73af9e2179933f7fb7b984e059ab7 to your computer and use it in GitHub Desktop.

Libvirt allows you to expose any USB device attached to your physical machine to the guest VMs. To do it, first, you have to get the vendor id and product id.

Run lsusb on terminal:

Qg8kPL8

Create a hostdev xml with vendor and product nano usb.xml

<hostdev mode='subsystem' type='usb'>
    <source>
        <vendor id='0x0781'/>
        <product id='0x5567'/>
    </source>
</hostdev>

Note: You have to add 0x prefix before vendor and product id.

Then, run following command to attach usb to guest vm.

virsh attach-device vmname/vmid usb.xml

This only works if the device is attached and enabled when the VM is started. The connection will be lost whenever the device is disabled or removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment