# Digital camera woes - please help!

## psims

I have an Olympus D-520 Zoom digital camera.  I have two flash cards for it, a Smartmedia 128M one and the Olympus 32M one that came with it.  I understand that I should be able to plug the camera in via usb and have the flash cards recognized as a scsi device.  I installed the hotplug package.  I have usbcore and usb-ohci loaded as modules.  When I plug it in I get the following:

hub.c: USB new device connect on bus1/1, assigned device number 2

usb.c: USB device 2 (vend/prod 0x7b4/0x102) is not claimed by any active driver.

SCSI subsystem driver Revision: 1.00

Initializing USB Mass Storage driver...

usb.c: registered new driver usb-storage

scsi0 : SCSI emulation for USB Mass Storage devices

usbview shows the camera.  However I do not see a device node for it.  I have searched far and wide, I seem to have found some others who have had the same problem but no answers.  Can someone tell me what's going on here, and just what is the purpose for the hotplugging package, is it just to run scripts when devices are detected like mounting the device?

If anyone can help I would really appreciate it.

Thanks,

psims

----------

## pilla

Are you sure your camera is supported? I have a Vivitar USB but I cannot access it under Linux. Make some searchs in the forums and also Google just to be sure somebody else hasn't done it yet...

You can make some research from [url]gphoto.sourceforge.net[/url]. My 2 cents.

 *psims wrote:*   

> I have an Olympus D-520 Zoom digital camera.  I have two flash cards for it, a Smartmedia 128M one and the Olympus 32M one that came with it.  I understand that I should be able to plug the camera in via usb and have the flash cards recognized as a scsi device.  I installed the hotplug package.  I have usbcore and usb-ohci loaded as modules.  When I plug it in I get the following:
> 
> hub.c: USB new device connect on bus1/1, assigned device number 2
> 
> usb.c: USB device 2 (vend/prod 0x7b4/0x102) is not claimed by any active driver.
> ...

 Last edited by pilla on Tue Sep 17, 2002 2:47 am; edited 1 time in total

----------

## psims

I was afraid this might be the problem, but according to Lycoris' hardware compatibility list the 510 is supported:

Certification: No  

Product Name: Olympus D-510 Zoom  

Manufacturer:  Lycoris  

Model: None  

Revision/Chipset:  None  

Category: Imaging Hardware  

Compatability:  100%  

Product URL:  

Driver URL:  

Description: This USB caerma works like a mass storage device. When you plug it in, it is available as a SCSI device. You can mount that and copy/delete/write to it. 

Notes: None 

I didn't think there should be much difference between the 510 and the 520.  Also, the ZDNet linux hardware database appears to list it as supported:  

http://lhd.datapower.com/db/dispproduct.php3?DISP?3220#resources

Do you know what would not be supported, the SmartMedia card, the usb mechanism?

----------

## Kabuto

That model acts like a SCSI drive.  So you should just be able to mount the SCSI srX device like a regular drive.

----------

## psims

When I load the ide-scsi module I get the sr (sr0 and sr1) devices for the two cdrom drives, but when I insert usb-storage a device never appears.

----------

## SNo0py

 *Kabuto wrote:*   

> That model acts like a SCSI drive.  So you should just be able to mount the SCSI srX device like a regular drive.

 

I'm having an Fuji Finepix which acts also as an SCSI-Device. I can manually mount and unmount it without problems, but I want to automount the /dev/sda0 when connecting the Cam to the bus -> how does this work?

----------

## yannick

Hi,

it is really simple (though I spent a night to find how to use all the functionnality of hotplug) :

Install hotplug and create a new file /etc/hotplug/usb/usb-storage with this in it :

```

#!/bin/bash

if [ "$PRODUCT" = "4cb/100/1000" ]; then

        mount /dev/sda1 -t vfat -o umask=000 /mnt/fuji

        echo "#!/bin/bash" > $REMOVER

        echo "umount /mnt/fuji" >> $REMOVER

        chmod a+x $REMOVER

fi

```

Then chmod a+x /etc/hotplug/usb/usb-storage and that's all !

Edit: If it doesn't exist, create the directory /var/run/usb/, cause that's where $REMOVER will be created.

This file is called just after the module usb-storage is loaded, it mounts the camera file system then fills another file which will be called when the camera is disconnected and will unmount the camera.

If you want to modify this script, check /etc/hotplug/usb.agent to see what information is available (like $PRODUCT, $REMOVER, ...) to the script.

The product number in this script is the one of the Fujifilm FinePix 1400Zoom and it works perfectly with my Fujifilm FinePix 6800Zoom. It's magic.

Hope it helps,

YannickLast edited by yannick on Mon Nov 18, 2002 3:01 pm; edited 1 time in total

----------

## /

 *psims wrote:*   

> When I load the ide-scsi module I get the sr (sr0 and sr1) devices for the two cdrom drives, but when I insert usb-storage a device never appears.

 

Are you sure no devices along the line /dev/sda1 are created?

(might also be sdb1 )

----------

## psims

No, nothing in /dev/sd*

I have sr0 and sr1 for the two cdrom drivers.

I can see the camera in /proc/bus/usb/devices

When I modprobe usb-storage I get:

Initializing USB Mass Storage driver...

usb.c: registered new driver usb-storage

scsi1 : SCSI emulation for USB Mass Storage devices

scsi: device set offline - not ready or command retry failed after bus reset: host 1 channel 0 id 0 lun 0

WARNING: USB Mass Storage data integrity not assured

USB Mass Storage device found at 2

USB Mass Storage support registered.

The camera also shows up in /proc/scsi/usb-storage-0/1.

It does not show up as an attached device in /proc/scsi/scsi.

I included Microtech and Sandisk smartmedia support in the kernel.

No /dev/sd anything.

----------

## rommel

couple of things...i have a olympus d-450 , and use the sandisk to read the smartmedia.

but anyway did you create a  mount point and device entry in fstab for your camera

/dev/sda1         /mnt/flash     vfat         noauto,users,ro    0 0

if you did then what is the erro messge when you try to mount /mnt/flash or what ever you called it?

also try comiling the usb-storage intot he kernel instead of a module and boot the system with the camera on? and plugged into a usb port.

----------

## psims

When I try to mount it, I get:

mount: special device /dev/sda1 does not exist

I get the same with usb-storage compiled into the kernel.

Using devfs, my cdroms are mounted with /dev/cdroms/cdrom0

Where should the flash show up?

----------

## psims

I rebooted with usb-storage compiled in and the cameral plugged in.  Here is my dmesg from the initialization of teh scsi devices:

 SCSI subsystem driver Revision: 1.00

scsi0 : SCSI host adapter emulation for IDE ATAPI devices

  Vendor: TOSHIBA   Model: DVD-ROM SD-M1202  Rev: 1020

  Type:   CD-ROM                             ANSI SCSI revision: 02

  Vendor: IOMEGA    Model: ZIPCD1024INT-A    Rev:  1.8

  Type:   CD-ROM                             ANSI SCSI revision: 02

Attached scsi CD-ROM sr0 at scsi0, channel 0, id 0, lun 0

Attached scsi CD-ROM sr1 at scsi0, channel 0, id 1, lun 0

sr0: scsi3-mmc drive: 32x/32x cd/rw xa/form2 cdda tray

Uniform CD-ROM driver Revision: 3.12

sr1: scsi3-mmc drive: 32x/32x writer cd/rw xa/form2 cdda tray

Linux Kernel Card Services 3.1.22

  options:  [pci] [cardbus] [pm]

usb.c: registered new driver usbdevfs

usb.c: registered new driver hub

PCI: Found IRQ 9 for device 00:02.0

usb-ohci.c: USB OHCI at membase 0xd0830000, IRQ 9

usb-ohci.c: usb-00:02.0, Acer Laboratories Inc. [ALi] USB 1.1 Controller

usb.c: new USB bus registered, assigned bus number 1

hub.c: USB hub found

hub.c: 4 ports detected

PCI: Found IRQ 9 for device 00:06.0

usb-ohci.c: USB OHCI at membase 0xd0832000, IRQ 9

