Mailing List Archive


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

[tlug] Re: Crazy automount solution



Hi all,

maybe some of you are interested in this automount-Solution using
udev and autofs, which will create storage$n and
$volumelabel-Symlinks in /dev/usb.
The autofs part will then look for $somename in /dev/usb, if you
access /usb/$somename.

So you can use the volume label as a persistent device name (even if
you don't want the automounting part). :-)

udev-Rule:
BUS="usb", SYSFS{bDeviceClass}="00", PROGRAM="/etc/udev/scripts/usbstorage.sh", SYMLINK="usb/%c{1} usb/%c{2}"

---- usbstorage.sh ----
#!/bin/bash

if [ `/sbin/udev_volume_id | grep "^F" ` != "F:filesystem" ]; then
	exit 0
fi

n=1
while [ $n -lt 10 -a -e /dev/usb/storage$n ]; do
	let "n+=1"
done
if [ ! -e /dev/usb/storage$n ]; then
	echo -n "storage$n "
fi

/sbin/udev_volume_id -l
---- end of usbstorage.sh ----

---- /etc/auto.usb ----
#!/bin/sh

key="$1"
opts="-fstype=autofshack,utf8"
dev="/dev/usb/$1"

if [ -r "$dev" -a ! -d "$dev" ]; then
	echo -n "$opts / auto:$dev"
fi
---- end of /etc/auto.usb ----

---- /etc/auto.master ----
# $Id: auto.master,v 1.3 2003/09/29 08:22:35 raven Exp $
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#/misc	/etc/auto.misc --timeout=60
#/misc	/etc/auto.misc
/nfs	/etc/auto.net --timeout=5
/smb	/etc/auto.smb --timeout=5
/usb	/etc/auto.usb --timeout=5
---- end of /etc/auto.master ----

---- /sbin/mount.autofshack ----
#!/bin/bash
#
# Work around autofs-borkage
#
#  mount -t autofshack realtype:/device /mountpoint
#  gets mangled to
#  mount -t realtype /device /mountpoint
#

index=1
args=""
realtype=""

for arg in "$@"; do
	if [ "`echo -n "$arg" | sed -e 's@[^:]*:/.*@example.com@'`" = "__magic__" ]; then
		realtype=`echo -n "$arg" | sed -e 's@example.com([^:]*\):\(.*\)@example.com@'`
		dev=`echo -n "$arg" | sed -e 's@example.com([^:]*\):\(.*\)@example.com@'`
		args="$args \"$dev\""
	else
		if [ "$arg" = "autofshack" ]; then
			args="$args \"\$$realtype\""
		else
			args="$args \"\$$index\""
		fi
	fi
	let "index+=1"
done

eval "exec /bin/mount $args"
---- end of /sbin/mount.autofshack ----

-- 
Tobias						PGP: http://9ac7e0bc.uguu.de


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links