December 2006 Archives

iPod and Udev

| 1 TrackBack

I've had an 8GB iPod for a while now. I haven't bothered, until recently to set up my laptop up so I could automagically mount and unmount the device as any non-root user. These are the steps I took.

  1. Verify correctly working iPod support

    Plug in your usb cable and verify that the kernel is seeing your iPod. Run the command dmesg and you should see output such as this:

    [17190851.088000] USB Mass Storage support registered. [17190856.088000] usb-storage: device scan complete [17190856.088000] Vendor: Apple Model: iPod Rev: 1.62 [17190856.088000] Type: Direct-Access ANSI SCSI revision: 00 [17190856.092000] SCSI device sdb: 3964928 2048-byte hdwr sectors (8120 MB) [17190856.092000] sdb: Write Protect is off [17190856.092000] sdb: Mode Sense: 68 00 00 08 [17190856.092000] sdb: assuming drive cache: write through [17190856.096000] SCSI device sdb: 3964928 2048-byte hdwr sectors (8120 MB) [17190856.096000] sdb: Write Protect is off [17190856.096000] sdb: Mode Sense: 68 00 00 08 [17190856.096000] sdb: assuming drive cache: write through [17190856.096000] sdb: sdb1 sdb2

    You are most interested in the following line:

    [17190856.096000] sdb: sdb1 sdb2

    The second partition (sdb2) is the one you want.

    You can also verify your iPod is connected correctly by running lsusb

    root@hostname:~# lsusb Bus 005 Device 004: ID 05ac:1260 Apple Computer, Inc.

    Verify that you can manually mount the iPod and see the files thereupon.

    root@hostname:~# mkdir /media/ipod root@hostname:~# mount -t vfat /dev/sdb2 /media/ipod root@hostname:~# cat /proc/mounts | grep ipod /dev/sdb2 /media/ipod vfat rw,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1 0 0 root@hostname:~# ls /media/ipod/ Calendars Contacts iPod_Control Notes root@hostname:~# umount /media/ipod
  2. Create Udev rule to make consistent device node

    When you plug in your iPod the kernel will use the next avalible device name following this format; /dev/sd?? Where the first question mark is replaced by a letter from a to z and the second question mark is replaced by a number from 1-9. The problem with this is that each time you plug in your iPod, you're not guaranteed to have it show up in the same location. To solve this, create a Udev rule which automaticly creates a symlink alias for your ipod device.

    Gather information about the device in question

    root@dit00mlt023167:~# udevinfo -a -p /sys/block/sdb/sdb2/

    You are going to see a lot of output here, and only a small amount of it is really needed. Find some unique keys/identifiers for your hardware and take note of them. Be aware that they all need to be from the same block of data, and some keys are too generic to be used. Here's a sample of the keys I chose:

    BUS=="usb" SYSFS{serial}=="000A2700189125F2" KERNEL=="sdb2"

    Now we need to create a Udev rule, using these keys, which will create our device alias. Create the file /etc/udev/rules.d/30-ipod.rules with the following line as it's only contents.

    BUS=="usb", SYSFS{serial}=="000A2700189125F2", KERNEL=="sd?2", SYMLINK=="ipodnano"

    Notice the SYMLINK key and the way the KERNEL key has been modified. This way, no matter how the device gets detected, the second partition will always end up named /dev/ipodnano. Unplug and re-plug your iPod and check to see that the symlink is being created.

    root@hostname:~# ls -l /dev/ipodnano lrwxrwxrwx 1 root root 4 2006-12-27 14:40 /dev/ipodnano -> sdb2
  3. Create an fstab entry to allow non-root users to mount the iPod

    The last step is to create an entry in the file /etc/fstab to allow users other than root to mount the device and access the files. Add the following line to the fstab file:

    /dev/ipodnano /media/ipod vfat user,noauto 0 0

    The first field is the device. Using the symlink created eariler assures that no matter what order the block devices are detected, your iPod is always located there. The second field is the mount point. Using /media/ipod is compliant with the current revision of the FHS. The third field is the filesystem. Most recent iPods use the FAT32 filesystem to be cross-platform compliant. The fourth field is where the magic happens, the user option allows a non-privliged user to mount and unmount this volume, and to have proper permissions and ownership of the files therein, noauto keeps the system from trying to mount the iPod during boot. The last two fields are the dumpfield and fsck field respectivly, they are used by external applications to decide if the volume needs to be backed up and in which order to do filesystem checking.

  4. Use your newly created device and rules to easily modify your collection on your ipod

    Now you have all the proper settings, you should be able to modify your iPod's library pretty easily as a non-priviliged user. Check to see everything works:

    goozbach@hostname:~$ mount /media/ipod goozbach@hostname:~$ ls -l /media/ total 20 lrwxrwxrwx 1 root root 6 2006-12-05 06:41 cdrom -> cdrom0 drwxr-xr-x 2 root root 4096 2006-12-05 06:41 cdrom0 drwxr-xr-x 6 goozbach goozbach 16384 1969-12-31 19:00 ipod goozbach@hostname:~# ls /media/ipod/ Calendars Contacts iPod_Control Notes

    You can now use programs such as GTKpod to manage your iPod music library.

This guide has been tested and proven to work on FC6 and Ubuntu Edgy

Full Rolling Boil

It's OUT! Software for Starving Students CD has been released.

Great collection of software that is designed to help those poor college students have a decent set of software tools.
Please help seed the torrents. Last year NeverBlock had over 400GB of downloads from mirroring this cd. Help spread the love.

Bubble Bubble Bubble

Something somewhat big is brewing. Keep your eyes open for some sort of announcement later today.