usb-ohci.c: usb-00:06.0, Acer Laboratories Inc. [ALi] USB 1.1 Controller (#2)

usb.c: new USB bus registered, assigned bus number 2

hub.c: USB hub found

hub.c: 2 ports detected

Initializing USB Mass Storage driver...

usb.c: registered new driver usb-storage

USB Mass Storage support registered.

pci_hotplug: PCI Hot Plug PCI Core version: 0.4

NET4: Linux TCP/IP 1.0 for NET4.0

IP Protocols: ICMP, UDP, TCP

IP: routing cache hash table of 2048 buckets, 16Kbytes

TCP: Hash tables configured (established 16384 bind 32768)

ip_conntrack version 2.1 (2047 buckets, 16376 max) - 304 bytes per conntrack

ip_tables: (C) 2000-2002 Netfilter core team

ipt_time loading

ipt_random match loaded

ipt_nth match loaded

NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.

ds: no socket drivers loaded!

reiserfs: checking transaction log (device 03:01) ...

Using r5 hash to sort names

ReiserFS version 3.6.25

VFS: Mounted root (reiserfs filesystem) readonly.

Mounted devfs on /dev

Freeing unused kernel memory: 92k freed

hub.c: USB new device connect on bus1/2, assigned device number 2

usb-storage: act_altsettting is 0

usb-storage: id_index calculated to be: 65

usb-storage: Array length appears to be: 67

usb-storage: USB Mass Storage device detected

usb-storage: Endpoints: In: 0xc1a5b714 Out: 0xc1a5b700 Int: 0x00000000 (Period 0)

usb-storage: New GUID 07b401020000000108112582

usb-storage: GetMaxLUN command result is 1, data is 0

usb-storage: Transport: Bulk

usb-storage: Protocol: Transparent SCSI

usb-storage: *** thread sleeping.

scsi1 : SCSI emulation for USB Mass Storage devices

usb-storage: queuecommand() called

usb-storage: *** thread awakened.

usb-storage: Command INQUIRY (6 bytes)

usb-storage: 12 00 00 00 ff 00 34 c1 0b 56 1b c0

usb-storage: Bulk command S 0x43425355 T 0x5 Trg 0 LUN 0 L 255 F 128 CL 6

usb-storage: Bulk command transfer result=0

usb-storage: usb_stor_transfer_partial(): xfer 255 bytes

usb-storage: usb_stor_bulk_msg() returned 0 xferred 36/255

usb-storage: Bulk data transfer result 0x1

usb-storage: Attempting to get CSW...

usb-storage: clearing endpoint halt for pipe 0xc0010280

usb-storage: usb_stor_clear_halt: result=0

usb-storage: Attempting to get CSW (2nd try)...

usb-storage: Bulk status result = 0

usb-storage: Bulk status Sig 0x55425355 T 0x5 R 219 Stat 0x0

usb-storage: Bulk logical error

usb-storage: -- transport indicates error, resetting

usb-storage: Bulk reset requested

Adding Swap: 273096k swap-space (priority -1)

reiserfs: checking transaction log (device 03:02) ...

usb-storage: command_abort() called

usb-storage: -- nothing to abort

usb-storage: device_reset() called

usb-storage: Bulk reset requested

usb-storage: usb_stor_clear_halt: result=0

usb-storage: usb_stor_clear_halt: result=0

usb-storage: Bulk soft reset completed

usb-storage: scsi cmd done, result=0x70000

usb-storage: *** thread sleeping.

Using r5 hash to sort names

ReiserFS version 3.6.25

reiserfs: checking transaction log (device 03:03) ...

Using r5 hash to sort names

ReiserFS version 3.6.25

usb-storage: usb_stor_clear_halt: result=0

usb-storage: usb_stor_clear_halt: result=0

usb-storage: Bulk soft reset completed

usb-storage: queuecommand() called

usb-storage: *** thread awakened.

usb-storage: Command TEST_UNIT_READY (6 bytes)

usb-storage: 00 00 00 00 00 00 34 c1 0b 56 1b c0

usb-storage: Bulk command S 0x43425355 T 0x5 Trg 0 LUN 0 L 0 F 0 CL 6

usb-storage: Bulk command transfer result=0

usb-storage: Attempting to get CSW...

usb-storage: Bulk status result = 0

usb-storage: Bulk status Sig 0x55425355 T 0x5 R 0 Stat 0x1

usb-storage: Bulk logical error

usb-storage: -- transport indicates error, resetting

usb-storage: Bulk reset requested

eth1: Setting 10mbps half-duplex based on auto-negotiated partner ability 4021.

eth2: Setting half-duplex based on auto-negotiated partner ability 0000.

usb-storage: usb_stor_clear_halt: result=0

usb-storage: usb_stor_clear_halt: result=0

usb-storage: Bulk soft reset completed

usb-storage: scsi cmd done, result=0x70000

usb-storage: *** thread sleeping.

usb-storage: bus_reset() called

resize_dma_pool: unknown device type -1

----------

## rommel

well the dmesg out put for mine with the sandisk plugged in at boot looks like this

```
scsi3 : SCSI emulation for USB Mass Storage devices

  Vendor: Sandisk   Model: ImageMate SDDR-0  Rev: 0208

  Type:   Direct-Access                      ANSI SCSI revisio

n: 02

Attached scsi removable disk sde at scsi3, channel 0, id 0, lu

n 0

SCSI device sde: 32768 512-byte hdwr sectors (17 MB)

sde: Write Protect is on

 /dev/scsi/host3/bus0/target0/lun0: p1

WARNING: USB Mass Storage data integrity not assured

USB Mass Storage device found at 2

hub.c: USB new device connect on bus3/2, assigned device numbe

r 3

```

thats about the extent of the output when my system boots for the usb-storage....earlier in the dmesg it loads the storage driver but the output is minimal compared to yours....so like there is a conflict with the device in that it isnt supported or its an irq thing.

what kernel are you running? it might be worth trying another kernel and see if the output changes any.

and you ahve entered a mount point in /mnt and an entry in fstab for the device ? yes?

----------

## elzbal

I don't know if this helps, but I have an Olympus C-4000 (which i *love*). As it turns out, the C-4000 has a broken/limited USB storage driver for the camera's built-in USB. The Linux drivers simply cannot communicate with that device. I don't remember the exact error message, but I think the kernel tried to report a bad cable.

Anyway, I ended up getting a $20 (or was it $30?) SanDisk SmartMedia reader/writer. I have had no problems with the reader since. I just leave the reader on the computer at all times (using one of the rear USB ports). I also like the fact that I'm not using my camera's batteries when I view or download pictures.

I don't know how similar the C-4000 is to your camera. It's likely that you may be a bit better off than I, since Lycoris claims compatability. However, at some point you may want to consider a dedicated SmartMedia reader device (SanDisk recommended).

----------

## SNo0py

 *yannick wrote:*   

> 
> 
> ```
> 
> #!/bin/bash
> ...

 

Hi!

Your script is working fine for mounting the cam. The remover-script is also created but not executed (because the usb-storage-driver stays in memory) so I'm switching off the cam and the device is mounted until the next reboot  :Sad: 

Any suggestions?

Thanks,

SNo0py

----------

## SNo0py

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg....

Two weeks of hacking, searching, trying... and then THIS solution   :Embarassed: 

```
mkdir /var/run/usb
```

*hmpf*

----------

## Craigo

Wow, I cannot believe those people are running into problems, make me feel really bad and I should have posted my ways. Better late than never  :Sad: 

I've got the Fuji 2600Zoom USB cam and basically I selected in the kernel:

SCSI:

* SCSI support

* SCSI disk support

* SCSI generic support

USB:

* Support for USB

* Preliminary USB device filesystem

* USB Mass Storage support

Filesystem:

* /dev file system support

* Automatically mount at boot

All my hardware was reconsiged straightaway (I could have show you more modules to select but do I really want to?  :Wink: 

Mounting the cam was easy by putting:

/dev/sda1               /mnt/film       auto            defaults,user

in /etc/fstab.

Then I'm too lazy to test it out so a quick gkrellm setup to see this. Plug in the USB cable in, switch the camera on and mount. Pulling the pictures from the cam can range from using rox, mc etc etc

-/Craigo/-

----------

## striscio

 *SNo0py wrote:*   

> 
> 
> I'm having an Fuji Finepix which acts also as an SCSI-Device. I can manually mount and unmount it without problems, but I want to automount the /dev/sda0 when connecting the Cam to the bus -> how does this work?

 

Which model of finepix do you have?

I have a f401, but I can't get it working....

----------

## SNo0py

I'm having an 1400Zoom which acts as an Mass-Storage-Device... your's too? Can you mount it "by hand"?

----------

## striscio

 *SNo0py wrote:*   

> I'm having an 1400Zoom which acts as an Mass-Storage-Device... your's too? Can you mount it "by hand"?

 

It seems I have problems mount usb filesystem (do not have a /proc/bus/usb mount point nor I can create one).

Anyway I had good news abuot my camera under linux. It's only a matter of time (and trying...).

Thanks,

	gianpaolo

----------

## SNo0py

No, the usb-mass-storage-device acts as an SCSI-Device so you have to enable SCSI within your kernel. Afterwards you should be able to mount /dev/sdXX!

----------

## striscio

 *SNo0py wrote:*   

> No, the usb-mass-storage-device acts as an SCSI-Device so you have to enable SCSI within your kernel. Afterwards you should be able to mount /dev/sdXX!

 

Found some hints on the forum...

better having compiled usb stuff as module...

now I'm recompiling.

----------

## yannick

 *Quote:*   

> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg....
> 
> Two weeks of hacking, searching, trying... and then THIS solution 
> 
> ```
> ...

 

I'm happy that it's working finally !

I think I had the same problem but I had forgotten it, sorry  :Smile: .

YannickLast edited by yannick on Mon Nov 18, 2002 5:42 pm; edited 1 time in total

----------

## Larde

Now that was a fine thread. I was searching how to automount with hotplug, and the script works perfectly. Thanks for that solution!

Btw, the $PRODUCT for Sony DSC-P51 is "54c/10/410"  :Smile: 

Larde.

----------

## SNo0py

 *yannick wrote:*   

> 
> 
> I think I had the same problem but I had forgot it, sorry .
> 
> Yannick

 

no problem...  :Wink: 

----------

## anil_et

Hi,

I was following the discussion above,may be bit off topic, can someone suggest me a good digital camera (in the case of Linux support and performance) since I am planning to buy one.

How about  Nikon ?

Anil

Thailand

----------

## Larde

Hi,

while the suggestions in this thread and the automount script worked perfect at home, at my work computer I cannot get it set up correctly. hotplug does notice when I plug in/out the camera as in:

```
Nov 18 08:36:29 [kernel] hub.c: USB new device connect on bus1/1, assigned device number 2

Nov 18 08:36:29 [kernel] usb.c: USB device 2 (vend/prod 0x54c/0x10) is not claimed by any active driver.

[...]

Nov 18 08:37:03 [kernel] usb.c: USB disconnect on device 2
```

It doesn't load usb-storage though, it only loads uhci and usbcore modules. What is worse, /etc/hotplug/usb/usb-storage is not called (well, that's related I guess  :Wink: ), so no automount for me. I can modprobe usb-storage and mount the cam by hand.

