[Plugin] USB_Manager


SimonF

Recommended Posts

7 minutes ago, ifndef said:

For some reasons, I need to use ssh to control the unraid server from time to time, so I want to control the usb_manager in the terminal with some commands. My application just passes the usb devices on the unraid to the virtual machine. It seems that the final control interface is in rc.usb_manager, but I can't find a useful command description. I hope you can help me

Can you provide an overview of what you need to do. rc.usb_manager is to process calls from QEMU hooks and UDEV so not really a command line interface, but maybe could be used.

Link to comment
On 2/5/2023 at 12:35 AM, SimonF said:

Can you provide an overview of what you need to do. rc.usb_manager is to process calls from QEMU hooks and UDEV so not really a command line interface, but maybe could be used.

At least two commands (list USB devices and Do VM attach)need to be listed. It would be better if you could allow editing device settings to bind VM

Link to comment
2 hours ago, ifndef said:

At least two commands (list USB devices and Do VM attach)need to be listed. It would be better if you could allow editing device settings to bind VM

does lsusb not give you the list of USB devices you need?

 

root@computenode:~# lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge, ASM1153 SATA 3Gb/s bridge, ASM1153E SATA 6Gb/s bridge
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 013: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 012: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 057: ID 1cf1:0030 Dresden Elektronik ZigBee gateway [ConBee II]
Bus 001 Device 007: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Bus 001 Device 005: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 002: ID 1462:7d25 Micro Star International MYSTIC LIGHT 
Bus 001 Device 010: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 009: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 008: ID 2516:01b5 Cooler Master Co., Ltd. Intel ARC RGB Controller
Bus 001 Device 006: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 004: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@computenode:~# 

 

To connect a device to a VM you can create a XML and run virsh attached-device "VMName" "XMLFilename" XML format and command are below.

 

	<hostdev mode='subsystem' type='usb'>
	<source>
	<address bus='${usbbustrim}' device='${usbdevtrim}' />
	</source>
	</hostdev>

root@computenode:~# virsh help attach-device
  NAME
    attach-device - attach device from an XML file

  SYNOPSIS
    attach-device <domain> <file> [--persistent] [--config] [--live] [--current]

  DESCRIPTION
    Attach device from an XML <file>.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--file] <string>  XML file
    --persistent     make live change persistent
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain


root@computenode:~# 

 

 

Edited by SimonF
Link to comment
1 hour ago, SimonF said:

LSUSB没有给你你需要的USB设备列表吗?

 

root@computenode:~# lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 174c:55aa ASMedia Technology Inc. ASM1051E SATA 6Gb/s bridge, ASM1053E SATA 6Gb/s bridge, ASM1153 SATA 3Gb/s bridge, ASM1153E SATA 6Gb/s bridge
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 013: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 012: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 057: ID 1cf1:0030 Dresden Elektronik ZigBee gateway [ConBee II]
Bus 001 Device 007: ID 2109:2817 VIA Labs, Inc. USB2.0 Hub             
Bus 001 Device 005: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 003: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 002: ID 1462:7d25 Micro Star International MYSTIC LIGHT 
Bus 001 Device 010: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 009: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 008: ID 2516:01b5 Cooler Master Co., Ltd. Intel ARC RGB Controller
Bus 001 Device 006: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 004: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@computenode:~# 

 

要将设备连接到VM,您可以创建一个XML并运行virsh连接的设备“VMName”“XMLFilename”XML格式和命令如下。

 

	<hostdev mode='subsystem' type='usb'>
	<source>
	<address bus='${usbbustrim}' device='${usbdevtrim}' />
	</source>
	</hostdev>

root@computenode:~# virsh help attach-device
  NAME
    attach-device - attach device from an XML file

  SYNOPSIS
    attach-device <domain> <file> [--persistent] [--config] [--live] [--current]

  DESCRIPTION
    Attach device from an XML <file>.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--file] <string>  XML file
    --persistent     make live change persistent
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain


root@computenode:~# 

 

 

Thank you very much. I got all what I needed

root@unraid:~# lsusb | grep SEGGER
Bus 001 Device 004: ID 1366:0105 SEGGER J-Link
root@unraid:~# nano jlink.xml
root@unraid:~# cat jlink.xml
<hostdev mode='subsystem' type='usb'>
        <source>
                <vendor id='0x1366'/>
                <product id='0x0105'/>
        </source>
</hostdev>
root@unraid:~# virsh list
 Id   Name      State
-------------------------
 2    Lubuntu   running

root@unraid:~# virsh attach-device Lubuntu jlink.xml
Device attached successfully

root@unraid:~# ssh [email protected]
ifndef@Lubuntu:~$ lsusb | grep SEGGER
Bus 001 Device 005: ID 1366:0105 SEGGER J-Link
ifndef@Lubuntu:~$

 

Link to comment

I have recently changed server and started to notice issues with auto-connecting USB devices to VM.

I pass 3 devices to one of my VMs - Zigbee controller (passed as serial device), Zwave controller (passed as device) and bluetooth. They are all configured to auto connect to my VM, but that is not happening. If I reboot, at least 2 show that they are not attached and I have to click the button to attach it. 

How can I figure out why is this happening?

Link to comment
1 hour ago, stefan.tomko said:

I have recently changed server and started to notice issues with auto-connecting USB devices to VM.

I pass 3 devices to one of my VMs - Zigbee controller (passed as serial device), Zwave controller (passed as device) and bluetooth. They are all configured to auto connect to my VM, but that is not happening. If I reboot, at least 2 show that they are not attached and I have to click the button to attach it. 

How can I figure out why is this happening?

Which OS version are you running?

 

and can you provide output of cat /var/log/syslog | grep usb_manager

Link to comment

It is home assistant OS (VM), unraid 6.11.5

 

Quote

