hotplug usb-storage experience

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I just spent several hours trying to get hotplug to mount/umount my usb-storage camera when it is plugged/unplugged from the system.

At first, I was just adding an entry in my /etc/fstab file for the camera so that I could mount and umount it using the "Disks" menu in Gnome but much to my confusion the entry kept mysteriously disappearing. I eventually discovered that whenever I unplugged the camera, hotplug was calling updfstab which was removing the entry that I had put in /etc/fstab. The problem was that updfstab was not putting the entry back when the camera was plugged in. Eventually, I figured out that if I changed the entry in /etc/updfstab.conf.default from...

device camera {
   partition 1
   match   hd DSC
   match   hd CAMERA
}

to...

device camera {
   partition 1
   match   hd DSC
   match   hd CAMERA
   match   hd OLYMPUS
}

updfstab would now add an entry to /etc/fstab when I plugged in the camera (It's an Olympus camera). So now I had /etc/fstab being updated whenever the camera was added or removed but it was not being mounted/umounted so I decided to do some more hotplug research.

After some reading, I was lead to believe that a script at /etc/hotplug/usb/usb-storage would be executed when the camera was added. This didn't work at first so I scoured the man pages of hotplug for clues. Eventually, through dumb luck and trial and error, I ended up copying all the entries in /lib/modules/2.4.22-1.2149.nptl/modules.usbmap that started with "usb-storage" into /etc/hotplug/usb.usermap. After, I did this, the /etc/hotplug/usb/usb-storage script was being executed when I plugged in the camera. The script just did a 'mount /mnt/camera'.

The only problem now was that the camera did not get unmounted when it was unplugged and, in fact, only root could umount it which was inconvenient. So, feeling like I was on a roll, I kept digging. It turns outs that hotplug sets a variable called $REMOVER which you can access in the hotplug script ( /etc/hotplug/usb/usb-storage) which is the path of the script that will be executed when the device is unplugged. The value of $REMOVER always ended up being /var/run/usb/{cryptic_string}. So, I modified my script to actually write a removal script to that path which would umount the camera. In the end the script at /etc/hotplug/usb/usb-storage looked like this...

#!/bin/bash
mount /mnt/camera
echo '#!/bin/bash' > "$REMOVER"
echo 'umount /mnt/camera' >> "$REMOVER"
chmod u+x $REMOVER

Unfortunately, the /var/run/usb directory did not already exist so I had to create it first.

In the end, it works perfectly. I plug in the camera and it gets mounted and a little icon shows up on my desktop. When I unplug it, it gets umounted and the icon disappears - very nice.

What I'd like to know is, why did I have to copy all those entries from /lib/modules/2.4.22-1.2149.nptl/modules.usbmap that started with "usb-storage" into /etc/hotplug/usb.usermap? I don't really know enough about what these entries are but it seems like I shouldn't have had to manually copy these cryptic entries to get hotplug to work with my usb-storage device. Can anyone offer any insights?

It also would have been nice if /var/run/usb storage had already existed. Should this directory be created during Fedora Core install?

-Jason




[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux