Re: handling removable media without gnome-volume-manager
On Fri, Mar 26, 2010 at 09:46:05PM -0700, briand@aracnet.com wrote:
> Hi all,
>
> I'd like something where I can encode the behavior for particular
> devices, i.e. as I'm using the same devices over and over I'd like a
> way to make sure that the same device gets mapped to the same thing.
>
> Not needing X to be up and running is nice too.
I use automount with a udev-fired script which generates automount
maps based upon the usb (or firewire) device's label.
For instance, my backup drive is labeled rsnapshot_backup. When I plug
it in, an automount map is created for /media/auto/rsnapshot_backup/.
When unplugged, the map and mount directory is removed.
My script still has some rough edges, It contains a fair amount of
crockery to deal with devices which generate multiple add events, such
as my ipod.
It's fairly short so I'll attach a copy to this posting.
HTH
dt
--
Dave Thayer | Whenever you read a good book, it's like the
Denver, Colorado USA | author is right there, in the room talking to
dave@thayer-boyle.com | you, which is why I don't like to read
| good books. - Jack Handey "Deep Thoughts"
# use -*- SH -*- mode to turn off wordwrap in jed
SUBSYSTEMS=="usb|firewire",ENV{ID_FS_USAGE}=="filesystem", RUN+="/usr/local/bin/removable_drive_handler"
#! /bin/bash
#vfat_mount_options="-fstype=auto,quiet,sync,nodev,nosuid,gid=floppy,dmask=002,fmask=113,shortname=mixed,iocharset=iso8859-1"
#sync option sends ipod performance down the toilet... Need to test for ipod and keep other devicess sync?
vfat_mount_options="-fstype=auto,quiet,nodev,nosuid,gid=floppy,dmask=002,fmask=113,shortname=mixed,iocharset=iso8859-1"
unix_mount_options="-fstype=auto,sync,nodev,nosuid"
map_file="/etc/auto.removable"
default_mountpoint_name="removable_drive"
autofs_mount_dir="/media/auto"
autofs_pid_file="/var/run/autofs/_media_auto.pid"
# Uncomment logger commands for debugging
#env | logger -t "Autoplug[$$]"
test "$ID_FS_USAGE" = "filesystem" || exit 0
logger -t "Autoplug[$$]" "Proceeding with $ACTION"
# Clean out map file removing non-existant devices and previous names for this one
echo \#Editing is futile, automatically generated at $(date) > $map_file.new
while read key options location
do
if [ "$location" != ":$DEVNAME" ]
then
if [ -e "${location##:}" ] #Remove colon to look for node
then
echo $key $options $location >> $map_file.new
fi
else
mountpoint="$key"
fi
done < $map_file
sort -u $map_file.new > $map_file #remove duplicate entries
rm $map_file.new
if [ "$ACTION" = "add" -o "$ACTION" = "change" ]
then
# Figure out name for mountpoint
if [ -n "$ID_FS_LABEL_ENC" ] #Another name for volume label?
then
mountpoint="$ID_FS_LABEL_ENC"
elif [ -n "$ID_MODEL" ] #Next try device model name
then
mountpoint="$ID_MODEL"
elif [ -n "$ID_FS_UUID_ENC" ] #Then try device UUID
then
mountpoint="$ID_FS_UUID_ENC"
else #Finally, use a default
mountpoint="$default_mountpoint_name"
fi
# If there's already a mountpoint with this name, try name.1, name.2 ...
if grep -q "^$mountpoint -" $map_file
then
n=1
while grep -q "^$mountpoint.$n -" $map_file
do
let "n += 1"
done
mountpoint=$mountpoint.$n
fi
# Add map for device using FS appropriate options
if [ "$ID_FS_TYPE" = "vfat" ]
then
echo "$mountpoint" $vfat_mount_options :$DEVNAME >> $map_file
else
echo "$mountpoint" $unix_mount_options :$DEVNAME >> $map_file
fi
fi
# If kill doesn't work, use initscript
kill -HUP $(cat $autofs_pid_file) || /etc/init.d/autofs reload
# Remove spurious (I'm looking at you, ipod) mountpoints by testing for valid fs
(sleep 3 ; "$autofs_mount_dir/$mountpoint/.")&
logger -t "Autoplug[$$]" "Performing $ACTION for $DEVNAME"\
"${mountpoint+on} $mountpoint"
Reply to: