|Line 1:||Line 1:|
= USB redirection over the network
= USB redirection over the network
== Summary ==
== Summary ==
Revision as of 12:01, 9 September 2011
USB redirection over the network
Allow redirecting a USB device to another machine over the network. For example use an USB webcam attached to machine A on machine B. For Fedora 16 the focus will be on allowing using USB devices attached to some machine (not necessarily the host machine) inside a qemu-kvm virtual machine.
- Name: Hans de Goede
- Email: firstname.lastname@example.org
- Targeted release: Fedora 16
- Last updated: Sep 9, 2011
- Percentage of completion: 100%
The intend is to deliver the following for Fedora 16:
- A usbredir package (done) with libraries for:
- parsing the usbnetredir protocol
- redirecting a local attached usb-device through an application provided pipe
- Support for qemu to receive data from a usbredir pipe, and make the redirected USB device show up as being attached to the emulated host controller inside the virtual machine (done)
- Support for spice-server (done) and spice-gtk (the gtk spice client widget) to use usbredir
- A nice UI for redirecting USB devices from a spice-gtk based virtual machine viewer (done, but only in spicy so far not in virt-manager / virt-viewer)
Benefit to Fedora
Currently many Fedora users choose to not use qemu-kvm for virtual machines, but instead use a less open alternative not shipped with Fedora. One of the stated reasons for doing so is the less then stellar support for USB redirection with qemu-kvm. Besides adding support for USB redirection over the network, qemu's USB redirection support is being improved in general, including adding support for USB 2.
The needed changes are isolated to the new usbredir package, qemu and spice. Work is already underway to try and get all changes upstream.
How To Test
First thing you need to do is download this file, and drop it in /etc/qemu.
Then create a new spice-enabled vm using using virt-manager, select spice as display type and qxl as video card model, when asked if you want to enable the agent channel, say yes.
When done, close virt-manager and edit the relevant /etc/libvirt/qemu/foo.xml file. Change the first line from:
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
And add the following lines at the end, above the "
<qemu:commandline> <qemu:arg value='-readconfig'/> <qemu:arg value='/etc/qemu/ich9-ehci-uhci.cfg'/> <qemu:arg value='-chardev'/> <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev1'/> <qemu:arg value='-device'/> <qemu:arg value='usb-redir,chardev=usbredirchardev1,id=usbredirdev1,bus=ehci.0,debug=3'/> <qemu:arg value='-chardev'/> <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev2'/> <qemu:arg value='-device'/> <qemu:arg value='usb-redir,chardev=usbredirchardev2,id=usbredirdev2,bus=ehci.0,debug=3'/> <qemu:arg value='-chardev'/> <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev3'/> <qemu:arg value='-device'/> <qemu:arg value='usb-redir,chardev=usbredirchardev3,id=usbredirdev3,bus=ehci.0,debug=3'/> </qemu:commandline>
Then close down any virtual machines you may have open, and restart libvirt:
sudo service libvirtd restart
Now start the vm with virt-manager, open it, select the details view, click on Display Spice and lookup and remember the port mentioned there (this will be 5900 if it is the only running vm).
Close virt-manager, and connect to the vm with spicy, like this:
sudo spicy -h localhost -p 5900
Where 5900 should be replaced by the port the vm is actually running on. Note that you need to start spicy as root, so that it can access the device nodes under
Select the options menu entry and make sure that the "auto redirect newly plugged in USB devices" option is checked. After this make sure the vm has keyboard focus (so close the options menu), plug in a new USB device and watch it show up in your vm :) Feel free to yank it out again at any time :)
If you plug in a device while the vm does not have keyboard focus, it will not get redirected, so you can use usb devices normally as long as you don't have the vm focussed when you plug them in.
Enjoy, and be sure to send any feedback you may have my way!
Users wishing to redirect USB devices to virtual machines can do so easily from the virtual machine viewer UI, and can do so even when connected to the virtual machine from another machine then the host.
The plan is to deliver the various bits mentioned under "Detailed Description" one by one. If time runs out before we can deliver the lower bullets, the already delivered bits will stay in place and can still be used, but only from the cmdline rather then from a nice integrated UI experience.
Fedora 16 now comes with improved USB support for qemu-kvm virtual machines. The virtual machines are now capable of emulating or passing through USB 2 devices. It is now also possible to redirect a USB device over the network, this allows passing through a USB device from another pc then the host to a virtual machine. See: http://fedoraproject.org/wiki/Features/UsbNetworkRedirection for detailed instructions on how to enable these new features.