Using the ImageMate with Linux

Here's what I've been able to figure out about using the Sandisk ImageMate SDDR-31 compact flash card reader with Linux. This card reader accepts both type I and type II CF cards, but does not accept any other media (no SmartMedia, etc). This is fine by me, because it is my reasonably educated opinion that CF cards are the best storage medium.

This page assumes assumes the 2.2.17 kernel, with USB support compiled in. The 2.2.18 kernel comes with USB support, as does the 2.4 kernel, and most of the 2.2.x kernel RPMs distributed by Mandrake.

In the instructions, I'll use a monospace font for commands you are supposed to type in at a console. Unless otherwise specified, all commands are run as root.

Before you start, make a directory in /mnt where you will mount your CF cards. I use /mnt/cf in the instructions below. You only have to do this once.

These instructions are only valid if you don't have any other USB devices that use usb-storage!! If you do, you may have to resort to unplugging the ImageMate before you remove the CF card, and putting the CF card in the reader before you plug the ImageMate in. I have to believe that this bug (?) in usb-storage has been fixed by the 2.4 kernel.

Update 2002-8

A while ago, Peter Rosell sent me a message suggesting that I add the following to this tutorial:
You should add which modules/features that are needed. It took me a while before I got all modules compiled and loaded. The modules that I had to load are(in that order):
  1. Plug in the CF reader.
  2. Insert the CF card into the reader
  3. modprobe usb-storage
  4. mount -t vfat /dev/sda1 /mnt/cf
  5. Copy the files out of /mnt/cf to wherever you want them to live. You may have to navigate some subdirectories; for example, my Canon PowerShot G1 stores data in /mnt/cf/dcim/100canon.
  6. You can delete everything in /mnt/cf, if you want to clear the data off of the card.
  7. sync ; sync -- this is very important! Always do this before unmounting the card!
  8. umount /mnt/cf
  9. rmmod usb-storage
You may encounter a variety of problems. One common problem I find is that after changing cards, sometimes usb-storage will refuse to correctly recognize a new card. Often, this evinces itself by the modprobe taking a long time and then the mount reporting that "sda1 is not a valid block device". When this happens, rmmod usb-storage, unplug the card reader, plug in back in, and start again. This usually clears everything up. I suspect that changing cards confuses usb-storage, while changing USB devices doesn't.

IBM MicroDrives

These drives are a little too slow for the usb-storage module, and require a little extra work, although they do work well once you get them mounted. The problem is that the cards require just a little too long to spin up, and the usb-storage module isn't able to read the partition table quickly enough. To get this CF card to work, do step 3, then step 9, then step 3 again. Pause for a second between each step. By the second modprobe, the drive should be spun up, and you should be able to mount the card as normal.

The Script

Here is a script you can use to make mounting and unmounting the cards a little easier. Do not run this script if you have any other USB devices that rely on usb-storage! A reasonable way to check for this is to run the following command as root:
lsmod | grep -c usb-storage
If you get anything other than 0, you have usb-storage loaded, and you should stop and think about why this might be.
#!/bin/sh

MOUNT_POINT=/mnt/cf

if [ ! -d $MOUNT_POINT ]; then
	echo 

case $1 in
	mount)
		# The next three lines are to let MicroDrives spin up 
		modprobe usb-storage
		rmmod usb-storage
		sleep 1
		modprobe usb-storage
		mount -t vfat /dev/sda1 $MOUNT_POINT
		;;
	umount)
		sync
		sync
		umount $MOUNT_POINT
		rmmod usb-storage
		;;
	*)
		echo Usage: $0 [mount|umount]
		;;
esac