Feb 11 13:24:28 Tower root: plugin: installing: usb_manager.plg
Feb 11 13:24:28 Tower root: plugin: checking: /boot/config/plugins/usb_manager/packages/usb_manager-2022.08.20.txz - MD5
Feb 11 13:24:28 Tower root: plugin: skipping: /boot/config/plugins/usb_manager/packages/usb_manager-2022.08.20.txz already exists
Feb 11 13:24:28 Tower root: plugin: running: /boot/config/plugins/usb_manager/packages/usb_manager-2022.08.20.txz
Feb 11 13:24:28 Tower root: | Installing new package /boot/config/plugins/usb_manager/packages/usb_manager-2022.08.20.txz
Feb 11 13:24:28 Tower root: Verifying package usb_manager-2022.08.20.txz.
Feb 11 13:24:28 Tower root: Installing package usb_manager-2022.08.20.txz:
Feb 11 13:24:28 Tower root: Package usb_manager-2022.08.20.txz installed.
Feb 11 13:24:28 Tower root: | Skipping package usb_manager-2022.08.20 (already installed)
Feb 11 13:24:28 Tower root: plugin: creating: /tmp/start_usb_manager - from INLINE content
Feb 11 13:24:28 Tower root: plugin: setting: /tmp/start_usb_manager - mode to 0770
Feb 11 13:24:28 Tower root: plugin: skipping: /boot/config/plugins/usb_manager/usb_manager.cfg already exists
Feb 11 13:24:28 Tower root: plugin: skipping: /boot/config/plugins/usb_manager/remote_usbip.cfg already exists
Feb 11 13:24:28 Tower root: plugin: skipping: /boot/config/plugins/usb_manager/vm_mappings.cfg already exists
Feb 11 13:24:29 Tower root:  usb_manager has been installed.
Feb 11 13:24:30 Tower root: plugin: usb_manager.plg installed
Feb 11 13:24:30 Tower root: plugin: usb_manager.plg installed
Feb 11 13:24:33 Tower usb_manager: Info: rc.usb_manager Building Connected Status
Feb 11 13:24:55 Tower usb_manager: Info: rc.usb_manager Reset Connected Status
Feb 11 13:25:23 Tower usb_manager: Starting usbip config check...
Feb 11 13:25:53 Tower usb_manager: Info: rc.usb_manager usb_remove  dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/bus/usb/001/006 001 006
Feb 11 13:25:53 Tower usb_manager: Info: rc.usb_manager Device Match 001/006 vm:   001 006
Feb 11 13:25:53 Tower usb_manager: Info: rc.usb_manager Removed 001/006 vm:  nostate 001 006
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager usb_add dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/bus/usb/001/010 001 010
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager Add device with more than one interface & connect serial yes  .
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager unable to connect device as Serial device details unknown for dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313.
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager tty_add dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/ttyACM1
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager Processing tty attach dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/ttyACM1 001 010
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager Add device with more than one interface & connect serial yes 1 1.
Feb 11 13:25:54 Tower usb_manager: Info: rc.usb_manager Autoconnect vm state:running dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 running 001 010
Feb 11 13:25:54 Tower usb_manager: Info: connect as serial guest port is:04
Feb 11 13:25:54 Tower usb_manager: Info: virsh called Home Assistant 001 010 Device attached successfully
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager usb_remove  dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/bus/usb/001/010 001 010
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Device Match 001/010 vm: Home Assistant  001 010
Feb 11 13:25:58 Tower usb_manager: Info: connect as serial guest port is:04
Feb 11 13:25:58 Tower usb_manager: Info: virsh called Home Assistant 001 010 Device detach request sent successfully
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Disconnect  001/010 vm: Home Assistant running 001 010
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Removed 001/010 vm: Home Assistant running 001 010
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager usb_add dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/bus/usb/001/011 001 011
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Add device with more than one interface & connect serial yes  .
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager unable to connect device as Serial device details unknown for dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313.
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager tty_add dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/ttyACM1
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Processing tty attach dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 /dev/ttyACM1 001 011
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Add device with more than one interface & connect serial yes 1 1.
Feb 11 13:25:58 Tower usb_manager: Info: rc.usb_manager Autoconnect vm state:running dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2450313 running 001 011
Feb 11 13:25:58 Tower usb_manager: Info: connect as serial guest port is:04
Feb 11 13:25:58 Tower usb_manager: Info: virsh called Home Assistant 001 011 Device attached successfully
Feb 11 13:26:40 Tower usb_manager: Info: virsh called Home Assistant 001 005 Device attached successfully
Feb 11 13:26:42 Tower usb_manager: Info: virsh called Home Assistant 001 004 Device attached successfully

 

Edited by stefan.tomko
Link to comment

I changed server equipment. However on first boot, I would understand that mappings may change, so on first boot ever after changing motherboard, RAM, etc, I adjusted mappings.

But now, every time I reboot server (whether it is planned or unplanned) reboot, it just boots and devices do not get attached. As a result, VM starts without it and Zigbee does not start because of missing adapter, Zwave is started but reporting missing adapter. Ocasionally, bluetooth fails as well until I attach them all. I had 3 reboots since the change, and all have the same symptoms.

Link to comment
2 minutes ago, stefan.tomko said:

I changed server equipment. However on first boot, I would understand that mappings may change, so on first boot ever after changing motherboard, RAM, etc, I adjusted mappings.

But now, every time I reboot server (whether it is planned or unplanned) reboot, it just boots and devices do not get attached. As a result, VM starts without it and Zigbee does not start because of missing adapter, Zwave is started but reporting missing adapter. Ocasionally, bluetooth fails as well until I attach them all. I had 3 reboots since the change, and all have the same symptoms.

Have you tried uninstalling and reinstalling. Config should remain.

Link to comment

Thanks @SimonF - I have uninstalled and installed plugin again. File above is created and I restarted to test it out - it works very well.

I do remember now that few days after switching to new server, my libvirt image was corrupted and I had to delete it and create from scratch. Maybe that contributed to it. Anyway, would this be an opportunity for improvement in any way? 

  • Like 1
Link to comment
28 minutes ago, stefan.tomko said:

Thanks @SimonF - I have uninstalled and installed plugin again. File above is created and I restarted to test it out - it works very well.

