Libvirt Hot Plugin USB - USB Hot Plugin for VMs


Recommended Posts

Hi! thanks for the plugin. 

I have an issue with some disks. 

when I tried to attach them I got this error

 

error: Failed to attach device from /tmp/libvirthotplugusb.xml
error: internal error: unable to execute QEMU command 'device_add': failed to open host usb device 2:3

 

I tried different usb ports and nothing?

 

can you help me? thanks

Link to comment
  • 2 weeks later...

Is there a clever way to script plug/unplug?

 

With one GPU, I may want to close one VM and open another. I can do that by scripting it 

What would be good would be to script unplugging the USB devices from that VM before loading the next VM which would plug in the same devices.

 

I would pass through USB controllers (and do) but not much use for Windows XP (no USB3) or Windows 2000 (no USB3) when my mobo only has USB3 controllers, no PCI slots for a USB2 controller and the only PCIe USB2 controller I found is stupid expensive for what it is.

 

Scripting unplug after each VM close would be such a help. I assume its some sort of virsh detach command? @dlandon ??

 

 

Link to comment

Hello guys, I would like to know, whether this plugin can be used to assign 2 same ID devices to different VMs?

 

The thing is, that I am running 3 VMs and I have  2 same mechanical keyboards ( Kingston hyperx alloy with same HWID), which is preventing them from being assigned to more than 1 VM, as unraid only shows 1 device and won't start the second VM because of this. 

 

I am thinking that I will most likely need to pass through 1 of the USB controllers (assuming that my X79 MB has the possibility). 

 

However looking at this plugin I am thinking that it could possibly be used to assign the 2nd mechanical keyboard to the other VM. 

 

Could you please let me know, whether this is possible? 

 

Thanks in advance. 

 

 

Link to comment
  • 2 months later...

This app rocks.  Both of my USB controllers are in the same IOMMU group and I am out of PCIe slots so adding another controller would not be an option.  Not quite as good as hot swapping natively Windows, but certainly much much much better than nothing.

 

Thanks for pointing it out!

 

Best regards,

craigr

Edited by craigr
Link to comment
  • 2 months later...
  • 4 weeks later...
On 1/10/2021 at 8:09 PM, mikeyosm said:

For those that are interested, I have found an article here that describes how to set up usb hot plug.

https://www.labsrc.com/unraid-automatic-usb-hotplugging-libvirt/#comments

 

I havent tested it myself but ideally it would be nice to see an expansion of this plugin to enable auto hot plug without having to use the UNRAID GUI.

Thank you for this link! This is exactly, what I was looking for in my case with USB-Switch (like KVM-Switch without video).

Had to do some tweaking though, because the scripts were not executed from flash drive by default.

Adding "/bin/bash" before "/boot/config/script.sh" calls solved my issues.

 

Would be great, if this plug-in could be enhanced with this auto hot plugging or even incorporated directly into Unraid.

Edited by Forusim
Link to comment
  • 1 month later...

Does anyone know another plugin which can work with this plugin to automate it?

 

I need to automatically reattach a mouse to a VM. 

 

Part of my workflow is to suspend a Linux VM, then suspend the unRaid server too. Then wake up the unRaid server, then manually wakeup the Linux VM after. Problem is, USB mouse does not work after waking up the Linux VM. So Im using this - usb hotplug plugin to reattach the USB mouse.

 

It has been great so far, however, I need to automate things. Can anyone jump in and help please?

NOTE: 
1. My Unraid server is only being used to Virtualize Linux Mint and Windows 10. Part of my job and workflow to use these OSes simultaneously.
2. Im suspending the Linux VM to preserve the state and save on power bills.
3. I can't let the Unraid server running 24/7 since power outages is frequent in my town and I only have 3-minute UPS backup.

Link to comment
1 hour ago, SimonF said:

Have a look at my usbip_gui plugin I am planning to rename it to usb manager

 

I found your plugin from the plugin menu of Unraid, installed it and went to the setting page, however it went to a blank white screen. I hit browser refresh several times, but no good. So I did a reboot, unRaid did not bootup. So I powered off my system.

 

I powered it back on, but it did not switched on - WEIRD!

 

After an hour of tinkering, machine did not power on still. What a coincidence.

 

