iPhone, iTunes, & Linux

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:

jjones@dads-pc:~$ hal-device | grep Apple -A 36 | grep info.udi
info.udi = '/org/freedesktop/Hal/devices/usb_device_5ac_1294_bcc2f6da7f53acb1b65d03d87c7bf1ac0748faeb' (string)
info.udi = '/org/freedesktop/Hal/devices/net_00_50_56_c0_00_08' (string)

Next, create a file like /etc/hal/fdi/policy/10-noiphone.fdi (“noiphone” is arbitrary…you can name it whatever you like) with the following:

<?xml version="1.0" encoding="UTF-8"?>

<deviceinfo version="0.2">
    <match key="info.udi" string="$info.udi1">
       <merge key="info.ignore" type="bool">true</merge>

    <match key="info.udi" string="$info.udi2">
       <merge key="info.ignore" type="bool">true</merge>

  • where $info.udi1 = first info.udi value from hal-device search
  • where $info.udi2 = second info.udi value from hal-device search

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:


export XAUTHORITY=/home/jjones/.Xauthority
export DISPLAY=:0.0
su jjones -c "/usr/bin/VBoxManage startvm 376e6b19-1602-4e73-bc7e-7248c49be9a3" >> /var/log/iphone.log


export XAUTHORITY=/home/jjones/.Xauthority
export DISPLAY=:0.0
su jjones -c "/usr/bin/VBoxManage controlvm 376e6b19-1602-4e73-bc7e-7248c49be9a3 acpipowerbutton" >> /var/log/iphone.log

Set the executable bit on these scripts:
jjones@dads-pc:~$ sudo chmod +x /usr/local/bin/iphone_*

With the iPhone unplugged, run the following command:

jjones@dads-pc:~$ sudo udevadm monitor --environment

Plug in the iPhone and take note of the output of udevadm. We’re looking for line similar to:


Lastly, create the file:

SUBSYSTEM=="usb", ENV{PRODUCT}=="5ac/1294/1", ACTION=="add", RUN+="/usr/local/bin/iphone_attach.sh"
SUBSYSTEM=="usb", ENV{PRODUCT}=="5ac/1294/1", ACTION=="remove", RUN+="/usr/local/bin/iphone_remove.sh"

Again, substitute the appropriate values for your own stuff.

Now when you plug in your iPhone, your VirtualBox XP machine should load automatically and autorun iTunes when booted up. When you remove the iPhone, XP detects an ACPI shutdown and closes. Enjoy!

About jjones

Guy who works in tech to pay the mortgage and raise a family that loves God.
This entry was posted in Me, Technology and tagged , , . Bookmark the permalink.

One Response to iPhone, iTunes, & Linux

  1. gap says:

    Thanks a ton… this has plagued me all summer, and was interrupting my iPhone updates b/c Ubuntu kept “capturing” the device after a reboot.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>