// Module included in the following assemblies:
//
// * virt/virtual_machines/advanced_vm_management/virt-configuring-usb-host-passthrough.adoc

:_mod-docs-content-type: PROCEDURE
[id="virt-configuring-vm-use-usb-device_{context}"]
= Connecting a USB device to a virtual machine

[role="_abstract"]
You can configure virtual machine (VM) access to a USB device. This configuration enables the VM to connect to USB hardware that is attached to an {product-title} node, as if the hardware and the VM are physically connected.

.Prerequisites

* You have installed the {oc-first}.
* You have attached the required USB device as a resource at the cluster level.

.Procedure

. In the `HyperConverged` custom resource (CR), find the assigned resource name of the USB device:
+
[source,terminal,subs="attributes+"]
----
$ oc get {HCOCliKind} kubevirt-hyperconverged -n {CNVNamespace}
----
+
Example output:
+
[source, yaml]
----
# ...
  spec:
    permittedHostDevices:
      usbHostDevices:
        - resourceName: kubevirt.io/peripherals
          selectors:
            - vendor: "045e"
              product: "07a5"
            - vendor: "062a"
              product: "4102"
            - vendor: "072f"
              product: "b100"
----

. Open the VM CR:
+
[source,terminal]
----
$ oc edit vm <vm_name>
----
+
where:
+
`<vm_name>`:: Specifies the name of the `VirtualMachine` CR.

. Edit the CR by adding the USB device, as shown in the following example:
+
Example configuration:
+
[source, yaml]
----
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: example-vm
spec:
  template:
    spec:
      architecture: amd64
      domain:
        devices:
          hostDevices:
          - deviceName: kubevirt.io/peripherals
            name: local-peripherals
# ...
----
+
* `spec.template.spec.domain.devices.hostDevices.deviceName` specifies the resource name from the `HyperConverged` CR.
* `spec.template.spec.domain.devices.hostDevices.name` defines the name of the USB device.

. Save and apply your changes:
+
[source,terminal]
----
$ oc apply -f <filename>.yaml
----
+
where:
+
`<filename>`:: Specifies the name of the `VirtualMachine` manifest YAML file.