Any tips?

Yours,

Larde.

P.S. can someone suggest me a good digital camera - I like the camera reviews at http://www.dcresource.com/reviews/cameraList.php

----------

## Craigo

anil_et,

I recommend either Fuji or Sony brands. They are the best cameras to use =)

-/Craigo/-

----------

## yannick

Larde:

Did you emerge hotplug ?

Yannick

----------

## Larde

Yes, I had hotplug. I just forgot General Setup->Support for hot-pluggable devices in my kernel.   :Embarassed:  Well, now it works as it should. Me happy.  :Wink: 

Yours,

Larde.

----------

## GaTeT

Hello! 

Yannick your script works 'almost' perfectly, but it doesn't unloads the usb-storage and sd_mod for me. I create the directory /var/run/usb, but the script only unmounts the camera. I modify the script to force the unload of modules and it goes like this:

```

#!/bin/bash

if [ "$PRODUCT" = "54c/10/410" ]; then

   mount /mnt/camara

   echo "#!/bin/bash" > $REMOVER

   echo "umount /mnt/camara" >> $REMOVER

   echo "rmmod usb-storage" >> $REMOVER

   echo "rmmod sd_mod" >> $REMOVER

   chmod a+x $REMOVER

fi

```

that's works perfectly for me. 

My question: could be any problem with this???

Another question. how to identify the ID of the camera??? ($PRODUCT)

I have a Sony DSC-P51 and I got the ID from this forum.

Thanks a lot!

Excuse my bad english :/

Best regards.

----------

## Regor

In my quick browse through this thread it didn't look like psims' original question got answered. The reason the Olympus doesn't work is because the device code they transmit to the computer is munged so the kernel doesn't recognize it as a usb-storage device. There is, of course, a patch available that hacks in a workaround. I just got a D520 and it now works perfectly.

Check out http://home.earthlink.net/~ebrombaugh/d150.html for

patches and tips on getting an Olympus D150, C220 or D520 to work.Last edited by Regor on Fri Dec 27, 2002 6:13 am; edited 1 time in total

----------

## yannick

 *GaTeT wrote:*   

> My question: could be any problem with this???
> 
> Another question. how to identify the ID of the camera??? ($PRODUCT)
> 
> I have a Sony DSC-P51 and I got the ID from this forum.
> ...

 

Thanks for the correction. I don't think it could cause any problem, if the module is in use, rmmod won't unload it (and if the module doesn't exist, rmmod will say it but not break your system  :Smile: ).

For your ID, you may look at the output of 'dmesg' or 'tail -10 /var/log/messages' just after connecting your camera, it should write the ID somewhere.

You may also replace the script by

```
#!/bin/bash

echo $PRODUCT > $REMOVER
```

 and look at the content of $REMOVER.

Yours,

Yannick

----------

## psims

Very happy you answered my post, I couldn't find anything after searching the net far and wide.  Now my camera works great.

Thanks again.

----------

## Tamnir

Thanks yannick and GaTeT, this hotplug script is just what I was looking for.

Some further improvements I came up with:

Consolidate mount info in /etc/fstab

Unload of scsi_mod

Lazy unmount

THe first change is just to put the mount information with the other

mounts info, in /etc/fstab. So in this script, we just call "mount /mnt/usb", or whatever you called your mount point. There may be reasons why you want this mount point info in the hotplug script, like if you have different USB storage devices, that for some reason you want to mount on the same mount point, but with different mount options... In any other case, it is probably better practice to put your mount data in /etc/fstab.

The second thing is simply unloading scsi_mod. We can safely do this since rmmod wouldn't unload it if it is still in use. No big deal, but since we are at unloading extra stuff, I guess we may as well.

The third change is the important one. The problem is when you yank out your USB device: if you happened to have files still in use, of more simply, if you had a process with a working directory on the USB device, then the umount command will fail, interrupting the remover script. As a result, usb-storage is not unloaded, so it will not be reloaded next time you plug in your device. Hence, the hotplug/usb/usb-storage script will not be called, and therefore, next time you plug it in, the device will not be automounted.

Luckily, umount is designed to handle such situations, with its "lazy unmount" option: -l. This lazy unmount will remove the mount on the spot, and will cleanup old references later, as they stop being busy.

The script now looks something like:

```

#!/bin/bash

if [ "$PRODUCT" = "_YOUR_USB_PRODUCT_ID_" ]; then

   mount /mnt/usb

   echo "#!/bin/bash" > $REMOVER

   echo "umount -l /mnt/usb" >> $REMOVER

   echo "rmmod usb-storage sd_mod scsi_mod" >> $REMOVER

   chmod a+x $REMOVER

fi

```

Cheers.

----------

## Jimboberella

This is great stuff Tamnir!

I am thinking it is going to be the solution to the problem I have, which is:

Device 1 is a 6 in 1 card reader

Device 2 is a USB drive stick

I want to mount each of the 4 slots of the 6-in-1 to named mount points eg /mnt/cf /mnt/sd /mnt/mmc /mnt/smc 

and also mount the usb stick as /mnt/usb

I assume that the script can be modified to add entries for each product code but I'm not sure of the syntax

```
#!/bin/bash 

if [ "$PRODUCT" = "_6in1_USB_PRODUCT_ID_" ]; then 

   mount /dev/sda1 -t auto -o umask=000 /mnt/cf 

   mount /dev/sdb1 -t auto -o umask=000 /mnt/mmc

   mount /dev/sdc1 -t auto -o umask=000 /mnt/smc

   mount /dev/sdd1 -t auto -o umask=000 /mnt/msc

   echo "#!/bin/bash" > $REMOVER 

   echo "umount -l /mnt/cf" >> $REMOVER 

   echo "umount -l /mnt/mmc" >> $REMOVER 

   echo "umount -l /mnt/smc" >> $REMOVER 

   echo "umount -l /mnt/msc" >> $REMOVER 

   echo "rmmod usb-storage sd_mod scsi_mod" >> $REMOVER 

   chmod a+x $REMOVER 

if [ "$PRODUCT" = "_stick_USB_PRODUCT_ID_" ]; then 

   mount /dev/sde1 -t auto -o umask=000 /mnt/usb

   echo "#!/bin/bash" > $REMOVER 

   echo "umount -l /mnt/usb" >> $REMOVER 

   echo "rmmod usb-storage sd_mod scsi_mod" >> $REMOVER 

   chmod a+x $REMOVER 

fi
```

The problem is that would require the devices to be pluged in in a specific order.

Is it possible to make the mount point eg /nmt/sdx felxible or to get it from dmesg at the time of plugging, so that I can plug them in in what ever order and still get the correct mount points assigned?

Would that be correct?

----------

## de4d

just another hint:

before adding

```

sleep 3 #maybe 1, 2

```

(above the mount cmd) to usb-stoage the mount didnt work for me for some reason.

im running 2.6mmtest5 (something) and im testing with sony F717 dsc

and something else:

what about plugging in a second DSC? this might be screwed by static fstab configuration.

more like /dev/sda1 mounts to /dev/f717 IF /dev/sda == f717 ...

or mount the 1st plugged to /mnt/dsc0 the next to /mnt/dsc1 (someone might plugin identical cams?)

any suggesttions?

ill try on my own for now

[edit]Jimboberella posted something quite similar/same - missed that some way :| [/edit]

[edit]not worth a new post but: anyone knows howto disable write buffering? after remove its a bit late to umount/flush buffer. didnt find appropriate option in `man mount`[/edit]

----------

## pazz

hi,

i have an usb-stick and whant to automount it..

but 

where do i get the $PRODUCT string?

i added the line

echo $PRODUCT > /productid

to your script but the file did not show up...

thanks 

pazz

----------

## lunatc

Hi!

I've made a script to automount a usb-storage device and hope It helps somebody with the usb-storage-type cameras. 

I've tested the script with 2 diferent usb-sticks and with a Ricoh Caplio RR-120 camera and it works.

BUT... 1st of all a WARNING

1.-The script modifies the fstab to allow users to safely umount the automounted device.

   So make sure this script fits on your system. USE IT AT YOUR OWN RISK.!!

2.-I've done with vfat-formatted devices in mind so modify it to suit your needs.

3.-It mounts the filesystem as owner root and with a "usbstorage" group, and with

   0770 permissions. Add users to the "usbstorage" group to allow users to access

   /umount the filesystem.

4.-Sorry for my english!  :Wink: 

Installing...

Modify /etc/hotplug/usb/usb-storage:

```

#!/bin/bash

# In my system I need this to refresh devfs when an usb-storage device

# is inserted. I don't know why I need to refresh devfs but it works!!

kill -HUP `pidof devfsd`

/usr/local/bin/usbstoragemount $REMOVER

MPOINT=$(cat $REMOVER | grep "#mounted: " | awk -F\  '{print $2}')

if [ ! -z "$MPOINT" ] ; then 

    # Do here whatever you like as open the path in konqueror and the like...

    echo $MPOINT

fi

```

Copy the script to /usr/local/bin (for example) as usbstoragemount:

```

#!/bin/bash

# usbstoragemount: A script to automount usb-storage devices

# lunatc at gentoo forums.

MOUNTOWNER=root

MOUNTGROUP=usbstorage

MYNAME="$(basename $0):"

MOUNTOK=0

REMSCRIPT="$1"

if [ ! $REMSCRIPT ] ; then 

   logger "$MYNAME Using fake remover. $MYNAME shoud be called with the remover path as the first arg."

   REMSCRIPT=/var/run/usb/fake-remover

fi

function GetDev() {

  DEVPATH=$(echo "$I $USBSTORDEV" | awk -F\  '{ printf "/dev/scsi/host%d/bus%d/target%d/lun%d\n",$0,$4,$6,$8  }')

  logger "$MYNAME DevPath: $DEVPATH"

  logger "$MYNAME DevName: $DEVNAME" 

}

function MountDevice() {

# Get mount point name based on the device name. 

# 1st sed:  Remove chars not in the a-z A-Z 0-9 range plus underscore and space chars

# 2nd sed:  Convert spaces to underscore: the {1,} converts two or more consecutive spaces

#           into one

# 3rd sed:  Remove underscores at the end

# 4th sed:  Remove underscores in the beginning

# After all a DEVNAME like "  Flash.  Disk " is converted into "Flash_Disk"

   MPOINT=/mnt/$(echo "${DEVNAME}" | sed -e "s/[^a-zA-Z0-9_ ]//g" -e "s/\ \{1,\}/_/g" -e "s/_$//g" -e "s/^_//g")

# if mount point does not exists

   if [ ! -d "$MPOINT" ] ; then

       logger "$MYNAME Making directory $MPOINT"

       mkdir "$MPOINT" > /dev/null

   else

   # reuse if not mounted

       if mount | grep "$MPOINT" > /dev/null ; then

           logger "$MYNAME $MPOINT exists and it is currently mounted."

           MPOINT="$MPOINT-$RANDOM"

           logger "$MYNAME Using $MPOINT instead"

           logger "$MYNAME Making directory $MPOINT"

           mkdir "$MPOINT" > /dev/null

       else

           logger "$MYNAME Reusing existing mount point $MPOINT"

       fi

   fi

   # Construct fstab entry...

   FSTABENTRY="$DEVPATH/part1 $MPOINT vfat noauto,users,uid=$MOUNTOWNER,gid=$MOUNTGROUP,sync,umask=007 0 0"

# ...and if not exists, add it at the end of fstab plus a comment (I use the remover path)...

# ...the comment serves as an identifier ...

# ...for allowing the remover script to locate the correct fstab entry 

   cat /etc/fstab | grep "$FSTABENTRY" > /dev/null || echo "$FSTABENTRY # $REMSCRIPT" >> /etc/fstab

# mount the device. If can't mount wait a second and retry.

  MOUNTOK=0

  if ! mount $MPOINT > /dev/null 2>&1 ; then

        logger "$MYNAME Cannot mount: retrying..."

        sleep 1 

        mount "$MPOINT" > /dev/null 2>&1 && MOUNTOK=1

  else

        logger "$MYNAME device mounted at $MPOINT"

        MOUNTOK=1

  fi

  [ "$MOUNTOK" = "0" ] logger "$MYNAME mount retry failed..."

   

}

function PrepareRemover() {

# Write the remover

# Inside the usbremover:

#  1.- remove old fstab.usbremover file

#  2.- umount device

#  3.- get a copy of the fstab WITHOUT (grep -v) the device entry. 

#      The correct entry gets identified by the "comment"

#  4.- Remove old fstab.old file

#  5.- Make a backup of the fstab (fstab.old)

#  6.- Make fstab.usbremover the new fstab

#  7.- Remove the mount point

# In the function: make the remover script executable.

  echo "#!/bin/bash" > $REMSCRIPT

  echo "rm -f /etc/fstab.usbremover" >> $REMSCRIPT

  echo "/bin/umount $MPOINT" >> $REMSCRIPT

  echo "/bin/cat /etc/fstab | /bin/grep -v \"$REMSCRIPT\" > /etc/fstab.usbremover"  >> $REMSCRIPT

  echo "test -f /etc/fstab.old && rm /etc/fstab.old" >> $REMSCRIPT

  echo "mv /etc/fstab /etc/fstab.old " >> $REMSCRIPT

  echo "mv /etc/fstab.usbremover /etc/fstab " >> $REMSCRIPT

  echo "rmdir $MPOINT" >> $REMSCRIPT

  test "$MOUNTOK" = "1" && echo "#mounted: $MPOINT" >> $REMSCRIPT

  chmod +x "$REMSCRIPT"

  logger "$MYNAME remover $REMSCRIPT created. $MOUNTOK." 

}

TESTMODE=0

# Usb-storage device inserted: look  for usb-storage dir entries in proc/scsi

for J in $(find /proc/scsi/ -name "usb-storage*") ; do

# For each dir entry check every file to get USB info:

# Example: when inserted the USB-device info can be located in /proc/scsi/usb-storage-0/3

#          it seems than that "3" file is the scsi host (scsi3 in this case)

# Look for every "host file"

for I in $(ls $J) ; do

  # Get info for the host 

  # I use DEVNAME to store the Product name, used later to set the mount point name

  DEVNAME=$(cat $J/$I | grep Product:| awk -F:\  '{print $2}' )

  ISATTACHED=$(cat $J/$I | grep Attached:| awk -F:\  '{print $2}' )

  if [ $TESTMODE = 1 ] ; then 

       logger "$MYNAME debug: Name: $DEVNAME"

       logger "$MYNAME debug: Attached.: $ISATTACHED"

       logger "$MYNAME debug: SCSI HOST: $SCSI$I"

       GetDev

       echo ""

  fi

  # If $ISATTACHED is "Yes" then maybe this is the usb device we are looking for

  if [ "$ISATTACHED" = "Yes" ] ; then 

       MODELMATCH=0

  # Try to see if the model in the scsi info 

  #    matches with the USB Name in the usb-storage info

       cat /proc/scsi/scsi | grep -A 3 "Host: scsi$I" | grep -i "Model: $DEVNAME" > /dev/null && MODELMATCH=1

       if [ $MODELMATCH = 0 ] ; then

          # this can happen. An usb device I own shows an empty model string

          logger "$MYNAME Warning: USB Name Not match with scsi info"  

       fi

       # Get the line that has the Channel, Id and Lun to locate the devfs path of the device

       USBSTORDEV=$(cat /proc/scsi/scsi | grep "Host: scsi$I")

       test "$TESTMODE" = "1" && logger "$MYNAME  debug: $USBSTORDEV"

       # Parse de info in the GetDev function. The host is known: "$I"

       GetDev

       MountDevice

       PrepareRemover 

  fi

done

done

```

Currently Running in 2 gentoo desktops and 1 laptop.

Hope this helps!

PS: Be carefull with copy and paste and the browser-wrapped long-lines on the script.

[EDIT]

 :Question:   I'm curious: 

  Has anybody gotten this script to work on their system?

  Corrections?

  What about kernel 2.6.X?

[/EDIT]

[Update]

https://forums.gentoo.org/viewtopic.php?t=53537&start=83

[/Update]Last edited by lunatc on Tue Nov 18, 2003 12:16 pm; edited 1 time in total

----------

## phooka

bleh.. nothing works on my system.. i used to have a /dev/sd* and could manually mount the my dsc-f717 after lots of fiddling.. but now i have 'upgraded' to r8 (from r5) it doesn't work anymore.. no /dev/sd*.   Where's my windows 2000 cd? hmm..

i think the linux folks need to kidnap some microsoft people, since they can seem to make any perph i have work.

can't believe i just said that.. i hate windows.

dale

----------

## jay

 *Larde wrote:*   

> Now that was a fine thread. I was searching how to automount with hotplug, and the script works perfectly. Thanks for that solution!
> 
> Btw, the $PRODUCT for Sony DSC-P51 is "54c/10/410" 
> 
> Larde.

 

How do I get $PRODUCT for a particular USB device, let's say for my CF card reader?

The linux hotplug page says:

idVendor/idProduct/bcdDevice, from device descriptor. Numbers are hexadecimal, without leading '0x' or zeros.

With usbview it is no problem to get the Vendor and the Product id. But what is bcdDevice???

----------

