2019-01-05 04:30:04 -05:00
---
2021-03-13 13:06:18 -05:00
lang: en
2019-01-05 04:30:04 -05:00
layout: doc
2021-06-17 07:23:57 -04:00
permalink: /doc/how-to-use-usb-devices/
2019-01-05 04:30:04 -05:00
redirect_from:
2021-06-17 07:23:57 -04:00
- /doc/usb-devices/
2019-03-29 20:12:44 -04:00
- /doc/usb/
2021-03-13 13:06:18 -05:00
ref: 195
2021-07-08 21:06:41 -04:00
title: How to use usb devices
2019-01-05 04:30:04 -05:00
---
2021-06-17 10:01:53 -04:00
*This page is part of [device handling in qubes ](/doc/how-to-use-devices/ ).*
2019-03-14 18:39:20 -04:00
2021-06-17 10:01:53 -04:00
If you are looking to handle USB *storage* devices (thumbdrives or USB-drives), please have a look at the [block device ](/doc/how-to-use-block-storage-devices/ ) page.
2019-03-14 18:39:20 -04:00
2021-04-10 18:09:05 -04:00
**Note:** Attaching USB devices to VMs requires a [USB qube ](/doc/usb-qubes/ ).
2020-05-23 11:56:50 -04:00
2019-08-18 13:47:08 -04:00
**Important security warning:** USB passthrough comes with many security implications.
2021-04-10 18:09:05 -04:00
Please make sure you carefully read and understand the ** [security considerations ](/doc/device-handling-security/#usb-security )**.
2021-06-17 10:01:53 -04:00
Whenever possible, attach a [block device ](/doc/how-to-use-block-storage-devices/ ) instead.
2019-03-29 20:12:44 -04:00
Examples of valid cases for USB-passthrough:
2019-03-04 15:43:13 -05:00
2021-04-10 18:09:05 -04:00
- [microcontroller programming ](https://www.arduino.cc/en/Main/Howto )
- [external audio devices ](/doc/external-audio/ )
- [optical drives ](/doc/recording-optical-discs/ ) for recording
2019-03-04 17:06:28 -05:00
2021-04-10 18:09:05 -04:00
(If you are thinking to use a two-factor-authentication device, [there is an app for that ](/doc/u2f-proxy/ ).
But it has some [issues ](https://github.com/QubesOS/qubes-issues/issues/4661 ).)
2019-03-04 17:06:28 -05:00
2021-03-13 12:03:23 -05:00
## Attaching And Detaching a USB Device
2019-03-29 20:12:44 -04:00
2021-03-13 12:03:23 -05:00
### With Qubes Device Manager
2019-03-29 20:12:44 -04:00
2021-06-18 08:46:02 -04:00
Click the device-manager-icon: ![device manager icon ](/attachment/doc/media-removable.png )
2019-08-18 13:47:08 -04:00
A list of available devices appears.
2021-06-18 08:46:02 -04:00
USB-devices have a USB-icon to their right: ![usb icon ](/attachment/doc/generic-usb.png )
2019-03-04 17:06:28 -05:00
Hover on one device to display a list of VMs you may attach it to.
2019-08-18 13:47:08 -04:00
Click one of those.
The USB device will be attached to it.
You're done.
2019-03-04 17:06:28 -05:00
After you finished using the USB-device, you can detach it the same way by clicking on the Devices Widget.
You will see an entry in bold for your device such as ** `sys-usb:2-5 - 058f_USB_2.0_Camera` **.
Hover on the attached device to display a list of running VMs.
2021-06-18 08:46:02 -04:00
The one to which your device is connected will have an eject button ![eject icon ](/attachment/doc/media-eject.png ) next to it.
2019-03-04 17:06:28 -05:00
Click that and your device will be detached.
2021-03-13 12:03:23 -05:00
### With The Command Line Tool
2019-03-29 20:12:44 -04:00
2019-03-04 17:06:28 -05:00
In dom0, you can use `qvm-usb` from the commandline to attach and detach devices.
2019-03-04 15:43:13 -05:00
2019-03-04 17:06:28 -05:00
Listing available USB devices:
2019-03-04 15:43:13 -05:00
2021-03-13 12:03:23 -05:00
```shell_session
[user@dom0 ~]$ qvm-usb
BACKEND:DEVID DESCRIPTION USED BY
sys-usb:2-4 04ca:300d 04ca_300d
sys-usb:2-5 058f:3822 058f_USB_2.0_Camera
sys-usb:2-1 03f0:0641 PixArt_HP_X1200_USB_Optical_Mouse
```
2019-03-04 15:43:13 -05:00
2019-03-04 17:06:28 -05:00
Attaching selected USB device:
2019-03-04 15:43:13 -05:00
2021-03-13 12:03:23 -05:00
```shell_session
[user@dom0 ~]$ qvm-usb attach work sys-usb:2-5
[user@dom0 ~]$ qvm-usb
BACKEND:DEVID DESCRIPTION USED BY
sys-usb:2-4 04ca:300d 04ca_300d
sys-usb:2-5 058f:3822 058f_USB_2.0_Camera work
sys-usb:2-1 03f0:0641 PixArt_Optical_Mouse
```
2019-03-04 15:43:13 -05:00
2019-03-04 17:06:28 -05:00
Now, you can use your USB device (camera in this case) in the `work` qube.
2021-04-10 18:09:05 -04:00
If you see the error `ERROR: qubes-usb-proxy not installed in the VM` instead, please refer to the [Installation Section ](#installation-of-qubes-usb-proxy ).
2019-03-04 15:43:13 -05:00
2019-03-04 17:06:28 -05:00
When you finish, detach the device.
2019-03-04 15:43:13 -05:00
2021-03-13 12:03:23 -05:00
```shell_session
[user@dom0 ~]$ qvm-usb detach work sys-usb:2-5
[user@dom0 ~]$ qvm-usb
BACKEND:DEVID DESCRIPTION USED BY
sys-usb:2-4 04ca:300d 04ca_300d
sys-usb:2-5 058f:3822 058f_USB_2.0_Camera
sys-usb:2-1 03f0:0641 PixArt_Optical_Mouse
```
2019-03-29 20:12:44 -04:00
2021-03-13 12:03:23 -05:00
## Maintenance And Customisation
2019-03-29 20:12:44 -04:00
2021-03-13 12:03:23 -05:00
### Creating And Using a USB qube
2019-03-29 20:12:44 -04:00
2019-08-18 13:47:08 -04:00
If you've selected to install a usb-qube during system installation, everything is already set up for you in `sys-usb` .
2021-04-10 18:09:05 -04:00
If you've later decided to create a usb-qube, please follow [this guide ](/doc/usb-qubes/ ).
2019-01-05 04:30:04 -05:00
2021-03-13 12:03:23 -05:00
### Installation Of `qubes-usb-proxy`
2019-03-29 20:12:44 -04:00
2020-03-02 10:20:36 -05:00
To use this feature, the `qubes-usb-proxy` package needs to be installed in the templates used for the USB qube and qubes you want to connect USB devices to.
2019-08-18 13:47:08 -04:00
This section exists for reference or in case something broke and you need to reinstall `qubes-usb-proxy` .
Under normal conditions, `qubes-usb-proxy` should already be installed and good to go.
2019-01-05 04:30:04 -05:00
If you receive this error: `ERROR: qubes-usb-proxy not installed in the VM` , you can install the `qubes-usb-proxy` with the package manager in the VM you want to attach the USB device to.
- Fedora: `sudo dnf install qubes-usb-proxy`
- Debian/Ubuntu: `sudo apt-get install qubes-usb-proxy`
2021-03-13 12:03:23 -05:00
### Using USB Keyboards And Other Input Devices
2019-03-29 20:12:44 -04:00
2021-04-10 18:09:05 -04:00
**Warning:** especially keyboards need to be accepted by default when using them to login! Please make sure you carefully read and understood the ** [security considerations ](/doc/device-handling-security/#usb-security )** before continuing!
2019-01-05 04:30:04 -05:00
2021-04-10 18:09:05 -04:00
Mouse and keyboard setup are part of [setting up a USB-qube ](/doc/usb-qubes/#enable-a-usb-keyboard-for-login ).
2019-01-05 04:30:04 -05:00
2021-03-13 12:03:23 -05:00
### Finding The Right USB Controller
2019-01-05 04:30:04 -05:00
Some USB devices are not compatible with the USB pass-through method Qubes employs.
In situations like these, you can try to pass through the entire USB controller to a qube as PCI device.
However, with this approach one cannot attach single USB devices but has to attach the whole USB controller with whatever USB devices are connected to it.
If you have multiple USB controllers, you must first figure out which PCI device is the right controller.
First, find out which USB bus the device is connected to (note that these steps need to be run from a terminal inside your USB qube):
2021-03-13 12:03:23 -05:00
```
lsusb
```
2019-01-05 04:30:04 -05:00
2021-03-13 12:03:23 -05:00
For example, I want to attach a broadband modem to the NetVM.
2019-01-05 04:30:04 -05:00
In the output of `lsusb` it may be listed as something like:
2021-03-13 12:03:23 -05:00
```
Bus 003 Device 003: ID 413c:818d Dell Computer Corp.
```
2019-01-05 04:30:04 -05:00
(In this case, the device isn't fully identified)
2021-03-13 12:03:23 -05:00
The device is connected to USB bus \#3.
2019-01-05 04:30:04 -05:00
Check which other devices are connected to the same bus, since *all* of them will be attach to the same VM.
To find the right controller, follow the usb bus:
2021-03-13 12:03:23 -05:00
```
readlink /sys/bus/usb/devices/usb3
```
2019-01-05 04:30:04 -05:00
This should output something like:
2021-03-13 12:03:23 -05:00
```
../../../devices/pci-0/pci0000:00/0000:00:1a.0/usb3
```
2019-01-05 04:30:04 -05:00
2021-06-17 09:54:52 -04:00
Now you see the path and the text between `/pci0000:00/0000:` and `/usb3` i.e. `00:1a.0` is the BDF address. Strip the address and pass it to the [`qvm-pci` tool ](/doc/how-to-use-pci-devices/ ) to attach the controller to the targetVM.
2019-01-05 04:30:04 -05:00
2020-05-18 14:24:37 -04:00
For example, On R 4.0 the command would look something like
2019-01-05 04:30:04 -05:00
2020-05-22 08:33:12 -04:00
`qvm-pci attach --persistent personal dom0:00_1a.0`