In OpenVZ, you can assign a USB device to a virtual machine so that the device is automatically connected to the virtual machine when you connect the USB device to the hardware node or start the virtual machine. To assign a USB device to a virtual machine, you need to specify two parameters:
-
ID of the USB device. To get this information, use the
prlsrvctl info
command, for example:# prlsrvctl info ... Hardware info: hdd '/dev/sda' hdd-part NTFS '/dev/sda2' hdd-part Linux '/dev/sda3' hdd-part Linux '/dev/sda5' hdd-part Linux swap '/dev/sda6' cdrom Optiarc DVD RW AD-7260S '/dev/scd0' net enp0s5 'enp0s5' usb Broadcom - USB Device 3503 '2-1.4.3|0a5c|3503|full|KM|Empty' sb Broadcom - USB Device 3502 '2-1.4.2|0a5c|3502|full|KM|Empty' usb LITEON Technology - USB Multimedia Keyboard '1-1.6|046d|c312|low|KM|Empty' serial /dev/ttyS0 '/dev/ttyS0' serial /dev/ttyS1 '/dev/ttyS1'
All USB devices available on the hardware node are listed in the Hardware info section and start with usb
.
-
ID of the virtual machine. To get this information, use the
prlctl list --info
command, for example:# prlctl list --info ID: {d8d516c9-dba3-dc4b-9941-d6fad3767035} Name: Windows 7 ...
The first line in the command output indicates the virtual machine ID; in our case, it is
{d8d516c9-dba3-dc4b-9941-d6fad3767035}
.
Once you know the USB device and virtual machine IDs, you can use the prlsrvctl usb set
command to assign the USB device to the virtual machine. For example:
# prlsrvctl usb set '1-1.6|046d|c312|low|KM|Empty' {d8d516c9-dba3-dc4b-9941-\
d6fad3767035}
The server has been successfully configured.
This command assigns the USB device LITEON Technology - USB Multimedia Keyboard with ID '1-1.6|046d|c312|low|KM|Empty'
to the virtual machine with ID {d8d516c9-dba3-dc4b-9941-d6fad3767035}
. When running the command, remember to specify the single quotes and curly brackets with the USB device and virtual machine IDs, respectively.
To check that the USB device has been successfully assigned to the virtual machine, use the prlsrvctl usb list
command:
# prlsrvctl usb list
Broadcom - USB Device 3503 '2-1.4.3|0a5c|3503|full|KM|Empty'
Broadcom - USB Device 3502 '2-1.4.2|0a5c|3502|full|KM|Empty'
LITEON Technology - USB Multimedia Keyboard '1-1.6|046d|c312|low|KM|Empty' \
{d8d516c9-dba3-dc4b-9941-d6fad3767035}
The command output shows that the USB device with ID '1-1.6|046d|c312|low|KM|Empty'
is now associated with the virtual machine with ID {d8d516c9-dba3-dc4b-9941-d6fad3767035}
. This means that the device is automatically connected to the virtual machine every time you start this virtual machine and connect the device to the hardware node.
To remove the assignment of the USB device with ID '1-1.6|046d|c312|low|KM|Empty'
, use the prlsrvctl usb del
command:
# prlsrvctl usb del '1-1.6|046d|c312|low|KM|Empty'
The server has been successfully configured.
When assigning USB devices to virtual machines, keep in mind the following:
- You cannot migrate a running virtual machine having one or more USB devices assigned.
- After migrating a stopped virtual machine, all its assignments are lost.
- All USB assignments are preserved if you restoring a virtual machine to its original location and are lost otherwise.
- The USB device assignment and a virtual machine is created for the user currently logged in to the system.