LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Linux Answers > Hardware
User Name
Password

Notices

By |2ainman at 2004-11-29 18:24
HOWTO: Use your 4th generation iPod on Linux using USB

Disclaimer: Do all instructions at your own risk. No responsibility will be claimed on possible damages incurred to your iPod. This process may also invalidate your warranty.

You may or may not be able to adjust this howto to suit your needs if you have an older generation iPod.

Much of this howto was taken from Alan Donovan. His page found here is protected under the GNU fdl

conventions:
# is assumed to mean that you are root in a shell environment
$ is assumed to mean that you are a normal user in a shell environment
bold commands are to be typed in at the appropriate prompt.

I ran through this howto using a full install of slackware 10.0 with the 2.4.26 kernel installed and the 20GB iPod.
What you will need:
  • A fourth generation iPod(including usb cable) ready to be wiped of all contents or already windows formatted
  • bin utils fdisk, dd, mkdosfs
  • gtkpod 0.85 and associated dependencies
Having a friend w/ a Mac computer is HIGHLY beneficial
If you've already used your iPod in windows, then it has already been formatted, and you can skip to the part titled Mounting the iPod where I discuss how to interface with the iPod using usb modules and gtkpod. You may, however, want to look over briefly the beginning because it assures that your iPod is being properly recognized.
A newly purchased iPod, or an iPod that has been only used on a Mac must be formatted as a fat32 file system for the purposes of this howto. New iPods and those used only on Macs use the HFS+ filesystem. You may have noticed that linux will support HFS, but do not consider messing around with your iPod using HFS; the differences between HFS and HFS+ are numerous. However, kernel support for HFS+ is in the experimental stage, and is part of the 2.6 kernel tree. Therefore, the first part of this tutorial is aimed at getting your iPod mountable using fat32 on your linux system.

Recognizing your iPod

The first thing you'll want to do is plug in your iPod

# dmesg
Code:
hub.c: new USB device 00:02.2-1, assigned address 15
usb.c: USB device 15 (vend/prod 0x5ac/0x1203) is not claimed by any active driver.
Initializing USB Mass Storage driver...
usb.c: registered new driver usb-storage
scsi1 : SCSI emulation for USB Mass Storage devices
  Vendor: Apple     Model: iPod              Rev: 1.63
  Type:   Direct-Access                      ANSI SCSI revision: 02
Attached scsi removable disk sda at scsi1, channel 0, id 0, lun 0
SCSI device sda: 39063024 512-byte hdwr sectors (20000 MB)
sda: Write Protect is off
 sda: sda1 sda2
WARNING: USB Mass Storage data integrity not assured
USB Mass Storage device found at 15
USB Mass Storage support registered.
Here we can see that the usb-storage module is emulating the iPod as a scsi device and that that device is /dev/sda.
If this does not show up:

# rmmod usb-storage
# modprobe usb-storage

Here we reload the module so that it may properly recognize the iPod. The usb modules don't always behave in the best manner concerning ejects and what not.

# cat /proc/bus/usb/devices and
# cat /proc/scsi/usb-storage-0/* and
# cat /proc/scsi/scsi all produce simplified versions of the information found in dmesg

Formatting the iPod
Now that you've got your iPod connected for sure you need to backup its firmware and reformat it.

# dd if=/dev/sda2 of=backup_firmware

This may take about 10 - 15 seconds to complete, and should result in a file ~ 32MB.
Keep this file, as it is the key to restoring your iPod. As long as you have this file, you can always have something to fall back on.
Now that you have backed up the firmware for the iPod, you must wipe the partition map

# dd if=/dev/zero of=/dev/sda bs=1M count=10

Here we zero out the first 10 MB of the iPods first partition. Doing this is the equivalent of deleting partitions from the partition table, but since our fdisk does not understand HFS+ filesystems, it would be rather difficult to read the partition table to delete the partitions needed.
Now we know that we've killed the partition map, and that its empty, but the kernel modules don't know that

# rmmod usb-storage
# modprobe usb-storage

You can then check again, using dmesg or the other instructions above, to assure that your iPod is again being recognized. You'll now see
Code:
  sda: unknown partition table


Now that it is recognized, we will format it

# fdisk /dev/sda
# n // for new partition
# p // for primary
# 1 // first partition
# <enter> // default first sector is 1
# +33M // enough space to allow that 32MB file
# n // for new partition
# p // for primary
# 2 // second partition
# <enter> //default first sector is continuation of last sector of first partition
# <enter> //default last sector is last available sector
# t // modify partition type
# 1 // modify type of first partition
# 0 // empty filesystem type (ignore warnings)
# t // modify partition type
# 2 // modify type of second partition
# b // change to fat32 "win95" filesystem
# w // commit the changes

Now we will copy the firmware back to the iPod, this time using the first partition

# dd if=backup_firmware of=/dev/sda1

At this point you will most likely see a check along with the message
"ok to disconnect" which happens normally when the iPod is done formatting in windows!
Since its ok to disconnect the iPod, we have to disconnect, then reconnect it because we're not done with it quite yet. Upon unplugging it, you may notice that its rather warm. This is normal. Now plug it back in, and depending on your firmware version you may/may not see the folder icon followed by the do not disconnect icon. Eject the iPod

# eject /dev/sda

Now unload and reload the module usb-storage, then unplug and put back in the iPod (just for good measure). Mine still didn't get emulated as a scsi device, so I had to reload the whole hotplug script via /etc/rc.d/rc.hotplug stop && /etc/rc.d/rc.hotplug start
Then we have to make the second partition into a fat32 file system

# mkdosfs -F 32 -n "++nerd;" /dev/sda2

"++nerd;" was the name I gave to my iPod. (This will show up in settings -> about)
Now comes the moment of truth:
If your iPod has that nasty "do not disconnect" sign flashing, you can get rid of it by doing

# eject /dev/sda

It may or may not be off already, either way, once you feel it is safe to unplug the iPod, do so.
Reset the iPod by holding both the Menu and Play buttons for 10 seconds. The apple logo should appear. If it doesn't, don't panic, just go through the steps again and if it still doesn't work, consult the links at the end of this document. The second iPod I did actually had some difficulties at this stage. It kept booting up to the apple screen, and then would go back to that folder with the exclamation point. I tried reformatting again, to no avail. Finally, upon looking at some documents online about actually putting linux ON your iPod, I decided to create three partitions, the first being one cylinder long and the other two being like the original two. (in dmesg, or the output from fdisk I recall something being wrong with sector 0x00 or something.) If you totally screw up your iPod, that "friend with a Mac" will come in great handy as they can download the update /restore utility which will fix your iPod's problems.

Mounting the iPod
Plug the iPod back in if you have not already done so.

# rmmod usb-storage
# modprobe usb-storage
# cd /mnt
# mkdir ipod
# mount -t vfat /dev/sda2 ipod

You reload the modules to identify your iPod yet again, then you create a directory for a mount point for the iPod. Lastly, you mount the iPod into the mount point with a file type of "vfat." If all goes well,

# ls ipod

should result in seeing four folders "Calenders" "Contacts" "Notes" and "iPod_Control".
Other versions of the iPod may not have these other folders, as previous iPods did not have all the functionality of the new ones (for better or worse).

Using gtkpod

We will assume that you have correctly built and installed gtkpod onto your system. So the first thing to do is fire up gtkpod. Upon opening you'll notice an interface with about four total panes. The very far left pane that spans the windows height is the playlist area. The top two panes off on the right are for sorting files locally. The bottom pane is for files actually on the iPod. A tutorial on the use of this program is out of the scope of this HOWTO, but we will assume that you can navigate the basic features of the program. First you're going to go to "file -> "create directories" ... won't let you do it will it? (You do not have write access to mnt/ipod.) If you can, thats great, but the vast majority of us are going to have to fix some stuff. First of all, you should not be running gtkpod as root, we want to be able to have the user mount the iPod and put files to it. The first thing we need to do is edit the /etc/fstab file. This is a file that keeps track of the options to mount all of the filesystems.
Add
Code:
/dev/sda2       /mnt/ipod         vfat        rw,users,noauto  0   0
This will mount the iPod under /mnt/ipod as a vfat file system with read/write permissions for all users. You can change this accordingly, but the user must be able to mount it.

# umount /mnt/ipod

make sure that it is unmounted as root before proceeding.

$ mount /mnt/ipod

Notice that this is the regular users's shell; you want the user to be able to mount the iPod.
Open up gtkpod again and go to create directories ... this time since you already mounted it with your permissions, the directories should be created as planned. (Actually this is still not working, but we still accomplished needed steps by editing the fstab)
Mounting the iPod each time seems like it would get tiresome, so lets tell gtkpod to do it for us
edit -> edit preferences -> input/output tab ipod mount point=/mnt/ipod
check "handle mounting and unmounting of ipod"
optionally, check "automatically import iTunesDB" if you want the files to be read at startup.
gtkpod would not have been able to do this automatically had we not defined the mount point in /etc/fstab

$ gtkpod

we will open gtkpod through a terminal so that we can see any error messages it may give. If it says that /dev/sda2 is not a block device, then its the modules fault. You'll have to go back into root,reload the modules, exit, and try to open up gtkpod again

# rmmod usb-storage
# modprobe usb-storage
# exit
$ gtkpod

Watch for error messages again. If all goes well on loading, press the "add files" button and add a few files to your iPod. Press the sync button to move the songs over to your iPod. Then exit the program. Hopefully, there were no error messages about unmounting. There you have it now, you've managed to get songs on your iPod w/o having to bow to Bill Gates.

Laziness settles in

So by now, you must be pretty fed up with unloading and reloading the usb-storage module, especially because you have to do it in root, which is not what we want. To fix this, we'll set up the sudoers file to allow users to specifically load and unload the usb-storage module. The sudoers file, located in /etc/sudoers by default is edited using the command visudo. Visudo's default editor is vi, which I don't particularly like. You can either rename vi and create a softlink to vim or something, or you can use the variable "editorsudoers"

