Wednesday, February 18, 2009

Windows USB in a Linux desktop

It's been a long time since the last post. I've been able to collect a lot of material for future posts, so I hope I have time to publish all the things I've planned.

The first post of this blog dealt with running a Windows application in a virtual machine, but having the application's window as a standalone window on a Linux desktop. This is very useful to run programs that are not available for Linux, or that cannot be replaced for others with similar functionality. Turns out that there's a particular family of programs that are usually not available for Linux, and don't have replacements.

Take an iPod Touch, for example.

I bought an iPod Touch for my dad while I was in the US, but I wanted to try it before I came back to Argentina so as to make sure it was working. Well, no luck for me. Touch iPods (at least, I don't know about others) require being activated using iTunes. There's no iTunes for Linux, and I don't dual boot my laptop. What did I end up doing? I borrowed a Windows laptop from work, installed iTunes on it, and I activated the damn thing. My Tech Support friend at work didn't like having iTunes on one of the company's laptop (even for 5 minutes, I removed it once the Touch was working), but I had no choice.

Or did I?

At that time USB support in KVM wasn't as good as it is today... but to be honest, it didn't occur to me that I could do that. Yes, I know, pretty amateur on my side. I could have installed iTunes on a Windows virtual machine and activate the iPod using the virtual machine.

Which brings me to my second problem. I have a Nokia phone. I like Nokia phones, I've grown used to the way the menus are arranged and how things work. Sadly, there's no Nokia software for Linux. Of course you can connect your phone as a mass storage device, or as a modem, but what if you want to use the Nokia software to update your phone? You can't. A friend of mine had an USB printer that printed ridiculously better using Windows drivers than CUPS drivers. He's screwed.

Or not. Enter USB pass-through. KVM lets you assing USB devices directly to a virtual machine, making the VM think that the device is connected directly to it. First, you need to make sure that KVM will see the USB devices in the host. Older KVM versions were not able to use /sys so you need to mount /proc/bus/usb:

$ mount -t usbfs none /proc/bus/usb

Current KVM, KVM-84, works without any mounting. Either way, you need to start your virtual machine with the -usb switch, which enables the USB emulation in KVM. Windows virtual machines will probably install drivers the first time you start them with USB. Once the VM is loaded, if you press Ctrl-Alt-2 you will get the console. You can use the info usbhost command to list the USB devices available in the host, and the usb_add command to add them to the guest. The only thing you need to make sure is that the device is not being used by the guest. This may need unloading the kernel module that contains the driver for your USB device, using rmmod or modprobe -r. The argument for the usb_add command is the device number that's listed with the info usbhost command. For example, if we want to add a USB SD card reader (SDDR-113):


Using the info usb command you can verify that the device was successfully added to the guest. And Windows makes the final confirmation.


Unfortunately I don't have any brand-new iPod Touch to try activating it using a virtual machine, but there's no reason why it shouldn't work. My Nokia phone did =).

No comments: