Mounting the iPhone on PCLinuxOS

By Archie Arevalo (Archie)

Not too long ago for many iPhone users, Linux had been a bad mix. However, leaps and bounds in progress to the project, libimobiledevice, has given us Linux users breakthroughs, rather than workarounds, and brought iPhone users, such as myself, much closer to a Linux-only solution. Until early this year, the only way I could sync my music and photo library to my iPhone was via a VirtualBox guest XP and iTunes. I also have an iPod Classic 160 GiB Black, and I have no problem with it on Linux. The XP virtual machine, along with iTunes, has been deleted from my computer, thus making my laptop 100% PCLinuxOS.

I discovered that in using Amarok, my iPhone gets mounted. And with a little bit of investigation, I am able to browse the partial directory structure of the iOS. I was able to create a symlink to the mount point in an accessible location. Thereafter, I could use GTKPod to add/remove music and picture files. Amarok would have been an acceptable solution, except that sometimes the album covers were not saved on the iPhone.

If you already have Amarok installed, that's good. Many of the dependencies needed should already be installed. But if you haven't installed GTKPod, it would be best that you do so, along with all its dependencies.



Plug in your iPhone and you should get a notification that a USB Imaging Interface has been attached and is ready for some action.



At this point, it is only when Amarok is up and running that are we be able to distinguish the iPhone as more than just a digital device, and we are able to add or remove music files to and from the iPhone. Did I mention I had problems getting the album covers?



How about GTKPod? Well it was a hit and miss thing with the actual mount location. It was pretty much the same with Dolphin. Sometimes it's there, sometimes it's not.

I wasn't completely happy with the Amarok solution. I needed to be able to mount my iPhone, even partially, so I could also copy some PDF ebooks to my iPhone folders. I was having very little success with GTKPod until a knowledgeable PCLinuxOS community member, AS, posted a forum reply, and together we worked on a solution that can trick the Device Notifier into recognizing the iPhone as a storage device.

Let's start all over again

Quit Amarok and any other application using the iPhone and unplug it!
The following procedure is how we were able to accomplish the task and make PCLinuxOS a much friendlier distro to iPhone users. The steps outlined here should also work on other desktop environments, although the tools used might be different.

First, let's create a folder where we can mount the iPhone, and either /mnt or /media should be an ideal place. For the sake of consistency in this procedure, we will use /mnt.

On the Konsole, type su - followed by your root password then Enter.

Type mkdir /mnt/iPhone [Enter]

The folder belongs to root and has the right permissions. You'll need to change the ownership of the folder to your user so you can have read and write access to it.

Type chown <user>:<user> /mnt/iPhone

where <user> is your user account.




If the permission is not quite the same with drwxr-xr-x, you can type in the command, chmod 755 /mnt/iPhone [Enter].

Note that the iPhone folder on /mnt/ will be there permanently, and will not be removed upon umounting of the device.

Let's exit Konsole for now, and add an iPhone entry on Dolphin. Open Dolphin and make sure that you have Places enabled on the sidebar. If you don't have it, just press F9.

On any empty area on Places, right-click and select Add Entry. On the Add Places Entry dialog box, type in the following:

Label: iPhone
Location: /mnt/iPhone

Click on the folder icon on Choose an icon and locate a cool iPhone icon. If you dont have any, there are some good stuff over at Interfacelift or you can try this iPhone icon. Click OK and you should have an additional entry for iPhone on your Dolphin sidebar. When you click the icon now, there won't be anything in Dolphin to display.



The Script

To get all this in place, we will need to be able to mount (and necessarily, unmount) the iPhone. For this, we will need a script to trick Device Notifier into recognizing the mount point as a storage device.

Open Kwrite and type in the following simple script.

#!/bin/sh
mntp=/mnt/iPhone
if ! ( mount | grep $mntp ); then
   ifuse $mntp
   notify-send -u normal "iPhone Mounted" "The iPhone is now mounted."
   dolphin $mntp
else
   fusermount -u $mntp
   notify-send -u normal "iPhone Unmounted" "The iPhone is now unmounted."
fi



Save the script (as any appropriate filename; AS suggested mgmt.iphone.sh) to any safe location and make sure it is executable - chmod o+x mgmt.iphone.sh

To break the script down, ifuse $mntp is the command to mount the iPhone. What the script would do when it is executed is to mount the device and open the mount point in Dolphin. Or, if already mounted, it would unmount it with fusermount -u $mntp.

But the script is too cumbersome by itself. So, what we need to make the PCLinuxOS user's life easier is to add another action to the USB Imaging Interface when the device is detected by Device Notifier. When clicking the action, the script would be executed and the iPhone would be mounted, followed by Dolphin opening the mount point’s directory. Another click on the action would unmount the device.

The Device Notifier

Open KDE System Settings (aka Configure Your Desktop). Navigate to Hardware > Device Actions and click Add. Type in Mount or Unmount iPhone in the Action name dialog box and click OK.



In Editing Action Mount or Unmount iPhone dialog box, click the floppy disk on the right hand side of Command and locate the script. Change the icon accordingly.

Change the Parameter type to Property Match, the Device type to Camera, the Value name to Supported Drivers, and in Equals, type gphoto. Click Save Parameter Changes then OK. Close KDE System Settings.



Let's see how we did so far. Plug in your iPhone and Device Notifier should popup with 4 actions. Click the USB Imaging Interface to expand the actions, and you should be able to see the additional actions, Mount or Unmount iPhone.



Click the action, Mount or Unmount iPhone.



Eureka! A partial mount of your iPhone's iOS tree structure! Actually, it is only the contents of /var/mobile/Media/ on your iPhone. I am guessing that this would be the equivalent to /home/<user> on PCLinuxOS, but that should be enough to get us going.

GTKPod

This fantabulous application is a graphical user interface for Apple's iPods and iPhones for Unix-like systems, written in GTK+. It provides an iPhone owner-cum-Linux user a means to organize his device — add/remove music files, sort out photos, etc.



The first thing you need to do is set up connecting your iPhone. On the menu, click Edit then Repository/iPod Options. Click Add new repository/iPod...

In Create Repository dialog box, the Repository type should be iPod and type in a name for the Repository name. The iPod mountpoint should be /mnt/iPhone. You can leave the iTunesDB backup as is, as the backup file will be created as you organize your iPhone. Select the correct Model from the dropdown box.



For the time being, we will leave the Synchronization section blank. but there are several scripts in /usr/share/gtkpod/scripts. At the time of writing this article, I haven't had the chance to test them out.


Select the iPhone, or whatever label you used for it, from the list and click Load iPod. At this point, it might take a while (depending on how many music and picture files you have on your iPhone) to "hash" the contents of your iPhone. Once it is done, you will have the additional sections on your iPhone ... and you are in business!