ipod

Using iPods with Linux


by: Ky MacPherson
last updated: 07 Dec 2009

I bought an iPod Shuffle in 2005 (the white rectangular model, not one of the little square ones that they sell today, but the text below should apply to both) and then in 2007 I bought an 80GB iPod (5.5 generation). They are both great devices.

The Shuffle's small size makes it great for exercising. With flash memory (no moving parts) and no display, you don't have to worry about jostling it around or dropping it.

The big iPod is great for home or office use where you may do some more extended listening; it will hold a much larger selection of songs, and you can navigate your collection with the menus. It can also play movies, so it's great for taking on an airplane.

I found that using GNUpod , I was able to initialize the iPods and upload songs to them without using the Windows software that came packaged with the iPod.

1. Mounting the iPod


The iPod will be plugged into a USB port, and accessed using a VFAT filesystem. If you compiled your own linux core, make sure you enabled USB and VFAT support.

Newer linux distros will create an /etc/fstab entry automatically a few seconds after the USB device is plugged in. Just watch for a line being added to this file to see what the mountpoint is named (and substitute that name for /mnt/ipod in the following sections). With an older kernel you need to edit /etc/fstab yourself, which you can do as follows:

Create an empty directory /mnt/ipod and add an entry in /etc/fstab for the iPod, like the following:
/dev/sda1     /mnt/ipod      vfat      sync,user,noauto,umask=000      0      0

The device to use (/dev/sda1 in the example) depends on how many scsi devices you have, and also the type of iPod. For the Shuffle, you will want to mount the first partition on the appropriate device (sda1 or sdb1 or sdc1 ...). For the larger iPod models the firmware is on the first partition, so to access the music filesystem you need to mount the second partition (sda2 or sdb2 or sdc2 ...).

Once the entry is set in /etc/fstab, the ipod can be mounted with the command Note the iPod battery will charge whenever it is plugged into the USB port, regardless of whether or not it is mounted. Mounting (and unmounting) are necessary only to access the iPod filesystem.

2. Initializing the iPod


This creates the directory structure on the iPod. It only needs to be done the first time you mount the iPod.

Install GNUpod version 0.98 or later and peruse the documentation. Note that the instructions on upgrading the iPod Firmware are not applicable for the iPod shuffle. For my generation 5.5 iPod there was no need to do a firmware upgrade either. I was able to plug in my iPod right out of the box and initialize it with

3. Transferring songs


To upload songs, plug the iPod into the USB port and mount it. Use the command to transfer all mp3 files in the current directory. Note that gnupod_addsong will detect if an mp3 is already stored on the iPod, so using wildcard in the filename (*.mp3) has the effect of only transferring songs that are not already uploaded.

You can check the amount of free space remaining with After you have finished uploading, sync the iPod database with For iPods with displays, you can also issue an eject command to get rid of the "Do not disconnect" message on the display. Rather than umount, use the command

4. Ripping from CDs


The iPod will play soundfiles in the .mp3 or .wav format. An mp3 file encoded at 128kBit/sec is about 1/10 the size of a wav file and still reasonably good audio quality, so that is the encoding I prefer to use on the iPod shuffle.

My 80GB iPod has noticeably better audio quality than the shuffle, and with the larger storage capacity, the filesize of individual mp3s is not such a concern as it is on the shuffle, so when encoding mp3s for the 80GB iPod I use a higher quality variable bitrate encoding.

There is a very nice GUI-driven ripper for linux called Grip . The 'Rip and Encode' feature automates the process of ripping and encoding tracks simultaneously. Grip can also look up album and track names from the internet. To encode mp3s with Grip, you will also need to install an mp3 encoder (such as lame or bladeenc) and provide the name of the encoder in the Config/MP3 menu.

If I want to edit a soundfile before uploading it to the iPod, then I will rip it to a wav file, so that I may edit it before encoding to mp3. For example, a track may have a long period of silence at the beginning or end that I want to remove. I found it is simpler, and better for audio quality, to do these edits to a soundfile while it is still in the wav format. To generate a wav file, you can use the 'Rip Only' button in Grip, or just use cdparanoia from the command line.

5. wav toolbox


There is a software package called ecasound that is useful for editing wav files. Here are several examples of edits using ecasound:

After modifying the wav by any of the procedures above, lame or bladeenc may be invoked from the command line to encode the mp3.

For 128 kBit/sec encoding with bladeenc, use: For 128 kBit/sec encoding with lame, use: For a higher audio quality variable bitrate encoding with lame, use:

6. mp3 toolbox


Sometimes I will download a track in mp3 format and want to edit it before loading it onto my ipod. ffmpeg is capable of simple editing directly on the mp3 format. For example:
Note that the ID3 tags will not be copied to the newly created mp3. We'll talk about how to create ID3 tags in a later section.

The advantage of using the above commands to edit the mp3 format directly is that the mp3 will not need to be recoded, i.e. there will be no degradation of audio quality. However, to be able to perform more complicated edits, such as fade-in or fade-out, the track will have to be converted to the wav format, edited, and then re-encoded. The conversion from mp3 to wav can be accomplished with ffmpeg:

7. Normalizing mp3 volume


mp3s ripped from various discs will have different volume levels. I have had good results using MP3Gain to normalize the volume levels. After ripping an mp3, or obtaining one from the internet, I levelize it with the command:

