I need to map my USB device (a OnePlus 10T smartphone) connected to a CentOS 7 server to a VM on it. It works fine when I do it in virt-manager GUI, but closing the VM window in the GUI immediately damages a working mapping. Why? If I reopen the VM window I can still see the old mapping there but that doesn't help the VM resume seeing the device - only re-mapping the device again does.
Apparently doing the above inserts a hostdev structure into the VM config (virsh dumpxml):
<hostdev mode='subsystem' type='usb' managed='yes'> <source> <vendor id='0x22d9'/> <product id='0x2765'/> <address bus='2' device='121'/> </source> <alias name='hostdev0'/> <address type='usb' bus='0' port='4'/> </hostdev>
However when (after removing the old mapping made in the GUI) I try using virsh attach-device with an xml file with the contents below (assuming 115 is looked up for my device in lsusb output beforehand):
<hostdev mode='subsystem' type='usb' managed='yes'>
<source>
<address bus='1' device='115'/>
</source>
</hostdev>
the mapping doesn't work (the VM cannot see the device) even though it results in exact same changes in virsh dumpxml. I can even see device # increment in lsusb output, like it always does when using the GUI way. Am I missing something else here to make it work "manually" w/o the GUI running?
Thanks in advance!
Update: virsh attach-device doesn't work with the following xml file contents as per this guide either (tried it with --current, --persistent and w/o them - still no luck):
<hostdev mode='subsystem' type='usb' managed='yes'>
<source>
<vendor id='0x22d9'/>
<product id='0x2765'/>
</source>
</hostdev>