# automatically mount right card when inserted into Cardreader

## ennservogt

Hi, I have the following problem. I have set up a dedicated linux server and would like to use my Multicard USB Cardreader with it. The Cardreader has four slots and can read 8 different card formats (CF, SD, ...). Everything is working fine, except that I manually have to mount the right slot of the Multicard Cardreader each time I insert a Compact Flash or SD Card for instance. 

To show you my situation I have attached the ouput of "sg_scan -i" and "sg_map". 

netslave:/# sg_scan -i

/dev/sg0: scsi0 channel=0 id=0 lun=0 [em]  type=0

    SMSC      223 U HS-CF  1.95 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0] 

/dev/sg1: scsi0 channel=0 id=0 lun=1 [em]  type=0

    SMSC      223 U HS-MS  1.95 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0] 

/dev/sg2: scsi0 channel=0 id=0 lun=2 [em]  type=0

    SMSC      223 U HS-SM  1.95 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0] 

/dev/sg3: scsi0 channel=0 id=0 lun=3 [em]  type=0

    SMSC      223 U HS-SD/MMC  1.95 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0] 

netslave:/# 

AND

netslave:/# sg_map 

/dev/sg0  /dev/sda

/dev/sg1  /dev/sdb

/dev/sg2  /dev/sdc

/dev/sg3  /dev/sdd

netslave:/# 

That's a pain in the ass, because some of my family members also have to use this Cardreader.  

So here is my question. Is it possible that each time I insert a Comact Flash or SD card into one of the slots of the card reader, the right slot with the card in it gets automatically mounted. And when the card is removed, the right slot should be automatically unmounted of course.

Greet,

EnnserVogt

----------

## hds

i second this question <g>. i have an USB reader as well, just for Sony Memorystick, though..

IIRC the automount should work with "hotplug", but sofar i didnt get this to work either.   :Mad: 

----------

## PowerFactor

Yeah, you should be able to make hotplug automatically mount the right card if the reader generates any sort of notification that a card has been inserted, many don't.  But I don't think there is any way you could make it automatically unmount them.  The card needs to be unmounted before you remove it and there is no way for the computer to anticipate that you are about to yank the card out.

I'd either use mtools to access the cards or look into setting up submount.

----------

## ennservogt

What sort of notification should the cardreader produce if a card is inserted into it? I have only noticed some messages coming from the kernel when I completely pluged the Cardreader in and out of the USB port.

----------

## hds

if i plugin my memorystick i get this:

```

Sep  4 17:55:04 hds usb 1-1.1: new full speed USB device using address 4

Sep  4 17:55:04 hds scsi1 : SCSI emulation for USB Mass Storage devices

Sep  4 17:55:04 hds Vendor: Sony      Model: MSAC-US1          Rev: 1.00

Sep  4 17:55:04 hds Type:   Direct-Access                      ANSI SCSI revision: 02

Sep  4 17:55:04 hds SCSI device sdc: 126848 512-byte hdwr sectors (65 MB)

Sep  4 17:55:04 hds sdc: assuming Write Enabled

Sep  4 17:55:04 hds sdc: assuming drive cache: write through

Sep  4 17:55:04 hds /dev/scsi/host1/bus0/target0/lun0: p1

Sep  4 17:55:04 hds Attached scsi removable disk sdc at scsi1, channel 0, id 0, lun 0

Sep  4 17:55:04 hds Attached scsi generic sg4 at scsi1, channel 0, id 0, lun 0,  type 0

Sep  4 17:55:04 hds USB Mass Storage device found at 4

Sep  4 17:55:04 hds scsi.agent[2382]: disk at /devices/pci0000:00/0000:00:07.2/usb1/1-1/1-1.1/1-1.1:1.0/host1/1:0:0

:0

```

and if i plug it out:

```

Sep  4 17:56:47 hds usb 1-1.1: USB disconnect, address 4

```

----------

## PowerFactor

 *ennservogt wrote:*   

> What sort of notification should the cardreader produce if a card is inserted into it? I have only noticed some messages coming from the kernel when I completely pluged the Cardreader in and out of the USB port.

 If the reader produces any notification you should see something in dmesg at least.

EDIT: What package is that sg_scan program from?

          (nm I found it, sg3_utils)Last edited by PowerFactor on Sat Sep 04, 2004 4:24 pm; edited 1 time in total

----------

## hds

IMHO "sg" is used, if you compile generic scsi support into the kernel. the devices are then called /dev/sg..

btw: any hints how i could get hotplug to work now? it looks like my cardreader tells the OS both, if card is inserted and ejected.

----------

## ennservogt

@hds: well, then you are a lucky guy  :Wink:  you just have to deal with the "usb.agent" file in the /etc/hotplug direcory. Do you need any further hints?

----------

## hds

 *ennservogt wrote:*   

> @hds: well, then you are a lucky guy  you just have to deal with the "usb.agent" file in the /etc/hotplug direcory. Do you need any further hints?

 

yes please. i didnt deal with hotplug sofar - if you have an example it would be nice.

----------

## ennservogt

You can tell hotplug to execute a script if a specific USB device is getting connectied or disconnected to the PC. Take a look at the usb.agent file in the /etc/hotplug directory. There you have to specify the Vendor and Product ID of your USB device and tell the usb agent which script to execute if this device gets connected to the PC.

----------

## hds

sure i have to modify "usb.agent"   :Shocked: 

i still dont understand how i would have to add my device there   :Shocked:   :Shocked: 

----------

## Nate_S

Look into UDEV + DBUS + HAL + IVMAN

UDEV, when set up properly, should be able to distinguish your slots on the card reader (not all multi-card readers support this due to the hardware, but since yours seems to show up on multiple luns, it should work)

DBUS and HAL are what let IVMAN work, it will take care of the mounting and umounting.  

-Nate

----------

## teutzz

ivman, for now at least, can only handle cds and dvds. so maybe gnome-volume-manager is the way to go (ebuild on bmg)

----------

## PowerFactor

Submount is about the only thing available right now the will handle flash cards and usb drives fully tranparently on a system wide level. IMO it's the only one of the currently available automounting options that is safe to use with non-lockable removable media(i.e. floppuies, usb drives and card readers).  It works in a manner similar to mtools but at the vfs layer so it looks like a normal mount.

If you use kde you can setup mtools to access your cardreader then access them from any kde app through kio_floppy.

In either case setting up udev to give each usb device a consistent name every time it is plugged in can help a lot.

----------

