[long] Re: [clug] USB memory sticks

Alex Satrapa grail at goldweb.com.au
Sat Nov 22 20:01:47 EST 2003


On 3 Nov 2003, at 22:48, Jan Newmarch wrote:

> I am in China, with lots of students expressing surprise that they 
> just can't push their memory sticks into my USB port and have it 
> available to copy my files. They show up in lsusb but I don't know 
> what device they are or how to handle them.

Short Version

  - set up entries in /etc/usbmgr/usbmgr.conf for USB key models that the
    usbmgr doesn't know about already (vendor/model codes are reported in
    dmesg and syslog)
  - using devfs, devices show as /dev/scsi/hostX/bus0/target0/lun0/part1,
    where it appears that the X in hostX is the first available, starting
    at 1.
  - in fstab, make sure devices have "sync" and "noatime" options (one 
for
    data security, other for device longevity)
  - automount using usbmgr "script" parameter for that device

Long Version

On my machine using devfs, the USB CF reader shows up as 
/dev/scsi/host1/bus0/target0/lun0/part1. Another machine (at work) 
shows the USB CF reader as /dev/sda (sda1?). I'm not aware what the 
loading order is - whichever USB socket I plug the CF reader into, the 
kernel seems to allocate the same device. My guess at this stage is 
that the order of plugging devices in is what determines what device 
name each USB device is given. When I plug the CF reader in, then 
connect the digital camera, the camera's CF card appears under 
/dev/scsi/host2/...  FWIW, the camera appears as a card reader/writer 
under Linux and Mac OS X.

In /etc/fstab, I define:
/dev/scsi/host1/bus0/target0/lun0/part1 /tanya/CF-Card  auto    
rw,user,noauto,sync,umask=0077,noatime                    0       0

The sync option is essential because a USB key (or CF reader, or 
digital camera) could be unplugged at any time. The 'user' option 
allows anyone using the machine could mount the device. Use noatime to 
preserve the life of the flash memory. Note that by putting an entry in 
fstab, I'm limiting myself to always inserting the CF reader first (or 
only).

I have usbmgr installed (you might want to consider murusaki 
http://www.dotaster.com/~shuu/linux/murasaki/), with a few lines like 
this:
# Simple Technology FlashLink UCS-100 CF/SM Reader
vendor 0x4e6 product 0x0005 module scsi_mod, sd_mod, usb-storage
# Coolpix 885 [Nikon]
vendor 0x04b0 product 0x0105 script nikon-coolpix module scsi_mod , 
sd_mod , usb-storage

Note that the /etc/usbmgr/nikon-coolpix script isn't told about what 
device was just added to the system! I think I'll have to try and 
coordinate actions between devfsd and usbmgr to be able to 
automatically mount the Nikon *and* the CF reader at the same time.

Things get messy when the USB device is unplugged, since the file 
system is still mounted - I try to minimise file system damage by using 
the "sync" option at mount time. All that you can do in the usbmgr 
script is "umount -f ..." to force the unmount (this is just to 
convince the OS that the device no longer exists). You could, of 
course, "sync" and "umount" the device manually. I have to admit to 
laziness myself - I find it tedious to have to unmount a device before 
pulling the plug out. Or rather, I find it tedious to have to manually 
unmount a device which I then have to manually disconnect from the 
system. At least with CDs and ZIP disks, when I say "eject", the file 
system is unmounted and the disk is physically removed from the PC :)  
Though the springs on the ZIP are wearing out, and it's not quite 
ejecting media across the room anymore.

I use the msdos filesystem on these devices, since I access them from 
the Nikon coolpix camera (which gives me no options), my iMac (running 
Mac OS X), and my PC (which is dual-boot Windows 98 & Debian GNU/Linux 
3.0). AFAIK, you can't partition a CF card - otherwise I'd be able to 
(for example) have an msdos filesystem for the camera, and an encrypted 
filesystem for my deepest darkest secrets   (though what they're doing 
on a CF card is beyond the realms of this hypothetical example).

FWIW, the digital camera files are stored under a folder 
/dcim/100nikon/, my files are under /alex/..., so my SSH and GPG keys 
happily cohabit on the file system with the pictures that my camera is 
taking. I just have to remember not to format the CF card in the camera 
before copying important data off the card first ;)  I can't have the 
camera connected via USB *and* take pictures, so there are no problems 
with simultaneous access to the file system.




More information about the linux mailing list