mount_smbfs: mount error..File exists
I’ve been playing around with mounting a Windows file share onto my machine via the terminal because I’m getting bored of constantly having to go to Finder and manually mounting it each time!
After a couple of times of mounting and unmounting the drive I ended up with this error:
> mount_smbfs //mneedham@punedc02/shared punedc02_shared/
mount_smbfs: mount error: /Volumes/punedc02_shared: File exists
I originally thought the 'file exists' part of the message was suggesting that I’d already mounted a share on 'punedc02_shared' but calling the 'umount' command led to the following error:
> umount punedc02_shared
umount: punedc02_shared: not currently mounted
I had actually absent mindedly gone and mounted the drive elsewhere through Finder which I only realised after reading Victor’s comments on this post.
Make sure that you already do not have the same share mounted on your Mac. I had //host/share already mounted in /Volumes/share, so when I tried to mount //host/share to /Volumes/newshare it gave me the “file exists” error.
I learnt, thanks to the unix.com forums, that you can see which devices are mounted by using 'df'.
This is where Finder had mounted the drive for me:
> df
Filesystem 512-blocks Used Available Capacity Mounted on
...
//mneedham@punedc02/shared 209696376 199773696 9922680 96% /Volumes/shared
Since the shared drive gets unmounted when I disconnect from the network I decided to write a shell script that would set it up for me again.
#!/bin/sh
function mount_drive {
mkdir -p $2
mount_smbfs $1 $2
}
drives_to_unmount=`df | awk '/mneedham@punedc02/ { print $6 }'`
if [ "$drives_to_unmount" != "" ]; then
echo "Unmounting existing drives on punedc02: \n$drives_to_unmount"
umount $drives_to_unmount
fi
mount_drive //mneedham@punedc02/media /Volumes/punedc02_media
mount_drive //mneedham@punedc02/shared /Volumes/punedc02_shared
At the moment I’ve just put that in '/usr/bin' so that it’s available on the path.
If there’s a better way to do this or a way to simplify the code please let me know.
I did come across a few ways to do the mounting using Apple Script in this post but that’s not half as fun as using the shell!
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.