[Plug-In] Hotplug USB for Virtual Machines


Recommended Posts

Does anyone know if this plugin is still being worked on?

 

I have 2 vms which use hotplug all the time but it would be great if I could replace my 2 usb controllers for this plugin

 

The main thing I need to do is pass usb hubs over, once the hub is passed through I would presume all connected usbs would be also?

 

I haven't tried this yet but I want to clarify before installing it :)

 

My usb hubs are not shown as devices that can be passed through under the vm manager window if that makes a difference

Link to comment

Does anyone know if this plugin is still being worked on?

 

I have 2 vms which use hotplug all the time but it would be great if I could replace my 2 usb controllers for this plugin

 

The main thing I need to do is pass usb hubs over, once the hub is passed through I would presume all connected usbs would be also?

 

I haven't tried this yet but I want to clarify before installing it :)

 

My usb hubs are not shown as devices that can be passed through under the vm manager window if that makes a difference

 

Well i am currently maintaining the plugin as its in my regular use. So will fix any issues caused by upgrades of Unraid Versions (Curently works with 6.1 and 6.2 Beta). As for your request it will not work with this plugin. This plugin works with USB attach functionality built in into QEMU (Virsh). It works with USB Hubs but cannot pass-through the HUB itself. Only able to pass-through Devices plugged into a HUB.

 

I found this from Proxmox Documentation which also uses QEMU.

 

Assigning Devices to VMs

 

Note that only "real" devices can be assigned, i.e. assigning of USB hubs is not possible.

 

Also i am using the same library of Unraid to display devices which is used in VM Page. Which specifically filters USB Hubs from the list of USB Devices because they are not supported. So i am afraid you have to continue using the 2 USB Controllers.

 

 

 

 

Link to comment

Hey and thanks for the plugin!

 

I guess that when attaching one USB to VM, it disappears from the unRAID server..

now,

will it reattached automatically to the unRAID server after stopping the VM or after restarting the unRAID server?

 

thanks.

 

if not,

is there a way for attaching one or two USB devices permanently to a VM?

 

Thanks!

Link to comment

Thanks for putting this out. I never did get around to finalizing this since they took over the vm manager. What I had put together was a drop down checklist for each vm between memory and hard drives and was using virsh like you did. I don't think I pushed any of that to my github but your welcome to it if you want.

 

Here's the usbhotplug.php I was using. I added the persistent option so it would save to the vm when shutdown. Otherwise you lose the usb you hot plugged. I'm not sure if that's something people would want or would want an option to save it.

<?
$arrValues = explode(":",$_POST["values"]);
$xml = "<hostdev mode='subsystem' type='usb' managed='yes'>
  <source>
    <vendor id='0x{$arrValues[1]}'/>
    <product id='0x{$arrValues[2]}'/>
  </source>
</hostdev>";
$filename = "/usr/local/emhttp/plugins/dynamix.vm.manager/usb.xml";
file_put_contents($filename, $xml);
$cmd = "virsh {$_POST['options']} --domain '{$arrValues[0]}' --file '$filename' --persistent 2>&1";
exec($cmd, $arrOutput);
echo $arrOutput[1];
?>

 

Also I noticed you used the dynamix plg as a template but left some of the original comments in there.

 

Good job on plugin. It works great.

Link to comment

Thanks for putting this out. I never did get around to finalizing this since they took over the vm manager. What I had put together was a drop down checklist for each vm between memory and hard drives and was using virsh like you did. I don't think I pushed any of that to my github but your welcome to it if you want.

 

Here's the usbhotplug.php I was using. I added the persistent option so it would save to the vm when shutdown. Otherwise you lose the usb you hot plugged. I'm not sure if that's something people would want or would want an option to save it.

<?
$arrValues = explode(":",$_POST["values"]);
$xml = "<hostdev mode='subsystem' type='usb' managed='yes'>
  <source>
    <vendor id='0x{$arrValues[1]}'/>
    <product id='0x{$arrValues[2]}'/>
  </source>
</hostdev>";
$filename = "/usr/local/emhttp/plugins/dynamix.vm.manager/usb.xml";
file_put_contents($filename, $xml);
$cmd = "virsh {$_POST['options']} --domain '{$arrValues[0]}' --file '$filename' --persistent 2>&1";
exec($cmd, $arrOutput);
echo $arrOutput[1];
?>

 

Also I noticed you used the dynamix plg as a template but left some of the original comments in there.

 

Good job on plugin. It works great.

 

I knew about the persistent option. But i didn't include it since it modifies the Domain XML file which will be redundant since this functionality is already available in VM Manager. If someone wants to associate a USB device with a VM permanently they can do it from VM Manager instead of my plugin.

 

But one thing i need help with is reattaching the USB device automatically back to VM when someone physically remove the USB and replug it while the VM is running.

 

I understood that udev handles all physical devices attached to a linux machine. But coudnt figure out how to isolate only few usb devices and detach/reattach them to VM upon unplugging and plugging.

 

If you can provide any assistance regarding this issue. It will be great help to finalize v2.0 of my Plugin.

Link to comment

