How I can prevent multiple mountings?

How I can prevent multiple mountings?

I have a Ubuntu Server, a NAS, and I am using CIFS protocol to mount. I ran into a situation where I had repeats of the same mount. The below is the output of me running the mount:

//10.0.1.38/FOO on /home/s3backup/mnt/FOO type cifs (rw,mand)
//10.0.1.38/FOO on /home/s3backup/mnt/FOO type cifs (rw,mand)
//10.0.1.38/FOO on /home/s3backup/mnt/FOO type cifs (rw,mand)

At this point, if I umount 3 times, I will finally dismount everything.

How would I be able to prevent this stacked mounting, either in mount options or in smb.conf on the NAS?

If not, can I get a warning when I try to mount on top of something?

Thanks!


Hi I wrote a short bash script to check. I've tested on Mac. Use at own risk :).

#!/bin/bash
# USAGE: hasmount.sh /home/me
# retcode 0 has mount
# retcode 1 no mount
# retcode 2 is not directory

if [ ! -d $1 ]; then
    exit 2
fi

n_matches=`mount | grep " \`pushd $1;pwd\` " | wc -l`
n_matches=`echo $n_matches`
if [ "$n_matches" = "0" ]; then
    exit 1
else
    exit 0
fi

答案1

You can use /etc/fstab to mount or even just to configure the mount (and use noauto). Then use mount -a or mount /home/s3backup/mnt/FOO to mount it.

Another alternative is to use an alias for mount that will check if the filesystem is already mounted or if the mountpoint already has a FS mounted at that point.

相关内容