You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
= Configuring a virtual machine connection to a USB device
7
+
= Connecting a USB device to a virtual machine
8
8
9
-
You can configure virtual machine (VM) access to a USB device. This configuration allows a guest to connect to actual USB hardware that is attached to an {product-title} node, as if the hardware and the VM are physically connected.
9
+
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.
10
10
11
11
.Prerequisites
12
12
13
13
* You have installed the {oc-first}.
14
+
* You have attached the required USB device as a resource at the cluster level.
14
15
15
16
.Procedure
16
17
17
-
. Locate the USB device by running the following command:
18
+
. In the `HyperConverged` custom resource (CR), find the assigned resource name of the USB device:
18
19
+
19
20
[source,terminal]
20
21
----
21
-
$ oc /dev/serial/by-id/usb-VENDOR_device_name
22
+
$ oc get hyperconverged kubevirt-hyperconverged -n openshift-cnv
23
+
----
24
+
+
25
+
*Example output*
26
+
+
27
+
[source, yaml]
28
+
----
29
+
# ...
30
+
spec:
31
+
permittedHostDevices:
32
+
usbHostDevices:
33
+
- resourceName: kubevirt.io/peripherals
34
+
selectors:
35
+
- vendor: "045e"
36
+
product: "07a5"
37
+
- vendor: "062a"
38
+
product: "4102"
39
+
- vendor: "072f"
40
+
product: "b100"
22
41
----
23
42
24
-
. Open the virtual machine instance custom resource (CR) by running the following command:
43
+
. Open the VM instance CR:
25
44
+
26
45
[source,terminal]
27
46
----
28
-
$ oc edit vmi vmi-usb
47
+
$ oc edit vmi <vmi_usb>
29
48
----
49
+
+
50
+
where:
51
+
52
+
<vmi_usb>:: Specifies the name of the `VirtualMachineInstance` CR.
53
+
30
54
31
-
. Edit the CR by adding a USB device, as shown in the following example:
55
+
. Edit the CR by adding the USB device, as shown in the following example:
56
+
+
57
+
*Example configuration*
32
58
+
33
-
.Example configuration
34
59
[source, yaml]
35
60
----
36
61
apiVersion: kubevirt.io/v1
37
62
kind: VirtualMachineInstance
38
63
metadata:
39
64
labels:
40
65
special: vmi-usb
41
-
name: vmi-usb <1>
66
+
name: vmi-usb
42
67
spec:
43
68
domain:
44
69
devices:
45
70
hostDevices:
46
71
- deviceName: kubevirt.io/peripherals
47
-
name: local-peripherals
72
+
name: local-peripherals <1>
48
73
# ...
49
74
----
50
75
<1> The name of the USB device.
76
+
77
+
. Apply the modifications to the VM configurations:
78
+
+
79
+
[source,terminal]
80
+
----
81
+
$ oc apply -f <filename>.yaml
82
+
----
83
+
+
84
+
where:
85
+
86
+
<filename>:: Specifies the name of the `VirtualMachineInstance` manifest YAML file.
You can enable USB host passthrough at the cluster level.
9
+
To attach a USB device to a virtual machine (VM), you must first enable USB host passthrough at the cluster level.
10
10
11
-
You specify a resource name and USB device name for each device you want first to add and then assign to a virtual machine (VM). You can allocate more than one device, each of which is known as a `selector` in the HyperConverged (HCO) custom resource (CR), to a single resource name. If you have multiple, identical USB devices on the cluster, you can choose to allocate a VM to a specific device.
11
+
To do this, specify a resource name and USB device name for each device you want first to add and then assign to a VM. You can allocate more than one device, each of which is known as a `selector` in the `HyperConverged`custom resource (CR), to a single resource name. If you have multiple identical USB devices on the cluster, you can choose to allocate a VM to a specific device.
12
12
13
13
.Prerequisites
14
14
@@ -17,24 +17,92 @@ You specify a resource name and USB device name for each device you want first t
17
17
18
18
.Procedure
19
19
20
-
. Identify the USB device vendor and product by running the following command:
20
+
. Ensure that the `HostDevices` feature gate is enabled:
21
+
+
22
+
[source,terminal]
23
+
----
24
+
$ oc get featuregate cluster -o yaml
25
+
----
26
+
+
27
+
*Successful output*
28
+
+
29
+
[source,yaml]
30
+
----
31
+
featureGates:
32
+
# ...
33
+
enabled:
34
+
- name: HostDevices
35
+
----
36
+
37
+
. Identify the USB device vendor and product:
21
38
+
22
39
[source,terminal]
23
40
----
24
41
$ lsusb
25
42
----
43
+
+
44
+
*Example output*
45
+
+
46
+
[source,terminal]
47
+
----
48
+
Bus 003 Device 007: ID 1b1c:0a60 example_manufacturer example_product_name
49
+
----
50
+
51
+
** If you cannot use the `lsusb` command, inspect the USB device configurations in the host's `/sys/bus/usb/devices/` directory:
52
+
+
53
+
[source,terminal]
54
+
----
55
+
for dev in *; do
56
+
if [[ -f "$dev/idVendor" && -f "$dev/idProduct" ]]; then
. Open the HCO CR by running the following command:
79
+
. Add the required USB device to the `permittedHostDevices` stanza of the `HyperConvered` CR. The following example adds a device with vendor ID `045e` and product ID `07a5`:
. Add a USB device to the `permittedHostDevices` stanza, as shown in the following example:
95
+
.Verification
35
96
97
+
* Ensure that the HCO CR contains the required USB devices:
98
+
+
99
+
[source,terminal]
100
+
----
101
+
$ oc get hyperconverged kubevirt-hyperconverged -n openshift-cnv
102
+
----
103
+
+
104
+
*Example output*
36
105
+
37
-
.Example YAML snippet
38
106
[source,yaml,subs="attributes+"]
39
107
----
40
108
apiVersion: hco.kubevirt.io/v1beta1
@@ -43,7 +111,6 @@ metadata:
43
111
name: kubevirt-hyperconverged
44
112
namespace: {CNVNamespace}
45
113
spec:
46
-
configuration:
47
114
permittedHostDevices: <1>
48
115
usbHostDevices: <2>
49
116
- resourceName: kubevirt.io/peripherals <3>
@@ -58,4 +125,4 @@ spec:
58
125
----
59
126
<1> Lists the host devices that have permission to be used in the cluster.
60
127
<2> Lists the available USB devices.
61
-
<3> Uses `resourceName: deviceName` for each device you want to add and assign to the VM. In this example, the resource is bound to three devices, each of which is identified by `vendor` and `product` and is known as a `selector`.
128
+
<3> Uses `resourceName: deviceName` for each device you want to add and assign to the VM. In this example, the resource is bound to three devices, each of which is identified by `vendor` and `product` and is known as a `selector`.
As a cluster administrator, you can expose USB devices in a cluster, making them available for virtual machine (VM) owners to assign to VMs. Enabling this passthrough of USB devices allows a guest to connect to actual USB hardware that is attached to an {product-title} node, as if the hardware and the VM are physically connected.
9
+
As a cluster administrator, you can expose USB devices in a cluster, which makes the devices available for virtual machine (VM) owners to assign to VMs. Enabling this passthrough of USB devices allows a VM to connect to USB hardware that is attached to an {product-title} node, as if the hardware and the VM are physically connected.
10
10
11
-
You can expose a USB device by first enabling host passthrough and then configuring the VM to use the USB device.
11
+
To expose a USB device, first enable host passthrough and then configure the VM to use the USB device.
0 commit comments