Jump to content
bshakil

[Plug-In] Hotplug USB for Virtual Machines

70 posts in this topic Last Reply

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

Share this post


Link to post

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.

 

 

 

 

Share this post


Link to post

Hi bshakil

 

Thanks for the quick reply, that is not an issue as I can pass through the individual devices - I just saw mention of hubs and took a guess

 

Regards,

Jamie

 

P. S.  Great plugin!

Share this post


Link to post

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!

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Brilliant and to the point. You rock.  :)

 

I will test it. If its as simple as the article says. I think i can finally bring the requested functionality.

 

 

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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?

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

it doesn't work with usb storage devices :(

 

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

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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?

 

Share this post


Link to post

Is there any compatibility problems with this plugin and unraid 6.3?

Share this post


Link to post

Is there any compatibility problems with this plugin and unraid 6.3?

I tried it while I was making a hotplug script today and it works fine.

Share this post


Link to post

Squid,

 

I use this plugin for my Windows 10 VM and find it real useful.  A hot plug version would be very welcome.  Let me know if you need my help.

Share this post


Link to post

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?)

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now