USB Redirection allows you to make usb devices attached to your client machine accessible to your remote KVM virtual machine via the network. This qemu/kvm feature has been in development for some time with a first working version available around middle of last year, 2011.
There are two modes of usb redirection in development; one mode which uses the spice protocol and a second which uses a tcp server. The tcp server has no dependence on spice protocol whatsoever and so allow extensions to be added to tcp remoting protocols like vnc, for example, to take advantage of this feature.
For using usb redirection over the spice protocol there's a GUI tool called spicy and for using the tcp server there are currently features added to virt-manager but I won't be looking at that in this post. For now I'll be taking a look at the procedure for usb redirection using the spice protocol.
USB redirection with the spice protocol requires two basic steps.
Below outlines these two steps
The amount of usb devices you can attach over the network to a single virtual machine is dependent on how many spice usb channels your guest was started with, the default being none. If you would like to add spice usb channels then the simplest way is to start your guest virtual machine with virt-manager and add "usb redirection" virtual hardware as shown below.
Add a separate device for each usb channel you require if you need to access to more than one usb devices simultaneously. For example if you wanted the ability to add two usb devices simultaneously you would add two "usb redirection" to your virtual machine. Your virt-manager guest details page would then look like the following snapshot.
Be aware though that changing the spice usb channels in virt-manager will require a reboot of your guest virtual machine to take effect so think about this to minimize downtime due to reboots.
There's a GUI tool called spicy which , as the name suggests, is a spice client for remoting to your virtual machine. On fedora, installing this client requires the spice-gtk-tools package which you can easily install using the following yum command
yum install spice-gtk-tools
Once installed you can run the following command to connect to your KVM virtual machine where 188.8.131.52 is the ip address of your kvm linux virtual server and 5901 is the spice server port for your guest.
spicy -h 184.108.40.206 -p 5901 -w password
You also could just run the command spicy with no arguments which will give you a GUI where you can then enter host, port and password for connecting to your spice enabled KVM guest. Personally I just specify everything on the command line as this saves me time.
Once connected to your guest virtual machine, select the following menu on the spicy gui client. Input -> Select USB Devices for redirection.
This will bring up the following dialog showing usb devices available for tunneling to your guest virtual machine.
Once you've selected your usb device for redirection the dialog will tell you if you have any more usb channels available.
Your guest virtual machine will now show the usb device attached. If you're doing this across a WAN, say from home to your office, then be patient as it can take a while before all the data on your usb device is available to your guest virtual machine. It all depends on available network bandwidth between your client machine and your guest virtual machine.
To disconnect your usb device in your guest, disconnect as you normally would and use the same dialog in spicy under Input -> Select USB Devices for redirection to uncheck your usb devices from redirection.
USB redirection is a nice feature of KVM with many possible use cases. Two that immediately come to mind include backing data from your virtual machine locally or attaching usb devices that provide additional functionality to your guest virtual machine. All this without having physical access to your KVM virtual server.
The big downside to the method explained in this post is having to use multiple management tools to use this feature. In this case it required using virt-manager to configure and start/stop your virtual machine and a separate tool called spicy to perform the usb redirection to your guest.
If you're aware of other tools that provide this functionality or more interesting use cases I'm interested in hearing so please post a comment.