Auto-Assign USB port to VM

wilsodg
Know my way around
Posts: 175
Joined: Mon May 20, 2013 12:34 am

Auto-Assign USB port to VM

Post by wilsodg »

TS670 pro, with latest 4.1.1 (nov) release. Running Windows 7 in a VM. Using a USB monitor with an app in the VM Works well for 99% of the time, but I have 2 issues.
First, the VM occasionally (once a week or so) seems to go into suspend mode. Will work on that - could be windows or the NAS.
2nd issue - when I start the NAS or the VM, I have to go in and manually assign the USB device to the VM. is there a way to automate this?

Ideas welcomed please.
TVS-872XT with TR-004 and D800C
TS670Pro with UX500-P expansion
TS569Pro
wilsodg
Know my way around
Posts: 175
Joined: Mon May 20, 2013 12:34 am

Re: Auto-Assign USB port to VM

Post by wilsodg »

Bump.
Updated to the 4.1.2 build 20150126 level.
Whilst the VM has stopped going into suspend (think it was a windows power setting), I do still have the issue that the USB port is not assigned to the VM in a definition file - therefore whenever the NAS or the VM are started, I have to go in and re-attach the USB. The VirtualHere USB sharing package seemed to have the ability to pre-assign a USB port to a VM, but (from memory), it was not so stable on the windows side.

So - question.. how to pre-assign a USB port/device to a specific VM. If no simple way to achieve this, how does one ask QNAP to consider adding this function?
Many thanks.
TVS-872XT with TR-004 and D800C
TS670Pro with UX500-P expansion
TS569Pro
wilsodg
Know my way around
Posts: 175
Joined: Mon May 20, 2013 12:34 am

Re: Auto-Assign USB port to VM

Post by wilsodg »

Bump again. I have been hoping that QNAP would address the auto-assign of a USB port to a VM when VS is started. It's annoying to have to go in and do this manually. Does anyone know if there a command that can be run within VS or another way to do this?
VS is on 1.4.3901, and QTS is on 4.1.4 2015/05/02 (yes I know it is a bit behind)
TVS-872XT with TR-004 and D800C
TS670Pro with UX500-P expansion
TS569Pro
arua_chris
New here
Posts: 2
Joined: Tue Apr 21, 2015 10:02 pm

Re: Auto-Assign USB port to VM

Post by arua_chris »

I would be also interested in such a feature.
I run a kaffeine-instance in a ubuntu-box to record programs from two DVB-S-USB-Devices. Would be nice to restart this one once a day to make sure that it is working in the long run.
arua_chris
New here
Posts: 2
Joined: Tue Apr 21, 2015 10:02 pm

Re: Auto-Assign USB port to VM

Post by arua_chris »

may be I should have checked it first. Surprisingly it is working.
- Model: TS-453 Pro
- Firmware: 4.2.0 Build 20160130
- Virtualization Station: V2.0.3924
- HD Station: 1.0.0
maybe this helps someone...
christian1302
New here
Posts: 4
Joined: Thu Aug 18, 2016 4:59 am

Re: Auto-Assign USB port to VM

Post by christian1302 »

With mit QNAP TS251+ (Virtualization Station 2.2 Beta) no auto assign of usb is working.
When the device is switched off & on (or awakes from hibernate) the device is listed as externaö device in the qnap web desktop.
I have manually go to virtualization station an reassign the device.
cporeaux
New here
Posts: 7
Joined: Tue Apr 29, 2014 3:24 pm

Re: Auto-Assign USB port to VM

Post by cporeaux »

Hello,
Same need here (TVS-871), need like you to manually set it up.
Other point : making a cold snapshot remove USB (prompted) but doesn't connect it after snaphost ;-(

about 2 years since first post, maybe someone will read us a day ;-)
NAS #1 (main): TVS-871, RAID5 (4*14Tb WD141KRYZ + 1*5120b SSD Read Cache Samsung 860 Pro) + 1 LAN PCI-E RJ45 10Gb. Latest QTS
NAS #2 : TS-419P+, RAID5 (4*2Tb WD2003FYYS) + 2 LAN (r+r) + eSATA HDD 2Tb for clod Backup. Latest QTS for this branch
MassiXV
New here
Posts: 2
Joined: Tue Apr 19, 2016 7:24 pm

Re: Auto-Assign USB port to VM

Post by MassiXV »

Guys, I've opened a ticket and talked with the support requesting if the auto-assignment will ever be implemented and they say they're evaluating the thing! He say they doesn't have an estimated arrival time but definitively they're working on it!

So if you want to see the feature implemented in a reasonable time please submit a ticket (https://helpdesk.qnap.com/index.php?/Tickets/Submit)!
My ticket is yet closed but hopefully with your help we can see this feature live as fast as possible!

Bye guys, and submit!
MassiXV
New here
Posts: 2
Joined: Tue Apr 19, 2016 7:24 pm

Re: Auto-Assign USB port to VM

Post by MassiXV »

OK, guys this is the guide:

REQUISITES: KNOWING OF SSH, VI, TERMINAL, ENGLISH OR AT LEAST KNOWING HOW TO SEARCH ON GOOGLE

OK, let's go!

1.SSH into the NAS and create a dummy package:

Code: Select all

vi /etc/config/qpkg.conf
Then add at the end of the file:

Code: Select all

[autorun]
Name = autorun
Version = 0.1
Author = Massi-X
Date = 2016-12-12
Shell = /share/MD0_DATA/.qpkg/autorun/autorun.sh
Install_Path = /share/MD0_DATA/.qpkg/autorun
QPKG_File = autorun.qpkg
Enable = TRUE
Create the folder for the package:

Code: Select all

mkdir /share/MD0_DATA/.qpkg/autorun
2.Create the autorun file:

Code: Select all

vi /share/MD0_DATA/.qpkg/autorun/autorun.sh
And put into this:

Code: Select all

#!/bin/sh

# Find where script is located
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# First start and resume windows machine
virsh start Windows
virsh resume Windows

# Wait 10 sec
sleep 10

# Then mount USB 1
virsh attach-device Windows $DIR/Mount_USB_1.xml

# Start windows another time, to be sure
virsh start Windows
Now save and set it executable:

Code: Select all

chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
3.Create the USB info file:

Code: Select all

vi /share/MD0_DATA/.qpkg/autorun/Mount_USB_1.xml

Code: Select all

<hostdev mode='subsystem' type='usb'>
	<source startupPolicy='optional'>
		<vendor id='0x00c3'/>
		<product id='0x0001'/>
	</source>
	<!-- OPTIONAL
    	<address type='usb' bus='0' port='5'/>
    	-->
</hostdev>
You can find vendor and product ID by issuing lsusb in the terminal.
The address set the port of the guest OS the USB will be connected (WARNING: if the port is in use, the USB will not be connected, remove the comment to using it).

Now save it and exit.

4. DONE!

WARNING: "Windows" is the name of the guest OS, you have to set it accordingly
WARNING: You can repeat the steps 2 ("# Then mount USB 1" and set executable) and 3 to add as many USB devices as you want.

Sources:
viewtopic.php?f=318&t=90425
https://translate.google.it/translate?h ... &sandbox=1
https://access.redhat.com/documentation ... uests.html
https://libvirt.org/formatdomain.html
viewtopic.php?f=16&t=42301
https://wiki.edubuntu.org/VirtFeatureVerification



UPDATE:
After my NAS semi-failed :evil:, I found that sometimes the package run too early, so this is the replacement for point 2 file (with logs too!):

Code: Select all

#!/bin/sh

/sbin/write_log "[WINDOWS AUTOSTART] Starting up Windows Machine" 4

# Find where script is located
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Wait until virsh is available

OUTPUT="$(virsh)"

while [[ $OUTPUT == *"command not found"* ]]
do

/sbin/write_log "[WINDOWS AUTOSTART] Virsh command not found, waiting" 4

OUTPUT="$(virsh)"

sleep 10

done

# First start and resume windows machine

virsh start Windows
virsh resume Windows

# Wait 10 sec

sleep 10

# Then mount USB 1
virsh attach-device Windows $DIR/Mount_USB_1.xml

# Start windows another time, to be sure

virsh start Windows

/sbin/write_log "[WINDOWS AUTOSTART] Autostart of Windows Machine Completed" 4
sj44k
Starting out
Posts: 19
Joined: Tue Mar 30, 2010 12:32 am

Re: Auto-Assign USB port to VM

Post by sj44k »

@MassiXV
I have the same (stupid) issue too, can you do an update about your ticket with support / share the ticket number so I can refer to your ticket when I contact support ?

Just created a ticked ( TFF-174-87798 ) and referred to this topic.
QNAP TS-451, Version 5.0.0.1891, 4x 2TB Raid 5
QNAP TS-410, Version 4.2.6, 3x 2TB 1x 6TB JBOD
Conceptronic CH3SNAS, Running ALT-F Releases / 0.1RC4.1, 2x 1TB
Northpower25
First post
Posts: 1
Joined: Sun Dec 02, 2018 10:32 pm

Re: Auto-Assign USB port to VM

Post by Northpower25 »

I have the same issue with an Ubuntu VM and an Aeotec USB Stick for Z-Wave home automation. Inside the Ubuntu VW run a Home Assistant Instance that need the Aeotec USB Stick to controll the Z-wave Network. If i take a automatic Snapshot or Backup the stick was lost in the Ubuntu environment and in the Home Assistent Instance until i reboot the Ubuntu VM.
lacalo
New here
Posts: 2
Joined: Tue Oct 15, 2013 5:30 pm

Re: Auto-Assign USB port to VM

Post by lacalo »

I have a virtual machine with Debian 9 on which runs the domotics of Jeedom and that uses two USB devices, one for the zwave network and another RFXCOM for 433 Mhz.
Each time Debian or Virtualization Station is restarted, the network becomes inactive because the USB devices are not reconnected to the virtual machine. It is incredible that Qnap maintains this situation as if it were not their thing. Synology has solved it, but it seems incredible to me that I have to change my installation of NAS for this small matter, which without a doubt produces a great frustration.
I have opened an incident in the support center several months ago, but it seems that they have their resources destined to various nonsense, instead of paying attention to the requests of their users, as justified as this one.
jrdee
Starting out
Posts: 11
Joined: Thu Apr 21, 2016 9:59 pm

Re: Auto-Assign USB port to VM

Post by jrdee »

After having realised this exact same problem (z-wave USB stick) I went on a search and of course come across this thread. I implemented what is noted above but no matter what I tried something always failed, for one reason or another.

I got something working whereby the virsh command would correctly mount the USB in my Win10 environment but found that when the QNAP restarted (I have it scheduled for a once per week restart, and it would also be a problem with power fail) then my Win10 environment wouldn't restart afterwards.

If I mount the USB using VS3 GUI then it would be ok (ie. Windows would resume ok after a QNAP restart) but using virsh command, Windows would fail to resume after a QNAP restart. I also found that if shutdown Windows 10 properly, the environment would start up fine after QNAP restart, even after using the virsh command. What I ascertained was when QNAP restarts it put the environment into "suspend" mode rather than a Windows shutdown.

Then I read the following in the VS3 Settings - Others section:
Note:
- Online VMs will be suspended before the NAS shuts down or reboots. However, a VM that uses SATA controllers will be shut down by sending an ACPI signal.
So, I first tried to change my Storage Interface from VirtIO to SATA but Windows wouldn't start (blue screen). Then I added a new Device (HDD) with Interface of SATA and size of 1GB. Upon starting my environment I noticed that Windows was using SATA mode even for the boot HDD. From this point, everything changed.

IT WORKS!!!!! I found that having selected the USB device through VS3 Connect USB Device section now sticks. It sticks through reboots, shutdowns, everything I've thrown at it.... no virsh command or autorun needed. It seems that everywhere recommends VirtIO interface for speed (hence the way I configured my environment), but this impedes on the USB pass through. Using SATA means USB auto-assigns in VM.

Hope this helps others.
michalspl2000
Starting out
Posts: 28
Joined: Tue Sep 22, 2015 5:35 pm

Re: Auto-Assign USB port to VM

Post by michalspl2000 »

Hi, mby a bit different problem but "same topic"

Is any way to set Auto-Assign USB port to VM during working on VM. What I mean ... I have GPU pass-throw and use VM like normal PC but when I connect any USB (usb stick, usb sound card, usb keyboard etc.) I need to enter to NAS-> VirtualizationStation -> Click on VM on which I working -> and then attached USB ofc it start working ok but still need make a lot of steps to "copy 1 file on usb stick"

So for me the best idea will be some script which will attached all new connected USB to one specify VM any suggestion ?
newegg
Starting out
Posts: 24
Joined: Mon Feb 10, 2014 10:11 am

Re: Auto-Assign USB port to VM

Post by newegg »

michalspl2000 wrote: Thu Oct 17, 2019 4:48 pm Hi, mby a bit different problem but "same topic"

Is any way to set Auto-Assign USB port to VM during working on VM. What I mean ... I have GPU pass-throw and use VM like normal PC but when I connect any USB (usb stick, usb sound card, usb keyboard etc.) I need to enter to NAS-> VirtualizationStation -> Click on VM on which I working -> and then attached USB ofc it start working ok but still need make a lot of steps to "copy 1 file on usb stick"

So for me the best idea will be some script which will attached all new connected USB to one specify VM any suggestion ?
Hi there,
Since new version release, there is a new feature to fit your requirement and I'm happy to use it this month.
Image
https://www.qnap.com/en/app_releasenote ... hoose=QKVM
Virtualization Station 3.2.696
( 2019/07/09 )
[New Features]
Added vQTS support for the following models: TDS-16489U/TDS-16489U R2, TS-2888X
Added pass-through support for QNAP SAS-12G2E expansion cards.
Added pass-through support for QNAP USB-U31A2P01 expansion cards. This support is unavailable for attached USB HID devices such as keyboards or mice.
Locked

Return to “Virtualization Station”