I have tried to attach a kingston and a sandisk USB stick to my Windows10 machine, and I get a "Device attached successfully" on both of them but windows doesnt recognize them. What drivers am I missing? I have tried telling windows to find the drivers and I have tried to tell windows to use drivers from the virtio-win-0.1.102.iso but nothing works. It just says windows is using the best drivers.

zxrDPhY.png

Link to comment
  • 3 weeks later...

There are a few issues with VMs seeing USB devices but nothing this plugin can resolve i believe

 

I have a 64GB kingston USB pendrive and an external HDD cradle

Passing them to my main VM running OVMf the devices don't appear at all

Passing them to my second VM using SeaBios and they work instantly

 

This is on the latest beta 23 however so there may be something that needs updating to make it work with OVMF but i'm not sure

 

Just pointing it out id needed, honestly glad i found this plugin!

 

Regards,

Jamie

Link to comment
  • 3 weeks later...

Anyone else receive a Code 10 "The device cannot start" error? I'm trying to connect an android phone, but even with the latest drivers installed I'm receiving this error.

 

Am I the only one with this issue?

 

New USB Pass Through Method with USB 3...Please Test

 

https://r.tapatalk.com/shareLink?url=http%3A%2F%2Flime-technology%2Ecom%2Fforum%2Findex%2Ephp%3Ftopic%3D41922&share_tid=41922&share_fid=18593&share_type=t

 

 

 

 

 

Sent from my iPhone using Tapatalk

Link to comment
  • 4 weeks later...

I love this plug-in! Great work! I wanted to get your thoughts on listing and adding the device address with your plug-in. No matter if your using vanilla UnRAID or your plug-in, having many identical devices (for me its Logitech Unifying Receivers and USB NICs) is problematic. I know which bus they're on but their enumeration changes on removal/reboot.

 

Thanks again for creating this plug-in.

Neil

Link to comment
  • 3 months later...

it doesn't work with usb storage devices :(

 

also, can you make one that automatically attaches anything you plug in to a specified vm

 

It does work with usb storage devices from what I have tested and I don't know why it shouldn't as it just uses virsh.

 

well, I will try it with more usb storage devices, I think the problem was that (not sure but probably) the storage device was mounted in the host.

Link to comment
  • 1 month later...

bshakil hasn't been around for a while, and I'm thinking about significantly expanding this plugin (at least initially as a script with a future possibility for a plugin) to support automatically detecting changes and applying them to the specified VM.

 

But, I would need to know a couple of things to determine how things would work (and only need to know for those that DO NOT have any usb controllers passed through) just so I can compare your system's operation to my system's

 

- How many Busses are listed when you do

lsusb

- How many USB ports total does your motherboard support total according to the manual.  Note that this does not necessarily mean the number of ports you have installed.  You may have extra USB headers unused on the motherboard.

- Plug a USB device into a particular port

lsusb

pull the device and then plug it in again to the exact same port

lsusb

  Did the device number for the device change?

 

Link to comment
  • 5 months later...

after improperly disconnecting USB camera I now get this error when I try to reconnect it to VM any ideas? 

 

error: Failed to attach device from /tmp/libvirthotplugusb.xml
error: internal error: unable to execute QEMU command 'device_add': usb port 2 (bus usb.0) not found (in use?)

 

Link to comment
3 minutes ago, SylverWolf said:

after improperly disconnecting USB camera I now get this error when I try to reconnect it to VM any ideas? 

 


error: Failed to attach device from /tmp/libvirthotplugusb.xml
error: internal error: unable to execute QEMU command 'device_add': usb port 2 (bus usb.0) not found (in use?)

 

Did you try detaching the device before attaching. Sometimes when you remove the device it remains attached to the VM. So select the same device Detach it and then try to attach it again.

  • Upvote 1
Link to comment
5 hours ago, bshakil said:

Did you try detaching the device before attaching. Sometimes when you remove the device it remains attached to the VM. So select the same device Detach it and then try to attach it again.

Yes, I did, in fact it can attach and detach successfully from other VM's just not this one. Again it was working before. I also tried deleting the lib XML and uninstalling the plugin and reinstalling also rebooting the unraid server.

 

error: Failed to detach device from /tmp/libvirthotplugusb.xml
error: operation failed: host usb device vendor=0x046d product=0x082d not found

this is what i get when i hit detach

Link to comment
  • 5 months later...
On 2/4/2017 at 12:59 PM, Squid said:

bshakil hasn't been around for a while, and I'm thinking about significantly expanding this plugin (at least initially as a script with a future possibility for a plugin) to support automatically detecting changes and applying them to the specified VM.

 

But, I would need to know a couple of things to determine how things would work (and only need to know for those that DO NOT have any usb controllers passed through) just so I can compare your system's operation to my system's

 

- How many Busses are listed when you do


lsusb
 

 

- How many USB ports total does your motherboard support total according to the manual.  Note that this does not necessarily mean the number of ports you have installed.  You may have extra USB headers unused on the motherboard.

- Plug a USB device into a particular port


lsusb
 

pull the device and then plug it in again to the exact same port


lsusb
 

  Did the device number for the device change?

 

Did anything ever come of this, Squid? Just found this plugin today and while it's working for me so far, I'm curious if you ever came up with anything script or new plugin wise?

Link to comment
  • Squid locked this topic
Guest
This topic is now closed to further replies.