I got the new iPhone 3Gs a couple weeks ago, and apparently like many other Linux users, wrestled with the best way to sync/backup my phone since iTunes only runs on Mac and Windows. I settled on running XP in a VirtualBox machine and running iTunes from there. Although many people are doing this successfully, I thought I’d share a couple hints to save some time for anyone looking to do the same.

First off, this is for Ubuntu 9.04…ymmv on other flavors and versions of Ubuntu.

If you have the open source edition (OSE) of VirtualBox installed, you’ll need to remove it and install the proprietary version. This is necessary for the USB pass-through. I’m using VirtualBox 2.2.24. If you’re using Ubuntu, you can do this through the Synaptic Package Manager or through the command:

jjones@dads-pc:~$ sudo apt-get install virtualbox-2.2

Install XP on the virtual machine. Update your service packs, etc and install iTunes. I disabled some services from automatically starting to keep the boot-up relatively quick. I also used VirtualBox’s shared folders feature to keep all my music in Linux and share it with the VM. I just mapped a network drive in XP and imported that folder into my iTunes library. Next, make sure you have USB enabled. Go to Settings->USB.

You’ll also want to setup a USB filter to have the iPhone passed through to the virtual machine. With the iPhone plugged in, click the button to add a new filter and choose the iPhone.

Once you get this up and running, you’ll find that plugging your iPhone in will cause Ubuntu to mount it as a camera. XP may or may not see it too. But iTunes won’t see it until until you unmount the iPhone camera in Ubuntu. It would be good at this point to make sure that’s the case. I came across a great post on the Ubuntu forums that gave a slick way to supress the automounting of the iPhone as a camera without turning off automounting of removal media altogether. It involves creating a HAL policy to ignore when the iPhone is detected. the HAL daemon actually sees two devices when the phone is plugged in. We need to grab the IDs of both. You can do this by grepping through the output of the command:

jjones@dads-pc:~$ sudo hal-device

We’ll use the values for each ‘info.udi’. Here’s a little snippet that should grab what we need:

I needed to reboot to see this take effect. But afterwards, you should be able to plug in your iPhone without it being mounted in Ubuntu as a camera. If you have USB enabled and a filter set up, XP and iTunes should have no trouble detecting the phone.

If you’re like me and intend to use the XP virtual machine for iTunes only, here’s a way to have your virtual XP loaded automatically when the iPhone is attached and unloaded when removed. Here’s how:

Get the id of the virtual machine running XP:
jjones@dads-pc:~$ VBoxManage list vms

Create the following two scripts substituting my vm id and other info with your own: