Adding a USB device

AndyL

Member
Jul 28, 2011
61
0
6
I have had success in adding a USB device to a KVM virtual machine by adding it to the conf file and restarting the vm.
An example line in the conf file is:

usb0: host=1058:1042

This works OK.
If I wish to add another device, I presume that I would add another line so:
usb1: host=XXXX:XXXX
Is this correct?

There is also the occasional need to be able to add USB devices "on the fly" - just as if you had plugged them into a physical machine, and use them without rebooting.

In the vm monitor, I have tried:

usb_add host:XXXX:YYYY

where XXXX is the vendor id, and YYYY is the product id, both obtained from the 'info usbhost' command (or lsusb from a console window).

I have also tried

usb_add host:2.9

where 2 is the bus, and 9 is the address.

I have had no success with either if these methods. I have tried three separate USB devices, all to no avail.

Has anyone managed to get the hotplugging of USB devices to work? If so, what's the trick!

pveversion output:

pve-manager: 3.0-23 (pve-manager/3.0/957f0862)
running kernel: 2.6.32-22-pve
proxmox-ve-2.6.32: 3.0-107
pve-kernel-2.6.32-20-pve: 2.6.32-100
pve-kernel-2.6.32-22-pve: 2.6.32-107
lvm2: 2.02.95-pve3
clvm: 2.02.95-pve3
corosync-pve: 1.4.5-1
openais-pve: 1.1.4-3
libqb0: 0.11.1-2
redhat-cluster-pve: 3.2.0-2
resource-agents-pve: 3.9.2-4
fence-agents-pve: 4.0.0-1
pve-cluster: 3.0-4
qemu-server: 3.0-20
pve-firmware: 1.0-23
libpve-common-perl: 3.0-4
libpve-access-control: 3.0-4
libpve-storage-perl: 3.0-8
vncterm: 1.1-4
vzctl: 4.0-1pve3
vzprocps: 2.0.11-2
vzquota: 3.1-2
pve-qemu-kvm: 1.4-13
ksm-control-daemon: 1.1-1
 
A quick addendum: It seems that Windows XP is Ok, but Windows 7 does not see any usb devices.

usb_add does not work on either XP or 7, but an addition to the conf file and restarting the VM does work on Windows XP, but not on Windows 7.
 
A quick addendum: It seems that Windows XP is Ok, but Windows 7 does not see any usb devices.

usb_add does not work on either XP or 7, but an addition to the conf file and restarting the VM does work on Windows XP, but not on Windows 7.

And yet another - Win 7 did not work with a USB bluetooth mouse adapter, but it did work with a USB hard disc. Windows XP did work with the USB mouse adapter.

I still can't hotplug things though :-(
 
Right - even more stuff!

Hotplugging does work with Windows 7 and XP - if you get the command right!
The command at the monitor is:
device_add usb-host,vendorid=0x1234,productid=0x1234

it's the 0x that makes all the difference - credit to user giner for this one at http://forum.proxmox.com/threads/8862-USB-Pass-through-bug.
You don't need the 0x notation in the conf file, however.

But ... you can hotplug a USB keyboard, I also tried a USB wireless mouse dongle. They both worked fine. However if USB mass storage devices are added, Windows pops up a warning telling you that the device you have added will work better on a USB2 hub. This may be true, but hotplugging seems to add a device to the USB1.1 hub that is installed by default. The device shows up in device manager, but has an exclamation mark next to it and does not function. If you add the device through the conf file, the it appears that a new USB2 hub is added to the vm, and the device added to that.
So it appears that hotplugging a USB disk is not possible - which is a shame, because that's what I would like to do.

As to the device_del syntax - it's a complete mystery to me. There appears to be a dearth of up to date documentation concerning these commands. There's a lot that is out of date, but that is really no use. Does anyone know a definitive location for documentation on all the monitor commands, and more importantly, with examples that is current?
 
Right - even more stuff!

Hotplugging does work with Windows 7 and XP - if you get the command right!
The command at the monitor is:
device_add usb-host,vendorid=0x1234,productid=0x1234

it's the 0x that makes all the difference - credit to user giner for this one athttp://forum.proxmox.com/threads/8862-USB-Pass-through-bug.
You don't need the 0x notation in the conf file, however.

But ... you can hotplug a USB keyboard, I also tried a USB wireless mouse dongle. They both worked fine. However if USB mass storage devices are added, Windows pops up a warning telling you that the device you have added will work better on a USB2 hub. This may be true, but hotplugging seems to add a device to the USB1.1 hub that is installed by default. The device shows up in device manager, but has an exclamation mark next to it and does not function. If you add the device through the conf file, the it appears that a new USB2 hub is added to the vm, and the device added to that.
So it appears that hotplugging a USB disk is not possible - which is a shame, because that's what I would like to do.

As to the device_del syntax - it's a complete mystery to me. There appears to be a dearth of up to date documentation concerning these commands. There's a lot that is out of date, but that is really no use. Does anyone know a definitive location for documentation on all the monitor commands, and more importantly, with examples that is current?

I seem to be talking to myself here ... anyway - you can hotplug a USB mass storage device with Windows XP. It does not work with Windows 7. At least untile I reply to myself again .. :)
 
One last thing before I go home.

In Device Manager in XP, under Universal Serial Bus controllers there is an Intel 82371SB PCI to USB Universal Host controller, one Standard Enhanced PCI to USB Host Controller, three Standard Universal PCI to USB Host controllers and then five USB Root Hub's.

On Windows 7, there is only one Intel 82371SB PCI to USB Universal Host controller, and one USB Root Hub.

As far as is possible, the definition of the two virtual machines is the same. I even changed the OS Type in the Options tab to Windows XP to see if it would make any difference to the Windows 7 machine. It didn't.

There's an interesting bit here: https://bugzilla.redhat.com/show_bug.cgi?id=789621

As far as I can see, the default USB device in Proxmox is USB1.1 I think. Could it be changed to 2.0?

So it seems that Win7 and XP detect the same emulated hardware in different ways. I'm not sure if this is the place here for my observations, but hopefully it will be of some use to someone.
 
No, we add a ehci controller if you use a 'usb[n]' configuration (with usb1 on top).

OK - so it looks like the problem is somewhere in qemu. What did you mean by a 'usb[n]' configuration? i don't see where you can do this from the web interface?
 
OK - so it looks like the problem is somewhere in qemu. What did you mean by a 'usb[n]' configuration? i don't see where you can do this from the web interface?

This is command line only for now, see

# man qm
# man vm.conf
 
A bit more reading shows that there is a way to add a USB disc to a Windows 7 virtual machine on the command line, without editing the conf file and rebooting.

You need to plug in your USB drive and see how it is referred to - syslog will tell you. In this example it was sdf.

At the monitor command, type

drive_add 0 id=myid,if=none,file=/dev/sdf
device_add usb-storage,id=myid,drive=myid

and Windows 7 should see a new USB disc. To remove the disc, eject it in Windows as usual, and then the command is

device_del myid

Which will remove it.

I did discover that you can add the same disc to more than one virtual machine at the same time. It seems that the first machine gets to write to it (or it may be that the first vm that writes is the winner) and the second machine can see the contents, but is not notified if the contents change. Also the second machine appears to be writing to the drive, but it doesn't actually get written. I'm not suggesting that this is a good idea - far from it - just pointing it out that there is nothing to stop you doing it! I guess it might be useful if you have a read only dongle ....

Hopefully one day this will make it into the GUI!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!