# editorsudoers=/usr/bin/vim
# visudo
Code:
Cmnd_Alias IPOD=/sbin/modprobe usb-storage, /sbin/rmmod usb-storage
%users    ALL= NOPASSWD : IPOD
%users    ALL= NOPASSWD : /usr/bin/eject /mnt/ipod
The preceding sets up an alias for commands involving the iPod that involve root permissions. That command set is then given to the group users, to be run on all servers, without a password. We also included the eject command which will be handy later.
Lets try them out

$ lsmod | grep usb
Here, we should see that the module usb-storage is still loaded.

$ sudo /sbin/rmmod usb-storage
$ lsmod | grep usb
Now its gone

$ sudo /sbin/modprobe usb-storage
$ lsmod | grep usb
and its back again.

Gtkpod has a nice little feature that lets you specify commands to be run before gtkpod starts up, and after it exits. In ~/.gtkpod/ you can create two files; gtkpod.in and gtkpod.out. These files can be filled with simple commands to be run.

$ cd ~/.gtkpod
$ touch gtkpod.in
$ touch gtkpod.out
$ echo "sudo /sbin/rmmod usb-storage" >> gtkpod.in
$ echo "sleep 1" >> gtkpod.in
$ echo "sudo /sbin/modprobe usb-storage" >> gtkpod.in
$ echo "sleep 4" >> gtkpod.in
$ echo "sleep 2" >> gtkpod.out
$ echo "sudo /usr/bin/eject /mnt/ipod" >> gtkpod.out

This sequence will unload then load the usb-storage module, with small intervals of time in between, so as to give things time to load.
The operation will end in gtkpod unmounting the iPod. But if you remember, when the iPod was unmounted, it still had that nasty "do not disconnect" screen. Thats where eject comes in handy. Thats about it, thats all I have for you. Have fun!

Summary

This howto covered the process of recognizing, configuring, and utilizing a 4th generation iPod on a usb interface with a hotpluggable kernel, in particular, the default kernel for slackware 10.0; 2.4.26. We used our already up and running system to meet the physical connection requirement of this process. We tailored a few things on our system, such as the file system tab and sudoers file to better integrate with the software (gtkpod) we used to interface with the device. Lastly, we tweaked the software to take advantage of the changes we made to our system.

More information

http://people.csail.mit.edu/people/a...acks/ipod.html
  • Primary source used in this howto
  • Written for firewire devices
  • Discusses alternate possibility of HFSplus file system in kernel
  • Protected under GNU fdl
http://gtkpod.sourceforge.net/README
  • Extremely long readme detailing gtkpod in all its glory
http://www.gnu.org/software/gnupod/gnupod.html
  • Work from which previous source was also derived
  • Also protected under the GNU fdl
  • Contains information about gnupod, a collection or perl scripts which gtkpod was/is based off of.

o'reilly digital media
  • Link detailing the process of putting a linux distribution, uClinux, onto an iPod!
  • Inspiration for adding in a 1 cylinder partition on my iPod to work around IO error sector 0
http://developer.apple.com/reference...d/GS_Hardware/
  • For those that want to look under the hood
Special thanks to Angello Pozo for letting me use his Mac in a time of great need!

by cleeland on Mon, 2005-01-31 13:07
Just an FYI that this process didn't work for me on a 3G ipod running firmware version 2.2.

Everything worked until I tried to dd the firmware back to partition 1. During that, I got a "device out of space" error.

The bad thing is that, since the firmware wasn't there, the ipod wouldn't boot--just hung at the apple logo screen forever. I ended up popping it into the dock and putting it into forced-firewire mode, and using "iPod Restore" from my wife's mac.

Now, looking in more detail...

Sure enough, looking at the firmware file vs. partition size, the firmware file is slightly larger than the partition.

Backing up the firmware:
Code:
root@grenoble:~/ipod# dd if=/dev/sda2 of=backup_firmware
65536+0 records in
65536+0 records out
33554432 bytes transferred in 32.646649 seconds (1027806 bytes/sec)
Creating the 1st partition:
Code:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-19073, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-19073, default 19073): +33M
Writing the firmware back to the partition:
Code:
root@grenoble:~/ipod# dd if=backup_firmware of=/dev/sda1
dd: writing to `/dev/sda1': No space left on device
65505+0 records in
65504+0 records out
33538048 bytes transferred in 83.290233 seconds (402665 bytes/sec)
Size of backup firmware file:
Code:
root@grenoble:~/ipod# ls -l backup_firmware
-rw-r--r--  1 root root 33554432 2005-01-30 10:19 backup_firmware
I'm not hip to all nuances of fdisk, so maybe there's an easy way around this. But, no matter what I seemed to try to do to get a partition sized appropriately for the size listed of the firmware, I couldn't convince fdisk to do it. FWIW, fdisk version is 2.12.

by allforcarrie on Tue, 2005-02-01 01:10
i dont know what my problem is but i cant even get my ipod to mount.

by harerama on Mon, 2012-08-20 18:22
Thank you my sweet love. My precious ipod is currently syncing with rhythmbox.


  



All times are GMT -5. The time now is 11:05 AM.

Main Menu

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration