How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

Auto Mount Samba Shares on Boot ( GVFS Method )

Updated to include Mint Debian Changes

Prerequisites

This HowTo assumes you can connect to a remote share from Nautilus. If you cannot, this HowTo will not help you. If you have problems connecting to a remote share manually I suggest you post a separate topic asking for help.

Linux Mint Debian Edition Prerequisites

You need to install one package:

Code: Select all

sudo apt-get install gvfs-fuse
You need to add yourself to the fuse group:

Code: Select all

sudo gpasswd -a your_user_name fuse
You need to logoff and login again for the group to actually change.


GVFS

When you use Nautilus to access a samba share manually you may not know that Nautilus actually creates a mount point. The problem is it's in a hidden directory. You have to enable Nautilus to "see" that directory by going to:
Nautilus > Edit > Preferences > View > Show hidden and backup files.
The mount point is at :
/home/your_user_name/.gvfs ( note the "." in front of the gvfs - that indicates a hidden directory )


Procedure

Step 1: Connect to the Server from Nautilus

Nautilus > Network > Workgroup > Machine > Share

If the server requires authentication then enter it and click on the "remember forever" option before entering "Connect"
Once you have successfully connected go back and unmount the remote share.

Step 2: Connect from the terminal

Open Terminal
Type gvfs-mount smb://Server/share_name
Substitute the actual "Server" and "Share_name" for the ones above

The "Server" in that command can take many forms, for example:
gvfs-mount smb://WinXP/share_name
gvfs-mount smb://WinXP.local/share_name
gvfs-mount smb://192.168.0.100/share_name
The last one is by ip address of the server which is the most reliable method.

Make sure this remounts the remote share to /home/user_name/.gvfs without prompting for authentication.

Step 3: Create a script that will automate this process and place it in the Autostart folder:

Open Terminal
Type gedit
Enter the following:

Code: Select all

#!/bin/sh
gvfs-mount smb://Server/share_name
Again, Substitute the actual "Server" and "Share_name" for the ones above

Save the file as, for example: /home/user_name/share_name_mount.sh
Exit gedit
Back in the terminal make the script executable by issuing the command:
chmod +x /home/user_name/share_name_mount.sh

Go to Menu > Preferences > Startup Applications > Add > point it to /home/user_name/share_name_mount.sh.

Logoff and logon again and you should have your share mounted to /home/user_name/.gvfs/ automatically ( assuming the server is running ) and you should have a mount icon on your desktop.


Issues

[]Your Specific Application Cannot Access The Hidden Mount Point

One way around this is to create a symlink to the .gvfs folder. For example:

Open Terminal
Type mkdir /home/your_user_name/LanShare
Type ln -s /home/your_user_name/.gvfs/"share_name on host_name" /home/your_user_name/LanShare


Another way to do this is to create a bookmark to the .gvfs folder so that is shows up in the Open and Save boxes:

Run the following command:

Code: Select all

nautilus $HOME/.gvfs
*** Bookmark that location: Bookmarks > Add Bookmark
*** Right click the resulting ".gvfs" bookmark > Rename and rename to LanShares for example. It should then be visible in your application as LanShares.

[]Multiple Samba Shares.

If you have many shares you want to automount you may be tempted to create one script with many gvfs-mount lines in them.
I would advise against that. I have found that if one of them fails, all subsequent lines will not be executed. What I do is simply create a separate script for each share I want to mount.

[]Karmic Bug

There is a bug in Karmic ( basis for Mint8 ) dealing with accessing a remote share with a saved password https://bugs.launchpad.net/ubuntu/+sour ... bug/463267. You will get an error message that looks like this:
Unable to mount location
DBus error org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)
Doesn't happen to everyone but unfortunately the fix is to remove the saved password for the share. Guest shares will work it's just that auto mounting of authenticated shares may not. To remove the saved password:

Menu > Accessories > Passwords and Encryption Keys > Passwords Tab

Expand the "Passwords: login" entry and you should see the the entry for the remote share.


Notes

The traditional method of doing this requires adding entries into fstab. Although it requires more effort, the traditional method has the advantage of being universal in that it can be used the same way on all systems. This way requires Gnome ( or at least gvfs ). This is not a better way - it's just another way. I found this method on the Ubuntu forums (http://ubuntuforums.org/showthread.php?t=1186877). Credit belongs to the original author. I've tried to improve the flow a bit and point out a few quirks I've discovered through use.
Last edited by altair4 on Fri Mar 23, 2012 6:45 am, edited 9 times in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Fred

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by Fred »

altair4,

Nice, informative post sir. :-)

Thanks!

Fred
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

I came across a very unusual problem when someone asked for my help with their Wireless USB Adapter. If that adapter is plugged in when she turns her machine on it won't boot. I assumed it was because her BIOS was set up to boot from USB first but it was not, so I'm not sure what's going on there. What she has to do is boot without the adapter in place and then attach it after login. She has no problem doing that but the problem is the the script to mount the remote share in my HowTo will execute immediately after login but before the network is up.

I created a little script to replace the one I have in the main HowTo to work around this problem:

Code: Select all

#!/bin/sh
while true
	do
		if initctl status nmbd|grep -c running
		then
		gvfs-mount smb://Server/share_name
		exit 0
		fi 
		sleep 5
	done
This replaces the simpler script I have in STEP 3.

My logic in this script is that the nmbd daemon will only successfully start if the network is up first. Doing a query of the status of the daemon every 5 seconds to see if it's running let's me know that the network is up. Then I execute the gvfs-mount command and exit the script.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
mwdowns

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by mwdowns »

Great tutorial. Thank you.

One question: what is the correct syntax for a share with a space in the name? For example I want to mount a share called "Lossy Music".
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

The flip answer is to not have spaces in your share name :wink:

To answer your question:

Code: Select all

gvfs-mount smb://server_name/"Lossy Music"
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
raptosaurus

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by raptosaurus »

Ok, I need some help. The scripts themselves run perfectly. However, the shares don't mount on startup.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

These scripts will run immediately after login but it's possible that your network is not up yet. If that's the case then I recommend the slightly more complicated script I mentioned above:
I created a little script to replace the one I have in the main HowTo to work around this problem:

Code: Select all

    #!/bin/sh
    while true
       do
          if initctl status nmbd|grep -c running
          then
          gvfs-mount smb://Server/share_name
          exit 0
          fi
          sleep 5
       done
This replaces the simpler script I have in STEP 3.

My logic in this script is that the nmbd daemon will only successfully start if the network is up first. Doing a query of the status of the daemon every 5 seconds to see if it's running let's me know that the network is up. Then I execute the gvfs-mount command and exit the script.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
turqoisehex
Level 2
Level 2
Posts: 52
Joined: Tue Aug 03, 2010 9:33 pm

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by turqoisehex »

Thanks for the awesome post!!! :D

This is so useful for mounting NAS shares. For some reason when I tried to mount my Tomato NAS shares using the gvfs-mount command I got:

Code: Select all

Error mounting location: volume doesn't implement mount
So instead I found out how to do it with CIFS:

Code: Select all

sudo mount -t cifs //192.168.0.2/music /media/music -o username=user,password=user,iocharset=utf8
and it worked like a charm!!!

I tried to do something similar using KDE Mint9, WOW what a headache! I'm sticking to Mint 9 Gnome DVD.

Anyways, thanks again!
Gotenks

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by Gotenks »

Thank you for the tut, I attempted to follow it in LMDE however the .gvfs directory is empty so I made a new tutorial that will work regardless of mint flavor..

http://community.linuxmint.com/tutorial/view/157

Thanks again!
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

Gotenks wrote:Thank you for the tut, I attempted to follow it in LMDE however the .gvfs directory is empty so I made a new tutorial that will work regardless of mint flavor..
First, It didn't work on LMDE because you have packages missing and users are not assigned to groups automatically as they are in Ubuntu-based Mint. Had you asked for help I would have investigated and found that you need to do 3 more steps for LMDE:

In a Terminal:
You need to install one package:

Code: Select all

sudo apt-get install gvfs-fuse
You need to add yourself to the fuse group:

Code: Select all

sudo gpasswd -a your_user_name fuse
Not sure why yet ( I installed LMDE in VBox 3 minutes ago to answer your post so I'm still learning ):
You need to logoff and login again for the group to actually change.

Second,Your Howto is the classic method of automounting remote shares. This is about the GVFS method of mounting remote shares and as I said in my HowTo:
The traditional method of doing this requires adding entries into fstab. Although it requires more effort, the traditional method has the advantage of being universal in that it can be used the same way on all systems. This way requires Gnome ( or at least gvfs ). This is not a better way - it's just another way.

Third,
You are perfectly free to create your own HowTo on the classic method or even a better HowTo on the GVFS method but attaching it to someone else's HowTo was rude and not the Mint way.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
JasonLG

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by JasonLG »

altair4 wrote:These scripts will run immediately after login but it's possible that your network is not up yet. If that's the case then I recommend the slightly more complicated script I mentioned above:
I created a little script to replace the one I have in the main HowTo to work around this problem:

Code: Select all

    #!/bin/sh
    while true
       do
          if initctl status nmbd|grep -c running
          then
          gvfs-mount smb://Server/share_name
          exit 0
          fi
          sleep 5
       done
This replaces the simpler script I have in STEP 3.

My logic in this script is that the nmbd daemon will only successfully start if the network is up first. Doing a query of the status of the daemon every 5 seconds to see if it's running let's me know that the network is up. Then I execute the gvfs-mount command and exit the script.
First, excellent howto. I was using the smbfs/cifs method but I kept getting a system hang at shut down because the network manager was shutting down before the the shares were unmounted causing a black hole. This works pretty well flawlessly. I did however find that the share would not mount if my system was set to auto login. I had to log out and then log back in every time. But once I disabled auto login it worked fine. Maybe a keyring thing? I'll take having to login over a 2 min hang at shut down any day of the eek though. Thanks again.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

@JasonLG,
You know since I wrote this howto I came across a utility that's basically this method set to a GUI. It has a much more elegant method of automounting in that it probes the network at user specified intervals to make sure the remote share is available before it attempts to mount. So it not only waits for the client network to be up but it also waits for the remote server to be up as well:

HowTo: Using Gigolo to Mount Remote Samba Shares: http://forums.linuxmint.com/viewtopic.php?f=42&t=52144

I don't think it will resolve your keyring / autologin issue though.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
cmason1015

Re: How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by cmason1015 »

Brilliant!!! Thanks so much for this!

I had been using Gigolo, but hated the notification icon staring at me (turning off the notification turns off Gigolo). This is so much easier! :mrgreen: :mrgreen: :mrgreen:
smooveg

Re: How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by smooveg »

I have one question on running the "work around" script:

Code: Select all

  #!/bin/sh
    while true
       do
          if initctl status nmbd|grep -c running
          then
          gvfs-mount smb://Server/share_name
          exit 0
          fi
          sleep 5
       done
When running the script in Terminal I get an error:

Code: Select all

10: initctl: not found
When I manually gvfs-mount and then run

Code: Select all

sudo service nmbd status
it says it's an unrecognized service. I'm not sure how to get the script running correctly.

Thank you!
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

Based on your error messages I can only assume you are running Debian based Mint. "initctl" controls Upstart which is not in Debian and there is no nmbd daemon in Debian since it's a combined ( nmbd + smbd ) service called "samba". This HowTo was written before Mint released LMDE. It still works as advertised on LMDE but that particular script to work around a rather unique situation will not.

The easiest way out of this problem is for you to use Gigolo which resolves all of these problems automatically:
HowTo: Using Gigolo to Mount Remote Samba Shares: http://forums.linuxmint.com/viewtopic.php?f=42&t=52144
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
eljorge

Re: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by eljorge »

I created a little script to replace the one I have in the main HowTo to work around this problem:

Code: Select all

#!/bin/sh
while true
	do
		if initctl status nmbd|grep -c running
		then
		gvfs-mount smb://Server/share_name
		exit 0
		fi 
		sleep 5
	done
This script didn't work for me on my laptop, i'm using wifi and the script didn't wait for the connection to be established. I searched and found this script to wait for the wifi to be connected and then run the desired command, this is how it worked for me:

Code: Select all

#!/bin/bash
while true; do
    # testing...
    LC_ALL=C nmcli -t -f DEVICE,STATE dev | grep -q "^wlan0:connected$"
    if [ $? -eq 0 ]; then
        break
    else
        # not connected, sleeping for a second
        sleep 1
    fi
done
# now connected, run the script
gvfs-mount smb://Server/share_name
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: How To: Auto Mount Samba Shares on Boot ( GVFS Method )

Post by altair4 »

Thanks for the update - I'll have to try it out.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
Post Reply

Return to “Tutorials”