Hi,
i have several volumes (harddiscs and/or usb-sticks) on my box, but one of my external harddiscs i need only to backup movies, so that this harddisc
isn't always connected on my box.
in this case it's a good idea to mount this harddisc with mdev in always the same mountpoint.
for those who want to do the same that is possible if you edit the script on the box in /etc/mdev with name mdev-mount.sh
you need only a function as following in the mdev-mount.sh (i named it my_uuid_mount);
my_uuid_mount() { FIXED_MOUNTPOINT=/media/usb4 EXT_USB_HDD_UUID=9a9ceb61-8626-4851-b7b8-5813fc8kb2af if [ "$EXT_USB_HDD_UUID" = "$UUID" ] ; then MOUNTPOINT=$FIXED_MOUNTPOINT fi }
certainly you must edit the following variables from this function;
FIXED_MOUNTPOINT=/media/usb4
EXT_USB_HDD_UUID=9a9ceb61-8626-4851-b7b8-5813fc8kb2af
and set your own mountpoint and your uuid ( bold marked ) for your media
(you find out what is the uuid for your media with the command blkid in telnet or ssh if your media is connected on the box and on).
in my case the external harddisc will be mountet to /media/usb4 as you can see.
this function you must write on the right place in the mdev-mount.sh in fact under the function get_blkid, so that it looks as following;
get_blkid() { # run the result of blkid as a shell command eval `blkid /dev/${MDEV} | grep ${MDEV} | cut -d ':' -f 2` log ">" "device TYPE = $TYPE" log ">" "device UUID = $UUID" log ">" "device LABEL = $LABEL" } my_uuid_mount() { FIXED_MOUNTPOINT=/media/usb4 EXT_USB_HDD_UUID=9a9ceb61-8626-4851-b7b8-5813fc8kb2af if [ "$EXT_USB_HDD_UUID" = "$UUID" ] ; then MOUNTPOINT=$FIXED_MOUNTPOINT fi }
and now you must nor write the name of the new function (in this case my_uuid_mount) in the mdev-mount.sh on the right place too.
in fact at the following section from the original mdev-mount.sh script;
# Use mkdir as 'atomic' action, failure means someone beat us to the punch if ! mkdir "${MOUNTPOINT}" ; then MOUNTPOINT="/media/$MDEV" log ">" "alternative MOUNTPOINT = $MOUNTPOINT" mkdir -p "${MOUNTPOINT}" fi
after edit it must looks as following;
# Use mkdir as 'atomic' action, failure means someone beat us to the punch if ! mkdir "${MOUNTPOINT}" ; then MOUNTPOINT="/media/$MDEV" my_uuid_mount log ">" "alternative MOUNTPOINT = $MOUNTPOINT" mkdir -p "${MOUNTPOINT}" fi
basically now it's ready, but if you want to disconnect the media after usage you need also a own script to umount it before disconnect.
this script i named external_backup_hdd_mount.sh and you must copy it on your box to /usr/script and also it must be set executable
with following command in telnet or ssh;
chmod 755 /usr/script/external_backup_hdd_mount.sh
it looks as following;
#!/bin/sh EXTERNAL_BACKUP_HDD_MOUNTPOINT="/media/usb4" EXTERNAL_BACKUP_HDD_UUID="UUID=9a9ceb61-8626-4851-b7b8-5813fc8kb2af" TMP=/tmp LOGFILE=$TMP/external_backup_hdd_mount.log # Logfile loeschen rm -f $LOGFILE # Logfile erstellen touch $LOGFILE if [ ! -d $EXTERNAL_BACKUP_HDD_MOUNTPOINT ] ; then mkdir $EXTERNAL_BACKUP_HDD_MOUNTPOINT if [ "$?" = "0" ] ; then echo -e "Verzeichnis\n$EXTERNAL_BACKUP_HDD_MOUNTPOINT wurde erstellt." | tee -a $LOGFILE else echo -e "ABBRUCH !\nVerzeichnis\n$EXTERNAL_BACKUP_HDD_MOUNTPOINT erstellen fehlgeschlagen." | tee -a $LOGFILE && exit 1 fi fi EXTERNAL_BACKUP_HDD_MOUNT="$(/bin/mount | grep "$EXTERNAL_BACKUP_HDD_MOUNTPOINT" | awk '{print $3}')" > /dev/null 2>&1 case $EXTERNAL_BACKUP_HDD_MOUNT in $EXTERNAL_BACKUP_HDD_MOUNTPOINT) DEVICE="$(/bin/mount | grep "$EXTERNAL_BACKUP_HDD_MOUNTPOINT" | awk '{print $1}')" > /dev/null 2>&1 MOUNT_CNT="$(/bin/mount | grep -c ${DEVICE})" > /dev/null 2>&1 while [ "$MOUNT_CNT" -gt "0" ] do umount $DEVICE if [ "$?" = "0" ] ; then MOUNT_CNT="$(/bin/mount | grep -c ${DEVICE})" > /dev/null 2>&1 if [ "$MOUNT_CNT" -gt "0" ] ; then continue elif [ "$MOUNT_CNT" -eq "0" ] ; then echo "Platte wurde umountet." | tee -a $LOGFILE && break fi else echo -e "ABBRUCH !\nPlatte umounten fehlgeschlagen." | tee -a $LOGFILE && exit 1 fi done ;; "") mount $EXTERNAL_BACKUP_HDD_UUID $EXTERNAL_BACKUP_HDD_MOUNTPOINT if [ "$?" = "0" ] ; then echo "Platte wurde gemountet." | tee -a $LOGFILE else echo -e "ABBRUCH !\nPlatte mounten fehlgeschlagen." | tee -a $LOGFILE && exit 1 fi ;; esac exit
it's important that you use this script with hotkey, so put it on a button of your rc with hotkey, or you can also use ppanel for it.
and ditto as above at the new function with name my_uuid_mount you must edit the variables for your own mountpoint and uuid, in fact the following two variables
from the script with name external_backup_hdd_mount.sh;
EXTERNAL_BACKUP_HDD_MOUNTPOINT="/media/usb4"
EXTERNAL_BACKUP_HDD_UUID="UUID=9a9ceb61-8626-4851-b7b8-5813fc8kb2af"
the mountpoint and the uuid must be the same as in the new function with name my_uuid_mount
with the script named external_backup_hdd_mount.sh you can then if you connect your media and it was mounted with mdev (automounter)
automatically in your desired mountpoint, umount your media before disconnected, or if you change your mind mount it again.
but please note, if you update your image (box) maybe it comes also a update for mdev and then it's good possible that your
edited mdev-mount.sh script in /etc/mdev will overridden.
at last, with the mdev-mount.sh in /etc/mdev is something more possible, as example, if you have also a internal harddisc you can
set a link automatically from the external harddisc in the moviedir from the internal harddisc too after mount the external harddisc.
regards
Pike