March 15, 2009

HOWTO: Use USB devices in Virtual Machine Manager with QEMU

Filed under: Blog — krkhan @ 3:09 pm

Every once a while, I need to take the backup of my Nokia N72 using PC Suite. Since the task had to be performed on Windows, I expected my virtualized machine to be able to do so. Unfortunately, Virtual Machine Manager does not provide any option in its interface which would allow me to use my USB devices in virtualized machines. Going through the documentation though, here’s the method through which I was able to solve my issue.

First of all, you should have the vendor and product ID’s of the USB device you want to use. Sounds alien? Use the command:

[user@host ~]$ lsusb

Which will show you something like:

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 003: ID 0421:04c4 Nokia Mobile Phones
Bus 003 Device 002: ID 09da:000a A4 Tech Co., Ltd Port Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

The bold numbers in the line containing “Nokia Mobile Phones” are the vendor and product IDs respectively. Once you’ve noted them down for your required device (in my case: 0x421 and 0x4c4), list the virtual machines’ configuration files:

[user@host ~]$ sudo ls /etc/libvirt/qemu

networks windoze.xml

My virtual machine was named “windoze”, so windoze.xml is the file that I need to edit:

[user@host ~]$ sudo gedit /etc/libvirt/qemu/windoze.xml

In the editor, add the highlighted hostdev lines under the devices section (replacing the vendor and product IDs with the ones noted down from lsusb output):

<hostdev mode='subsystem' type='usb'>
<vendor id='0x0421' />
<product id='0x04c4' />

Save and close the file. Restart the service:

[user@host ~]$ sudo service libvirtd restart

If everything went smoothly, the USB device should now be accessible from within the virtual machine:

Screenshot of Nokia PC Suite connected to a USB device in virtualized Windows
(Click on the thumbnail for larger version.)

Tags: , , , , , , , , , , , ,


  1. Yes this works but if the usb device is powered down and then re-powered it isn’t recognized. Is there a way to restart the usb forwarding? My printer is configured to power itself off automatically after some amount of time with no activity.

    Comment by Kelvin — April 15, 2009 @ 8:50 am

  2. Kelvin, I haven’t been able to find a way to restart USB forwarding after powering off/on the device. I guess you should file this as a bug report at Virtual Machine Manager’s bugzilla.

    Comment by krkhan — April 15, 2009 @ 1:29 pm

  3. Hi There .. fist, thanks for the short tutorial .. I could get my E66 connected to Qemu.. Just wondering though, could you upgrade you phone from Qemu? I’ve tried but keep failing.. A long the way, the usb connection got broken.

    Comment by arianto — June 8, 2009 @ 9:45 am

  4. I found out why the connection got disconnected. During the upgrade process, the phone was turned-off by nokia pc suite and booted to a ROM system and the usb id changed.

    Comment by arianto — June 8, 2009 @ 2:40 pm

  5. There is work being done in the linux kernel to allow assigning usb ports instead of devices to VMs.
    Unlike device numbers, port numbers are persistent (not across reboots but on a single session)
    so this problem should be fixed too.

    Comment by pkt — June 29, 2009 @ 5:28 pm

  6. I tried your solution to include USB support in Windows 7, but as soon as I update the virtual machine’s .xml configuration file with your lines, Virtual Machine Manager doesn’t show the VM anymore. Of course I restarted libvirtd. Also complete restart of the PC doesn’t help. Even if followed by restart of libvirtd again.
    The only way to get it working again is to remove the added lines and restart the PC.

    Any hints?

    Comment by flip — October 4, 2009 @ 7:53 pm

  7. New versions of virt-manager allow attaching USB devices without manually updating the XML file. You should try the “Add Hardware” option in machine details.

    Comment by krkhan — October 5, 2009 @ 6:49 pm

  8. I found the problem. I added as described above the vendor:product ID and that went wrong.
    All went well when I tried to add the bus:device ID.
    On the other hand, adding hardware through the Virtual Device Manager UI gives only the options
    Storage, Network, Input, Graphics, Sound. Adding a Nokia phone still needs editing the VM’s .xml file.

    Comment by flip — October 5, 2009 @ 7:25 pm

  9. the reason copying and pasting from this page doesn’t work is that the ‘x’ in the two hex numbers is actually a special “multiply by” unicode character. what you need in the xml file is just a regular “x”.

    having said all that, i still can’t get it to work for me. my VM is back appearing in the list in Virtual Machine Manager but my usb device (htc hero phone) doesn’t appear in the VM.

    Comment by whyoh — October 20, 2009 @ 12:32 am

  10. Thanks a lot whyoh for pointing it out. I guess putting the thing in blockquotes was a bad idea — as I had to fix the quotes’ conversion to unicode as well. Still, I fixed the “x” issue. As far htc hero, are you still using this manual edit method or are you using the GUI add hardware option?

    Comment by krkhan — October 20, 2009 @ 4:30 pm

  11. hi there ,do you know how to get this solved on Xen-Kernel Virtual Machine?
    my msn
    thanks a lot

    Comment by marco — March 2, 2010 @ 7:08 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.