Need help with USB device passing

kokoticek

Active Member
Jun 7, 2010
121
3
38
Hello.
Just read this https://pve.proxmox.com/wiki/USB_Devices_in_Virtual_Machines and thought trying a tp-link nano usb wireless adapter and a memory stick on a Centos vm. Running latest stable Proxmox.
However I got extremly confused with the different device assignment methods.

"How to connect devices to a running machine without shutting it down is demonstrated by the examples from above. If device is assigned in that way the assignment is valid until the machine stops. The assignment is independent of the actual status of the device (whether it´s currently plugged in or not), i.e. it can be plugged in and out multiple times and will be always assigned to the VM; regardless if the "Productid" or "busaddress" method is used."

By the examples from above? Taking the Alcor stick example, how does one assign it to VM without shutting it down? With "qm set 804 -usb0 host=058f:6387" on Proxmox host's command line, or with "device_add usb-host,vendorid=0x058f,productid=0x6387,id=someid" in qm monitor? What's the difference between them?
What happens when VM stops? Is there harm if device is physically unplugged from physical host?

Regarding removing device from VM, if I wanted to permanently remove it the correct way would be first "device_del <idofyourdevice>" in qm monitor, then "qm set VMID -delete 'usbX' " in host's command line?
What happens -and what harm- in VM if just doing 2nd step without doing 1st step?
Finally, from "qm set VMID -delete 'usbX' " and /etc/pve/qemu-server/804.conf, is there a preferred way to remove device from config, or are they just 2 different ways of doing same task?

Thanks very much beforehand for help.
 
By the examples from above? Taking the Alcor stick example, how does one assign it to VM without shutting it down? With "qm set 804 -usb0 host=058f:6387" on Proxmox host's command line, or with "device_add usb-host,vendorid=0x058f,productid=0x6387,id=someid" in qm monitor? What's the difference between them?
the first command (qm set ...) writes the lines into the config and would "hotplug" the change to the vm, altough this is currently disabled because of a few technical reasons
the second is the command which actually adds the usb device to the vm

Regarding removing device from VM, if I wanted to permanently remove it the correct way would be first "device_del <idofyourdevice>" in qm monitor, then "qm set VMID -delete 'usbX' " in host's command line?
What happens -and what harm- in VM if just doing 2nd step without doing 1st step?
Finally, from "qm set VMID -delete 'usbX' " and /etc/pve/qemu-server/804.conf, is there a preferred way to remove device from config, or are they just 2 different ways of doing same task?
again the qm set command modifies the config and would "hot unplug" the device (but again this is currently disabled), while the device_del is the actual command to remove the device

so if you want to add/remove an usb device to/from a running vm, you have to use the monitor commands
if you want to make this changes persistent, do the qm set commands

editing the config file directly is also possible, but circumvents the hotplug mechanism

technical detail to usb hotplug:

we have this currently disabled, because we cannot reliably hot unplug those devices, which would break live migration,
this may change with pve 5.0 ( there were some improvements in qemu ) but no promises
 
Thanks very much!

So in summary, qm monitor device_xxx commands are the ones that hot plug/unplug usb devices into already running VMs, albeit just temporary (shutting down VM will loose all changes); qm set commands are the ones making changes permanent by writting into config file and originally should also be able to hot plug/unplug devices as well, but this last function currently doesn't work reliably thus VM restart is required to make changes apply.
Did I understand? If so, could I suggest making slight changes to the wiki?

But,
"The assignment is independent of the actual status of the device (whether it's currently plugged in or not), i.e. it can be plugged in and out multiple times and will be always assigned to the VM"
Which method does this actually refer to, qm set or device_xxx? Does it kind of try to explain the case when device is permanently assigned to a VM via qm set, the VM is started but usb device is physically NOT plugged?
Since I'm still a bit confused, this last case would look totally harmful to me!

Again, thanks for help.
 
"The assignment is independent of the actual status of the device (whether it's currently plugged in or not), i.e. it can be plugged in and out multiple times and will be always assigned to the VM"
both

when you either add the usb device with the device_add command to a running vm, or do the qm set command before rebooting/starting the vm, the usb device is "bound" to the virtual machine, whether the device is present or not

as soon as you plugin the device into the host, it gets assigned to the vm

is this a clear explanation
 
Aahh, so if I assign a usb device with either method but specifying id vendor, VM will actually do nothing (as if its "virtual usb" port was still empty) until such device is plugged into host (in any of host's usb ports), then host will automatically pass it to VM. I guess if any other usb device is plugged into host will simply not pass it to VM in this case?
And if I assign usb device with either method but specifying port, VM will just take *any* usb device connected to that host port?

Finally, what harm would do acidentally removing usb device from host while still assigned to VM? And how could it be fixed, if ever possible?

Again, thanks very much.
 
Finally, what harm would do acidentally removing usb device from host while still assigned to VM? And how could it be fixed, if ever possible?
the same as what would happen when you remove the usb device from a physical system, so this should be not a problem (for the host)
 
Thanks for all help again.

When finally trying assigning usb device (a wifi adapter) to VM in both ways I noticed it appeared enuemrated in VM, but was still enumerated in host! Should it disappear from host while assigned to VM? It's of course not possible for a single usb device whatever it is to be used by TWO machines at the same time!
 
you will not get a faster response with bumping without more information,

that said, how do you enumerate the usb devices ? with lsusb? or do you just see the network interface?
did you try it and did it work?