8. ID3 tags


You can manage the songs on the shuffle by inventing a file naming convention that makes sense to you; there is no real need to edit the ID3 tags. The iPods with displays on the other hand use the data in the ID3 tags to organize the menus, so it is necessary to set these tags for your mp3 files. I use the id3info/id3convert/id3tag utilities from the id3lib package to edit the id3v2 tags.

Note that mp3 files obtained from the internet may contain id3v1 tags which will conflict with id3v2 tags, so the first thing I do with an mp3 I downloaded is strip any existing tags with To set the tags, use id3tag. The command line syntax is pretty intuitive so take a look at the help page: The important tags to set are genre (TCON), artist (TPE1), album (TALB), and song (TIT2) because these strings will appear in the menu tree. You can also set tags for year (TYER) and track number (TRCK) which won't directly appear themselves, but will affect the ordering of the choices in the menus.

9. Podcasts


A podcast can be uploaded to the iPod using gnupod, just like a regular mp3 file. The genre tag can be forced to "Podcast" by using the --set-genre flag: The mp3 won't appear in the "Podcast" menu at the top level, but will instead appear in a music genre called "Podcast" (i.e. "Music>Podcast"). Aesthetically it's a bit clumsy, but it's perfectly functional. You can set the "shuffleskip" attribute for podcast tracks so that they do not get mixed in with the music when playing tracks in randomize mode. Use the following command to set this attribute for all mp3s in the "Podcast" genre:

10. Movies


To prepare a movie for the iPod, it must be converted to an mp4 file with the appropriate screensize and video bitrate. I use ffmpeg to do the conversion. ffmpeg is a powerful utility with a lot of options, so I will just give a few examples of commands I have used successfully. Once a movie has been converted to mp4 format, upload it to the iPod with gnupod_addsong.pl just as you would an mp3 file.

11. eBooks


The Notes mechanism on the 5.5G iPod allows the iPod to display text files. The iPod has a top level directory called "Notes", which the user is free to fill with subdirectories and/or text files, which the iPod can navigate and display. An important limitation to keep in mind is that the size of text files is limited to 4kb.

With a bit of effort, an eBook can be converted into a collection of little text files suitable for display as Notes. For eBooks in PDF format, the first step is conversion to a single text file, which can be accomplished with the pdftotext utility included with xpdf.

Issuing the command creates a text file with the Latin1 (ISO-8859-1) encoding and form feed characters for page breaks. The quality of the results are dependent on the how the PDF is coded. In some cases, a little perl scripting may be helpful to improve the readability. As an example, for one particular eBook I was able to preserve the spacing between paragraphs with the following command: The next step is to divide the text file into small chunks. With a little luck, the individual pages of the PDF document will not exceed the 4kb size limit. The following perl program utilizes the form feed characters inserted by pdftotext to generate one text file per page. For each page, it also creates hyperlinks to the previous and next pages, to allow easy navigation on the iPod. This perl script takes one argument, which is the name of the text file produced by pdftotext, and creates a directory that contains a separate text file for each individual page. If it so happens that the text contained on the individual pages of the PDF document exceeds the 4kb limit, then a little more perl wizardry will be required.

Once copied to the iPod, the book can be found under Extras>Notes from the main menu. When navigating through the pages, the center button is used to follow a hyperlink, and the Menu button behaves like the "Back" button on a browser, going back through the previous link followed. After reading through a bunch of pages, and traversing a bunch of links in the process, the easiest way to exit the reader is to press and hold the Menu button, which will bring you back to the iPod main menu.

12. Troubleshooting


I had no issues using the iPod for many months using the procedures above. However when I recompiled my kernel (2.4.27) to include the idescsi emulation (and probably some other scsi modules) to get my CDRW drive working, I began to see error messages after unmounting the iPod (or after unmounting another usb storage device, such as my digital camera). I would see errors like the following in /var/log/syslog:

Mar 10 06:22:36 debian kernel: sda: Unit Not Ready, sense:
Mar 10 06:22:36 debian kernel: Info fld=0xa00 (nonstd), Current 00:00: sense key Not Ready
Mar 10 06:22:36 debian kernel: sda : READ CAPACITY failed.
Mar 10 06:22:36 debian kernel: sda : status = 1, message = 00, host = 0, driver = 08
Mar 10 06:22:36 debian kernel: Info fld=0xa00 (nonstd), Current sd00:00: sense key Not Ready
Mar 10 06:22:36 debian kernel: sda : block size assumed to be 512 bytes, disk size 1GB.
Mar 10 06:22:36 debian kernel: sda: test WP failed, assume Write Enabled
Mar 10 06:22:36 debian kernel: sda: I/O error: dev 08:00, sector 0
Mar 10 06:22:36 debian kernel: I/O error: dev 08:00, sector 0
Mar 10 06:22:36 debian kernel: unable to read partition table
Mar 10 06:22:36 debian kernel: Device not ready. Make sure there is a disc in the drive.
Mar 10 06:22:36 debian kernel: Device not ready. Make sure there is a disc in the drive.

I found I could get rid of these errors by rebuilding the kernel with usb-storage built as a module (rather than compiled directly into the kernel). After this change, the procedure to mount the iPod is: and after finishing writing to the iPod, unmount the device, and then additionally unload the usb-storage module with the commands:


Ky's Home Page