Not sure what went wrong, but another prob of mine is how to revert back the unRaid USB. So noob of me

Link to comment
  • 3 months later...
  • 3 months later...
2 hours ago, Govnah said:

Trying to use this plugin to determine my NZXT AIO cooler and can't determine how to perform the following:

 

image.thumb.png.9ce0f75b96a891888b2d287b316a3f14.png

 

Installed the plugin and attached to VM, but no idea how to obtain the information posted above, and suggestions?

 

Thanks

 

What is it you are trying to do?

Link to comment

Us the Liquidctl docker app for my AIO cooler:

 

avpnusr/liquidctl - Docker Image | Docker Hub

 

Prerequisites

 

I highly recommend to use the following plugin for UnRAID from the Community Applications:

Libvirt Hotplug USB

 

Determine your USB-serial and "bus port"

 

I use this for easy detection of the serial of the USB-device, as which the AIO-cooler will be detected. As there is no guarantee, the AIO-cooler will be mapped to the container alone, the serial explicitly addresses this device.

Also you need the "port" from the usb bus, so you can map the device to the container.

In my example this would be /sys/bus/usb/devices/3-6.3

 

image.thumb.png.846ec753f631deaaf80813af87738e95.png

 

Link to comment
1 hour ago, Govnah said:

Us the Liquidctl docker app for my AIO cooler:

 

avpnusr/liquidctl - Docker Image | Docker Hub

 

Prerequisites

 

I highly recommend to use the following plugin for UnRAID from the Community Applications:

Libvirt Hotplug USB

 

Determine your USB-serial and "bus port"

 

I use this for easy detection of the serial of the USB-device, as which the AIO-cooler will be detected. As there is no guarantee, the AIO-cooler will be mapped to the container alone, the serial explicitly addresses this device.

Also you need the "port" from the usb bus, so you can map the device to the container.

In my example this would be /sys/bus/usb/devices/3-6.3

 

image.thumb.png.846ec753f631deaaf80813af87738e95.png

 

The image is from my plugin not USB hotplug.

 

Which version of Unraid are you using, on 6.10 the usb port number is now in system devices.

 

image.thumb.png.8b310133d23a141bc72271289ab666fc.png

 

 

Link to comment

Yes, 6.10 RC1 and I will take a look. So the information provided 

 

image.png.02fdd850ad79f71c6efcb05495336196.png

 

For the Serial I assume is: iSerial                 3 00000000001A

 

Based on the output below:

root@unRAID-Prod:/dev/bus/usb/009# lsusb -D /dev/bus/usb/009/004
Device: ID 1e71:2007 NZXT NZXT USB Device
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x1e71 NZXT
  idProduct          0x2007 
  bcdDevice            2.00
  iManufacturer           1 NZXT. - Inc.
  iProduct                2 NZXT USB Device
  iSerial                 3 00000000001A
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0029
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     412
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered

 

 

 

 

 

 

 

image.png

Edited by Govnah
Link to comment
  • 1 month later...

Hi,

 

i passthrough a USB Printer to a Debian VM with this Plugin. I have checked the Box in the VM Setting to passtrhough the printer and the printer is available in the VM:

 

root@debian11-103:~# lsusb
Bus 001 Device 004: ID 03f0:132a HP, Inc HP LaserJet 200 color M251n
Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd QEMU USB Tablet
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
root@debian11-103:~# 

 

If i turn off the printer, the printer i not more available in the VM. If then i turn on the printer, the printer does not connect automatically to the VM. I must manually add the printer to the VM in the VM-Tab.

How can i passthrough automatically to the VM after turning on the Printer?

 

Thx

Chris

 

Link to comment
11 minutes ago, Shantarius said:

How can i passthrough automatically to the VM after turning on the Printer

Have a look at my usb manager plugin as can auto connect a device when detected by the system. You can specify by port or device.

 

Edited by SimonF
Link to comment
13 hours ago, SimonF said:

Have a look at my usb manager plugin as can auto connect a device when detected by the system. You can specify by port or device.

 

 

Wow this is great and exactly what i need. Now i can use a Debian VM use as a (AirPrint)Printserver. If the Printer is off, the printjob is waiting in the cups-scheduler until i have turned on the printer and the printer auto connects to the VM 🙂 Very nice!

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.