auto mount external hard drive but only when present?

2005-03-09 Thread Duane Winner
Hi all,
Hoping someone might have a good technique for this situation:
I have a laptop with a docking station and in the expansion bay of the 
dock, I have a second hard drive, which I have configured as /dev/ad4s1d 
and mount it to /hd2

Normally on workstations with a 2nd drive, I'll just put another line in 
fstab and it will mount at each boot.

But because this is a laptop, and will be pulled off the dock when I'm 
on the road, I can't have that, because FreeBSD will scream into single 
user mode if that partition isn't there. I could put a 'noauto' switch 
into fstab, but that still leaves me with the problem:

The reason for the second drive is for backups: I want to run rsnapshot 
to take regular snapshots of my primary drive filesystems to the 2nd 
drive, and rsnapshot runs as a cron job. Now rnsnapshot is smart enough 
to know not to create the snapshot root if the mount isn't there, but 
while I am docked, I'll have to remember to manually mount the second 
drive. If I forget (which I'm apt to do), then no backups :(

What I'm looking for is a script or something that will mount 
/dev/ad4s1d to /hd2 automatically when it's present, but ignore it when 
it's not, and if possible to unmount it gracefully on shutdown.

I looked at amd automounting, but that seems to be a bit overkill (I 
really don't like the idea of adding NFS et.al. if I can avoid it).

Any ideas?
Cheers,
DW
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: auto mount external hard drive but only when present?

2005-03-09 Thread Mario Hoerich
# Duane Winner:
 I have a laptop with a docking station and in the expansion bay of the 
 dock, I have a second hard drive, which I have configured as /dev/ad4s1d 
 and mount it to /hd2
[...]
 But because this is a laptop, and will be pulled off the dock when I'm 
 on the road, I can't have that, because FreeBSD will scream into single 
 user mode if that partition isn't there. I could put a 'noauto' switch 
 into fstab, but that still leaves me with the problem:

Just a (rather crude) quickhack:

   #!/bin/sh

   SLEEP=300
   MOUNTED=0
   
   while [ 1 ]; do
   sleep $SLEEP

   if [ $MOUNTED = 0 ]; then 
   mount -t ufs2 /dev/ad4s1d /hd2 /dev/null 21

   if [ $? = 0 ]; then
   MOUNTED=1
   fi
   else
   touch /hd2/.touchme /dev/null 21

   if [ $? = 1 ]; then
   umount -f /hd2 /dev/null 21
   MOUNTED=0
   fi
   fi
   done

   
Basically, this'll try every $SLEEP seconds to either mount
the disk or, once this has been done successfully, to touch
a file on /hd2. If that fails, the disk's no longer there,
so force-unmount it.

I can't really test it, so I'm none too sure this works, though. :(

HTH,
Mario
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]