I do remember now that few days after switching to new server, my libvirt image was corrupted and I had to delete it and create from scratch. Maybe that contributed to it. Anyway, would this be an opportunity for improvement in any way? 

Its should create each install will have a look to see why it is not working.

Link to comment

Well, I did not uninstall it nor installed it. It has been the same server running from the same USB drive. If it gets created only with plugin install, it would be normal to not re-create it. 

But I was thinking - if it can't be recreated when plugin has something to auto-attach and it cannot do so, at least be notified that this is missing. I realize not many would have this issue like I did... but just in case. 

Link to comment
10 hours ago, stefan.tomko said:

Well, I did not uninstall it nor installed it. It has been the same server running from the same USB drive. If it gets created only with plugin install, it would be normal to not re-create it. 

But I was thinking - if it can't be recreated when plugin has something to auto-attach and it cannot do so, at least be notified that this is missing. I realize not many would have this issue like I did... but just in case. 

Plugins do a re-install at each boot. But found the issue, /etc/libvirt will not be mounted at boot time so will not create qemu.d and at the hooks file. Will look to add the processing when VM manager is started.

  • Like 1
Link to comment
  • 1 month later...

I just updated some of my USB Coordinator sticks for my Home Assistant VM running on unraid.  I needed to install this plugin (which is amazing) because all three of my new coordinators were being identified as the same hardware which was causing issues with the Standard USB Pasthrough and as a result my Home Assistant would not start and displayed an execution error.  After fumbling a bit I got this set up using Port mappings and it worked well.  However it seemed if I rebooted the VM, not all the USB devices reconnected properly.  I was able to reconnect them from the USB Manager GUI but I would prefer not to have to remember to do this everytime I reboot?  

 

So I updated my setting and mapped these coordinators as Devices which also worked.  Have not rebooted and will not unless I have some issues or need updates.  I was though curious if others had similar experiences and which version (port or device) you are using to map to Home Assistant?  

 

Lastly, with my coordinators mapped as devices versus ports, if I unplug a coordinator and move it to a different USB Port will it still be recognized and connect properly?  I kinda assumed if I used the port method and connected to a different port when re-plugging the cordinator it might not be recognized.  Thanks!

Link to comment
2 hours ago, Shesakillatwo said:

I was able to reconnect them from the USB Manager GUI but I would prefer not to have to remember to do this everytime I reboot?  

Did you set them to auto connect in the mappings at VM start? 

 

Sliders at the top.

 

image.thumb.png.936c1df5c65d310b8b1401c832a027d9.png

 

2 hours ago, Shesakillatwo said:

Lastly, with my coordinators mapped as devices versus ports, if I unplug a coordinator and move it to a different USB Port will it still be recognized and connect properly?  I kinda assumed if I used the port method and connected to a different port when re-plugging the cordinator it might not be recognized.  Thanks!

If you set mapping as device it will map no matter where the device is connected as long as there is a unique serial.

 

Port will map that specific port to the VM no matter which device is connected to it. Useful if duplicate USB and duplicate serials or no serial.

Link to comment

Thanks so much for the quick reply.  I am glad to hear that if using the device mapping it does not matter what port my coordinators are plugged into.  That puts that concern to rest!  On the question of "Did you set them to auto connect in the mappings at VM start", I am pretty sure I did but when tinkering at the time I was first setting this up maybe I made a mistake?  I will see how it goes for now and let you know if I see any additional issues.  Probably user error.....

 

BTW, this is an Awesome Plugin.  Before I found it I was really struggling with how I was gonna make this work for my three Home Assistant coordinators so this was a gold find for me.  Thanks!

  • Thanks 1
Link to comment
29 minutes ago, Trylo said:

Hi!

I'm getting this message:

image.png.398b830f5c76989e921bf2645eb1658b.png

"Following are missing or not loaded: USBIP Commands usbip_host module vhci_hcd module."

I thought maybe I just need to reboot Unraid, but that didn't help.

How can I fix this?

Do you need USBIP if not set enable USBIP to no in settings. If yes install the addon package via the settings page.

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.