Linux Multimedia Hacks
Authors: Rankin K
Published year: 2005
Hack 42. Use an iPod with Linux
You don't need a Windows PC or a Mac to use an iPod .
Linux users' relationship with the iPod is a bit like a girl who can't get a date to the Sadie Hawkins dancethe users keep asking for a bit of attention, and Apple just pretends it doesn't hear. If this were a less hackish group of users, that would be the end of the story, but thanks to some clever programming, Linux users can use an iPod with Linux and this hack shows you how.
This is aimed at Linux puriststhat is, people who don't want to have to use a Mac or Windowsbased PC, nor Wine nor Windows softwareto get going. (I fall into this category, not because of any religious convictions, but merely because Linux is all I have. For updates, visit http://pag.csail.mit.edu/~adonovan/hacks/ipod.html.)
Here's what you'll need if you want to use an iPod with your Linux box:
2.31.1. Setting Up Your Linux Desktop
Assuming you're using a PCMCIA FireWire card, once the card is inserted, the cardmgr daemon should take care of loading the ieee1394 and ohci1394 modules. If you have a PCI card, these should be loaded by system startup ( /etc/rc.local ).
When you attach the iPod to the FireWire interface, the sbp2 module is loaded automatically. (If it's not, load it with modprobe .) You should see messages appear in dmesg indicating that the device is recognized. Additionally, /proc/bus/ieee1394/devices contains information on each device, including the string [ Apple Computer, Inc .] for the iPod:
ieee1394: Host added: Node[00:1023] GUID[00d0f5cd4008049d] [Linux OHCI -1394] ieee1394: Device added: Node[00:1023] GUID[000a2700020e545e] [Apple Computer, Inc.] ieee1394: Node 00:1023 changed to 01:1023 SCSI subsystem driver Revision: 1.00 ieee1394: sbp2: Logged into SBP-2 device ieee1394: sbp2: Node[00:1023]: Max speed [S400] - Max payload  scsi0 : IEEE-1394 SBP-2 protocol driver (host: ohci1394) $Rev: 707 $ James Goodwin SBP-2 module load options: - Max speed supported: S400 - Max sectors per I/O supported: 255 - Max outstanding commands supported: 64 - Max outstanding commands per lun supported: 1 - Serialized I/O (debug): no - Exclusive login: yes Vendor: Apple Model: iPod Rev: 1.40 Type: Direct-Access ANSI SCSI revision: 02 Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0 SCSI device sda: 58595040 512-byte hdwr sectors (30001 MB) sda: test WP failed, assume Write Enabled sda: sda1 sda2
The iPod appears as a fake SCSI device (typically /dev/sda if you have no other SCSI devices) and can be accessed using the regular Unix tools for block devices. However, if you are using a Mac iPod, fdisk will not recognize the partition map, and you will get a message resembling "Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel." In this case, it is time to follow the GNU instructions (for conversion).
At this point, the Linux IEEE1394 drivers ( ieee1394, ohci1394 ) should have recognized the hardware:
$ cat /proc/bus/ieee1394/devices Node[00:1023] GUID[001106000000649a]: Vendor ID: `Linux OHCI-1394' [0x004063] Capabilities: 0x0083c0 Bus Options: IRMC(1) CMC(1) ISC(1) BMC(0) PMC(0) GEN(0) LSPD(2) MAX_REC(2048) CYC_CLK_ACC(0) Host Node Status: Host Driver : ohci1394 Nodes connected : 2 Nodes active : 2 SelfIDs received: 2 Irm ID : [00:1023] BusMgr ID : [00:1023] In Bus Reset : no Root : no Cycle Master : no IRM : yes Bus Manager : yes Node[01:1023] GUID[000a2700020ec65a]: Vendor ID: `Apple Computer, Inc.' [0x000a27] Capabilities: 0x0083c0 Bus Options: IRMC(0) CMC(0) ISC(0) BMC(0) PMC(0) GEN(0) LSPD(2) MAX_REC(2048) CYC_CLK_ACC(255) Unit Directory 0: Vendor/Model ID: Apple Computer, Inc. [000a27] / iPod  Software Specifier ID: 00609e Software Version: 010483 Driver: SBP2 Driver Length (in quads): 8 $ cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: Apple Model: iPod Rev: 1.40 Type: Direct-Access ANSI SCSI revision: 02
Performing the HFS-to-FAT32 conversion involves the following steps:
If all goes well, resetting the iPod (by holding down the Menu and Play buttons for 10 seconds) will cause it to reboot to the familiar menus . If not, go through the instructions again. Remember, the iPod is just a hard disk, so as long as you have the original firmware backed up correctly and safely on your PC, you can reformat it as many times as you like. (It worked for me the first time.) Be wary about installing different firmware from the one it came with, however.
At this point, you should be able to mount the disk in the usual way. Once this works, setup is complete and you can follow the normal usage instructions described in the next section.
2.31.2. Normal Usage
The Linux drivers for the iPod are still a little flaky; sometimes, the sbp2 driver gets stuck indefinitely in its initializing state and cannot be removed, and at other times the machine hangs .
To minimize the risk of such errors, I strongly advise you to follow a disciplined procedure for docking and undocking the iPod. Here's the order of events I usually employ :
Note that these steps are perfectly symmetrical. This seems to achieve greater reliability than performing them in an arbitrary order.
I use two scripts, dock-ipod and undock -ipod , whenever I attach or detach the iPod to or from the interface card. Here's dock-ipod :
#!/bin/sh modprobe sbp2 mount /dev/sda2 /mnt/ipod/
And undock-ipod :
#!/bin/sh umount /mnt/ipod rmmod sbp2
They must both be run as root :
$ su - root -c ./dock-ipod
$ sudo ./dock-ipod (if the user is a sudoer)
$ su - root Password: root$ ./dock-ipod
2.31.3. Downloaded MP3 Files and ID3 Tags
The iPod does not care about the filenames of MP3 files; all its database information is supplied by ID3 tags within the MP3 files. Therefore, these must be present for transferred files even to appear on the iPod.
You might want to add MP3 files that did not come from a CD (e.g., those downloaded from Napster, Kazaa, etc.) to your iPod. The ID3 tags in such files are often inappropriatefor example, because they feature the original artist/album name from the CD they came from, instead of the logical group to which they will belong on your iPod (e.g., Misc/80s Synth Pop ). If you do nothing about this, you will find each song appearing in its own artist/album category, with no useful grouping. You'll also need to tag manually when CDDB lookup fails (e.g., for non-industry CDs) or for MP3 files that were hand-encoded from WAV.
To change the tags, you need a tool such as ID3ed (http://www.dakotacom.net/~donut/programs/id3ed.html; free). This tool is pretty straightforward, and it comes with a helpful manpage . The synopsis says:
id3ed [-s songname] [-n artist] [-a album] [-y year] [-c comment] [-k tracknum] [-g genre] [-q] [-SNAYCKG] [-l] [-L] [-r] [-i] [-v] files…
Obviously, you don't need to include all those options. Here's an example:
$ id3ed -s "Red House" -n "Jimi Hendrix" \ -a "Are You Experienced?" -k 3 redhouse.mp3
Alternatively, use a graphical tool such as xid3 (www.nebel.gmxhome.de/xid3/; free), which has a Tcl/Tk-based frontend for ID3-tag editing that makes it a lot easier to use for this information. The main ID3 tags for the iPod are Artist, Album, Title, and Track Index (and Genre, if you bother to use that).
With minimal effort, your iPod will play nicely with Linux. No, you won't be able to buy songs from the iTunes Music Store, but you'll still have most of the functionality Mac and Windows users have.
Linux Multimedia Hacks
Authors: Rankin K
Published year: 2005