With current virtualization technologies it is possible to pass through devices from the host to the guest, calld USB pass through. KVM is no exception here, it even works with a USB GSM modem.
Many of customers I work with are migrating old IT systems and existing servers over to a newer and virtualized infrastructure. That often works without any problems. However, some services do depend on extra hardware like additional PCI cards – or, as in my case, on an external USB GSM modem.
To pass through such a device to the VM guest first the vendor and the product ID must be identified on the VM host:
$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 002: ID 0557:2221 ATEN International Co., Ltd Winbond Hermon Bus 002 Device 003: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270/E870 HSDPA/HSUPA Modem
The last entry shows the mentioned GSM modem, built by Huawei. The interesting numbers are the vendor ID 12d1
and the product ID 1003
. THe VM guest is oblivious of the device right now:
$ lsusb Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd Bus 001 Device 003: ID 0409:55aa NEC Corp. Hub
Next, the device must be defined in the VM guest XML. This can be done by directly editing the XML file within virsh: $ sudo virsh edit example-server
. The command brings up an editor with the content of the XML definition file of the host. The USB device must be added in the device section:
<devices> [...] <hostdev mode='subsystem' type='usb' managed='no'> <source> <vendor id='0x12d1'/> <product id='0x1003'/> </source> </hostdev> </devices>
Please note that a leading 0x
must be added to the IDs! Save the file, reboot the VM guest, and check if the guest now shows the new device:
$ lsusb Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd Bus 001 Device 003: ID 0409:55aa NEC Corp. Hub Bus 001 Device 004: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270/E870 HSDPA/HSUPA Modem
There it is. And the syslog shows that it was properly detected and can now be used in the usual ways, it’s done.
USB Serial support registered for GSM modem (1-port) option 1-2.1:1.0: GSM modem (1-port) converter detected usb 1-2.1: GSM modem (1-port) converter now attached to ttyUSB0 option 1-2.1:1.1: GSM modem (1-port) converter detected usb 1-2.1: GSM modem (1-port) converter now attached to ttyUSB1 usbcore: registered new interface driver option option: v0.7.2:USB Driver for GSM modems