0
  1. 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.

  2. 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>
dandreye
  • 11
  • 2
  • 6
  • not sure about the `
    ` you use in the XML, but [here is an example of how a USB device is attached to a running VM](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_administration_guide/sect-managing_guest_virtual_machines_with_virsh-attaching_and_updating_a_device_with_virsh) note the use of vendor/product to identify the USb device - also, please show the exact command you run i.e. the arguments you pass to `virsh attach-device`
    – Jaromanda X Feb 08 '23 at 22:45
  • @JaromandaX: Thank you: looks like I should be referring to vendor/product indeed. To apply that xml config I used "virsh attach-device MyVM phone.xml" as per StefC's answer here: https://unix.stackexchange.com/questions/561384/passing-a-usb-device-to-qemu-kvm. So I didn't prefix phone.xml with --file. – dandreye Feb 08 '23 at 23:08
  • @JaromandaX: it also looks like using --current is critical for an immediate effect (that'd then explain why there wasn't any w/o this option) and --permanent helps the mapping survive the USB device and/or the VM or the server reboot, right? – dandreye Feb 08 '23 at 23:28
  • that seems to be what the documentation for`virsh attach-device` is saying – Jaromanda X Feb 08 '23 at 23:32
  • Great: I'll report on the outcome once I get a chance to give it a try. – dandreye Feb 08 '23 at 23:34
  • @JaromandaX: Unfortunately it still doesn't work for some reason. I tried with --current and then with --persistent (they're mutually exclusive) and without them and still no luck either way. Repeated each test twice to be sure. – dandreye Feb 10 '23 at 22:49

0 Answers0