?

Log in

No account? Create an account
 
 
09 September 2011 @ 01:20 pm
USB redirection integrated into SPICE now available in Fedora-16  
I'm happy to announce the availability of USB redirection support in SPICE in Fedora 16. Unfortunately the virtmanager bits are not there yet. So if you want to try this you need to configure it manually. This howto assumes
a fully up2date F-16 with spice-gtk from updates-testing installed.

First create a virtual machine as usual, 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 and add the following lines at the end, above the "</devices>" line:

    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x2'/>
    </controller>
    <redirdev bus='usb' type='spicevmc'>  
      <address type='usb' bus='0' port='3'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='4'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='5'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='6'/>
    </redirdev>

Note that the slot='0x08' needs to be one higher then the higest pci slot already in use, so if you've more
pci devices in your config then me you may need to make this higher.

Then close down any virtual machines you may have open, and restart libvirt:
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:
spicy -h localhost -p 5900

Where 5900 should be replaced by the port the vm is actually running on.

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), and plug in a new USB device. You will now
get a PolicyKit dialog asking you for your root password, this is needed since redirecting USB devices requires access the device nodes under /dev/bus/usb. Once you've (correctly) typed your root password,  watch the USB device 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.

If you want to redirect already plugged in devices, or un-redirect redirected devices without unplugging them go to the
Input menu and click "Select USB Devices for redirection".

Enjoy, and be sure to send any feedback you may have my way!


Note (Feb 1 2012): this blog post has been updated to:
  • Use the new usbredir support in libvirt, rather then to directly inject qemu cmdline from the libvirt xml file using the qemu:commandline syntax.
  • Reflect the use of PolicyKit rather then needing to run the client as root
  • The new USB device selection widget
Tags: , ,