Painless USB attach/detach

56 views
Skip to first unread message

Sean Hunter

unread,
Sep 24, 2017, 7:45:19 AM9/24/17
to Qubes Users Mail List

Hey there,

I was trying out attaching usb devices to qubes and thought this might be useful to other people. If you have a device with a complicated description (eg a Yubikey) it can be a pain to figure out what device ID it's being attached to in sys-usb so you can use qvm-usb attach to send it to an AppVM.

[sean@dom0 ~]# qvm-usb
BACKEND:DEVID     DESCRIPTION                    USED BY
fedora-25:1-1     QEMU_QEMU_USB_Tablet_42        
p:1-1             QEMU_QEMU_USB_Tablet_42        
sys-firewall:1-1  QEMU_QEMU_USB_Tablet_42        
sys-usb:1-3       Yubico_Yubikey_4_OTP+U2F+CCID  
sys-usb:1-6       0489_e076                      
vault:1-1         QEMU_QEMU_USB_Tablet_42        

Typing qvm-usb, looking down for where my Yubikey is, then looking accross for the sys-usb:1-3 next to it, then typing qvm-usb attach somevm sys-usb:1-3 will get pretty old pretty fast.

Luckily, unix is awesome. I have created a couple of small shell functions which search the output of qvm-usb on the description and attach or detach. Thus:

[sean@dom0 ~]# usb-attach somevm Yubi
[sean@dom0 ~]# qvm-usb
BACKEND:DEVID     DESCRIPTION                    USED BY
fedora-25:1-1     QEMU_QEMU_USB_Tablet_42        
p:1-1             QEMU_QEMU_USB_Tablet_42        
sys-firewall:1-1  QEMU_QEMU_USB_Tablet_42        
sys-usb:1-3       Yubico_Yubikey_4_OTP+U2F+CCID  somevm
sys-usb:1-6       0489_e076                      
vault:1-1         QEMU_QEMU_USB_Tablet_42        

...and likewise...

[sean@dom0 ~]# usb-detach somevm Yubi

If you like them you could put them (or something similar) in your ~/.bashrc in your dom0.

Here they are:

function usb-attach() {
    qvm-usb attach "${1}" $( qvm-usb | awk "/${2}/"'{print $1;exit}' )
}

function usb-detach() {
    qvm-usb detach "${1}" $( qvm-usb | awk "/${2}/"'{print $1;exit}' )
}

Cheers,

Sean

usb.txt
signature.asc

Yethal

unread,
Sep 24, 2017, 8:44:36 AM9/24/17
to qubes-users
Great job! I use Micah Lee's script adapted to fit my usb devices
https://micahflee.com/2016/12/qubes-tip-making-yubikey-openpgp-smart-cards-slightly-more-usable/

Sean Hunter

unread,
Sep 24, 2017, 9:03:45 AM9/24/17
to Yethal, qubes-users
Yeah. Grep | cut -f1 from that script is similar to the awk line I use except that I also only print the first match (if there are multiple matches) whereas that script will print all of them which I think will cause problems if you have a device attached multiple timex.

Sent from my phone. Sorry if brief.
> --
> You received this message because you are subscribed to the Google Groups "qubes-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to qubes-users...@googlegroups.com.
> To post to this group, send email to qubes...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/qubes-users/25a26bb2-70d3-43dc-823b-8ff0ddaa734f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Yethal

unread,
Sep 24, 2017, 9:26:16 AM9/24/17
to qubes-users
For that to happen I'd have to have more than one device greppable using the same keyword (or regex) right?

Sean Hunter

unread,
Sep 24, 2017, 10:29:18 AM9/24/17
to Yethal, qubes-users


> On 24 Sep 2017, at 14:26, Yethal <grzegorz....@gmail.com> wrote:
>
> W dniu niedziela, 24 września 2017 15:03:45 UTC+2 użytkownik Sean Hunter napisał:
>> Yeah. Grep | cut -f1 from that script is similar to the awk line I use except that I also only print the first match (if there are multiple matches) whereas that script will print all of them which I think will cause problems if you have a device attached multiple timex.
>>
>> Sent from my phone. Sorry if brief.
>>
>>> On 24 Sep 2017, at 13:44, Yethal <grzegorz....@gmail.com> wrote:
>>>
>>> W dniu niedziela, 24 września 2017 13:45:19 UTC+2 użytkownik Sean Hunter napisał:
>>>>
>>>> [sean@dom0 ~]# qvm-usb
>>>> BACKEND:DEVID DESCRIPTION USED BY
>>>> fedora-25:1-1 QEMU_QEMU_USB_Tablet_42
>>>> p:1-1 QEMU_QEMU_USB_Tablet_42
>>>> sys-firewall:1-1 QEMU_QEMU_USB_Tablet_42
>>>> sys-usb:1-3 Yubico_Yubikey_4_OTP+U2F+CCID
>>>> sys-usb:1-6 0489_e076
>>>> vault:1-1 QEMU_QEMU_USB_Tablet_42
>>>>
>
> For that to happen I'd have to have more than one device greppable using the same keyword (or regex) right?
>

Yes that’s the case for the touchpad on my laptop for instance as you can see above. It’s built-in but usb-attached apparently. Any case both my script and the other one are about the sane for most practical use cases I would think. No reason to switch if its working well.

Cheers,

Sean


Reply all
Reply to author
Forward
0 new messages