View previous topic :: View next topic |
Author |
Message |
forna n00b
Joined: 13 Sep 2004 Posts: 14 Location: Dublin, Ireland
|
Posted: Wed Dec 29, 2004 10:12 pm Post subject: L'hotplug script non fa il mount della Flash memory |
|
|
Ciao a tutti,
ho provato a porre la stessa domanda nel Forum inglese ma non ho ricevuto alcuna risposta... così mi sono detto, proviamo con il forum italiano
Sto cercando di configurare uno script hotplug per fare il mount di una Flash memory USB automaticamente.
Ho scaricato e installato lo script:
[url]http://dev.gentoo.org/~wmertens/automount.hotplug [/url]
Code: | #!/bin/sh
#
# Automount hotplugged block devices, by Wout Mertens (wmertens@gentoo.org)
#
# Linux v2.6 version
# This script is released under version 2 of the GPL.
# To install this, either make it /sbin/hotplug, or, if you have
# linux-hotplug installed, make it /etc/hotplug.d/block/automount.hotplug .
# It needs to be executable. I tested it with busybox's ash.
#
# The devices will be mounted for the console user if applicable.
#
# To work, this needs:
# - v2.6 kernel support:
# - hotplugging, /proc mounted, /sys mounted
# - filesystems that will be mounted, like vfat
# - sh, echo, sed, stat or ls, getent or grep passwd,
# mount, umount, mkdir, rmdir. logger is used if there.
#
# Possible improvements:
# - Create a desktop entry for the device.
# - Call a notifier script when mounting/unmounting. This could create the
# desktop entry by itself.
# - Edit fstab instead, and give the "user" option. This depends more on
# the user/desktop knowing what he/it is doing.
# - Mount as supermount if available. This will improve behaviour for
# synchronous writes and hanging mounts, although umount -lf already
# does a good job. UPDATE: added, but untested. Let me know if it works.
# - Detect filesystem on device, so filesystems that don't need a mounting
# user can skip user detection.
# Debugging
# set -xv
# exec > /tmp/hotplug.$$ 2>&1
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
export PATH
# We only handle block device messages
[ "$1" != "block" ] && exit 0
# Proclaim stuff to the world
mesg () {
logger -t $0 "$*"
}
# Is path already mounted?
is_path_mounted () {
while read dev path rest
do
if [ "$path" = "$1" ]
then
return 0
fi
done < /proc/self/mounts
return 1
}
# Get mounted path for a device
get_mounted_path () {
while read dev path rest
do
if [ "$dev" = "$1" ]
then
echo "$path"
return 0
fi
done < /proc/self/mounts
return 1
}
# Wait for a file to appear
wait_for () {
local count=0
while [ $count -lt 10 ] && [ ! -e "$1" ]
do
sleep 1
done
[ $count -eq 10 ] && return 1
return 0
}
# Remove strange characters from a filename
clean_filename () {
# Note the lack of quotes around $1, this strips off spaces.
echo $1 | sed 's/[ /?*\"<>]/_/g'
}
# Figure out the device to mount
set `echo $DEVPATH | sed 's/\// /g'`
[ $# -ne 3 ] && exit 0
DEVICE=/dev/$3
if [ "$ACTION" = "remove" ]
then
# Is it ours?
dir=`get_mounted_path $DEVICE`
echo "$dir" | grep -q ^/mnt/usb || exit 0
# Unmount it
[ -d "$dir" ] || exit 1
umount -lf "$dir"
rmdir "$dir"
exit 1
fi
if [ "$ACTION" = "add" ]
then
# Is it a usb device? Exit if not.
ls -l /sys/$1/$2/device | sed 's/^.* -> //g' | grep -q usb || exit 0
# Mount it
# Make sure we have support for vfat
modprobe -q vfat
wait_for /sys/$1/$2/device/vendor || exit 1
# Find the name
PRODUCT=`cat /sys/$1/$2/device/model`
if [ -z "$PRODUCT" ]
then
PRODUCT=generic
fi
# Find out where we mount it
MOUNTPATH=/mnt/usb/`clean_filename "$PRODUCT"`
if is_path_mounted "$MOUNTPATH"
then
count=1
while is_path_mounted "${MOUNTPATH}_${count}"
do
count=$(( $count + 1 ))
done
MOUNTPATH="${MOUNTPATH}_${count}"
fi
# Make sure it's a directory
if [ -e "$MOUNTPATH" ]
then
if [ ! -d "$MOUNTPATH" ]
then
mesg "$MOUNTPATH exists but is not a directory"
exit 1
fi
else
mkdir -p "$MOUNTPATH"
if [ $? -ne 0 ]
then
mesg "Could not create mountpoint $MOUNTPATH"
exit 1
fi
fi
# Find out who we are going to mount it as
CONSOLEUSER=`stat -c%U /dev/console 2>/dev/null`
if [ -z "$CONSOLEUSER" ]
then
set `ls -l /dev/console`
CONSOLEUSER=$3
fi
[ -n "$CONSOLEUSER" ] || CONSOLEUSER=root
PASSWD=`getent passwd $CONSOLEUSER 2>/dev/null`
if [ -z "$PASSWD" ]
then
PASSWD=`grep "$CONSOLEUSER" /etc/passwd||grep root /etc/passwd`
fi
if [ -z "$PASSWD" ]
then
mesg "Could not get password entry for $CONSOLEUSER"
exit 1
fi
set `echo $PASSWD | sed 's/:/ /g'`
if [ $# -lt 4 ]
then
mesg "Bad password entry for $CONSOLEUSER"
exit 1
fi
# These options should prevent abuse and make it writeable for the
# console user.
if grep -q supermount /proc/filesystems
then
MOUNTOPTS="-s -t supermount -onoatime,nosuid,umask=077,uid=$3,gid=$4"
else
MOUNTOPTS="-s -onoatime,sync,dirsync,nosuid,umask=077,uid=$3,gid=$4"
fi
mesg mount $MOUNTOPTS $DEVICE $MOUNTPATH
mount $MOUNTOPTS $DEVICE $MOUNTPATH
fi |
Quando inserisco la Flash memory sembra che tutto funzioni correttamente:
- la directory /mnt/usb/USB_DISK_Pro viene creata
- in /var/log/messages posso vedere che il comando "mesg mount"... prima del mount viene eseguito correttamente:
Code: | Dec 27 20:43:04 gentoo /etc/hotplug.d/block/automount.hotplug: mount -s -onoatime,sync,dirsync,nosuid,umask=077,uid=1000,gid=100 /dev/sda1 /mnt/usb/USB_DISK_Pro |
il problema è che però la directory /mnt/usb/USB_DISK_Pro non viene montata! Se provo a listarne il contenuto mi dice che la cartella è vuota...
Se successivamente lancio il comando:
Code: | mount -s -onoatime,sync,dirsync,nosuid,umask=077,uid=1000,gid=100 /dev/sda1 /mnt/usb/USB_DISK_Pro |
manualmente dal terminale, allora il mount viene eseguito e posso vedere il contenuto della Flash memory.
Come mai il comando mount nello script non viene eseguito?
Grazie per l'aiuto |
|
Back to top |
|
|
randomaze Bodhisattva
Joined: 21 Oct 2003 Posts: 9985
|
Posted: Thu Dec 30, 2004 8:56 am Post subject: Re: L'hotplug script non fa il mount della Flash memory |
|
|
forna wrote: | Come mai il comando mount nello script non viene eseguito? |
Hai già visto se in questo post ci sono ifnormazioni utili? _________________ Ciao da me! |
|
Back to top |
|
|
forna n00b
Joined: 13 Sep 2004 Posts: 14 Location: Dublin, Ireland
|
Posted: Thu Dec 30, 2004 2:58 pm Post subject: |
|
|
Grazie per la risposta randomaze.
Provero' questo nuovo script stasera.
Solo un paio di domande.
Lo script che non mi funziona utilizza hotplug e l'ho messo nella directory:
Code: | /etc/hotplug.d/block/ |
e viene lanciato automaticamente dal demone di hotplug quando inserisco la Flash memory USB.
Come mai quest'altro script si installa sotto la directory
Code: | /etc/dev.d/default/ |
si tratta sempre di uno script di hotplug o di tratta di una rule di udev?
Sto cercando della buona documentazione su hotplug e udev ma l'argomento é abbastanza intricato. Non riesco a capirne la differenza e quando é meglio usare uno o l'altro.
Qualcuno ha un link a della buona documentazione in italiano o inglese?
Qual'é il metodo "migliore" per fare il mount automatico delle periferiche removibili (in generale mi riferisco a tutte le periferiche USB)? rule udev, script hotplug, ivman...
Mi interessa fare il mount automatico senza bisogno di GUI (non sono interessato per esempio a gnome-volume-manager).
Grazie per l'aiuto |
|
Back to top |
|
|
motaboy Developer
Joined: 15 Dec 2003 Posts: 1483
|
Posted: Thu Dec 30, 2004 8:49 pm Post subject: |
|
|
Semplicemente se usi udev devi mettere lo script sotto /etc/dev.d perchè il device viene creato da udev e quindi lo script deve essere lanciato dopo la sua creazione.
Comunque se non vuoi utilizzare la GUI puoi provare ivman. _________________ ... |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|