USB Device (Auto attach to Qube)

Hello,

Is there a way to attach a particular USB device (by Vendor ID/Product ID) to a Qube automatically on connect? I have a sys-usb to manage USB devices.

The USB device I am using frequently becomes disconnected (and reconnected) during use and it only needs to be connected to one particular Qube.

Thanks,
N

Is there a way to attach a particular USB device (by Vendor ID/Product ID) to a Qube automatically on connect? I have a sys-usb to manage USB devices.

I don’t know of an easy solution to this.

Using the qvm-usb tool you can attach a connected device to another VM persistently, but the device id is unreliable and may change if you reconnect devices in a different order.

Since sys-usb cannot escape virtualization and connect a device to another VM, what you could do is write udev rules in sys-usb to trigger an RPC call to dom0 which would attach the device to another VM (after a confirmation popup, if you want).

The USB device I am using frequently becomes disconnected (and reconnected) during use and it only needs to be connected to one particular Qube.

You might try enabling no-strict-reset on your USB controller attached to sys-usb

This weekend was a long weekend and I had some time to try out the idea that I had mentioned in in a comment above. The whole process was relatively straightforward and there were very few surprises :slightly_smiling_face:

Here is a blog post I wrote documenting my experience: USB auto-attach in Qubes » Saswat Padhi

Comments / suggestion are most welcome.

Cheers.

Very nice write up padhi.

Thank you,
N

1 Like

I recently did the same sort of thing as padhi, except my goal was for a prompt to open up in dom0 asking which qube a USB device should be attached to upon being plugged in. Unfortunately, when Qubes wakes up from standby, the sys-usb qube acts as if all USB devices were re-plugged in. I couldn’t figure out a way to differentiate that event versus the device actually being plugged in, so I ended up getting rid of it.

Here’s some details, if it helps anyone.

I was using the stdin/stdout way of communicating, with the following udev rule for not just block devices :

ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb", RUN+="/usr/lib/qubes/qrexec-client-vm dom0 custom.AskAboutAttachingUsbDevice /home/user/send-usb-device.sh $devpath"

Contents of /home/user/send-usb-device.sh:

#!/bin/bash
# used by /etc/udev/rules.d/90-qubes-usb-device-plugged-in.rules
echo $1 | rev | cut -d'/' -f 1 | rev

Script that eventually gets executed on dom0 (needs some hardening if using stdin/stdout):

#!/bin/bash

read usb_device

qubes=$(qvm-ls --raw-data --fields=NAME,CLASS | egrep "AppVM|DispVM|StandaloneVM" | egrep -v "sys|mgmt|dvm" | cut -f 1 -d "|" | sort);

qube=$(zenity --display=:0.0 --list --radiolist --text="Select a Qube to attach the USB device ${usb_device} to:" --column="Selection" $qubes --column="Qube" $qubes --width=250 --height=350)

if [ -n "$qube" ]; then
        qvm-device usb attach $qube sys-usb:$usb_device
fi
1 Like