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

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

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

Postby altair4 on Wed Feb 24, 2010 1:21 pm

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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

Linux Mint is funded by ads and donations.
 

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

Postby Fred on Wed Feb 24, 2010 8:57 pm

altair4,

Nice, informative post sir. :-)

Thanks!

Fred
Insanity: Doing the same thing over and over and each time expecting a different result.

Democracy is 2 wolves and a lamb voting on the menu. Liberty is an armed lamb protesting the electoral outcome. A Republic negates the need for an armed protest.
User avatar
Fred
Level 10
Level 10
 
Posts: 3356
Joined: Fri Jan 04, 2008 11:59 am
Location: NC USA

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

Postby altair4 on Tue Jun 29, 2010 9:03 am

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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

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

Postby mwdowns on Sat Jul 24, 2010 5:29 am

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".
mwdowns
Level 1
Level 1
 
Posts: 5
Joined: Sat Jul 24, 2010 5:25 am

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

Postby altair4 on Sat Jul 24, 2010 7:12 am

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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

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

Postby raptosaurus on Thu Aug 12, 2010 1:31 am

Ok, I need some help. The scripts themselves run perfectly. However, the shares don't mount on startup.
raptosaurus
Level 1
Level 1
 
Posts: 5
Joined: Fri Aug 06, 2010 3:29 am

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

Postby altair4 on Thu Aug 12, 2010 6:41 am

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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

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

Postby turqoisehex on Tue Aug 24, 2010 12:41 am

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!
turqoisehex
Level 1
Level 1
 
Posts: 45
Joined: Tue Aug 03, 2010 9:33 pm

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

Postby Gotenks on Thu Sep 09, 2010 12:05 am

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!
User avatar
Gotenks
Level 1
Level 1
 
Posts: 8
Joined: Fri Jan 11, 2008 1:48 am

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

Postby altair4 on Thu Sep 09, 2010 7:31 am

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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

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

Postby JasonLG on Thu Feb 03, 2011 8:23 am

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.
"I see" said the blind man to the deaf man who stuck his wooden leg out the window to check the weather.
JasonLG
Level 7
Level 7
 
Posts: 1624
Joined: Thu May 20, 2010 9:15 pm
Location: Polk City, Iowa USA

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

Postby altair4 on Thu Feb 03, 2011 9:15 am

@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: 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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

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

Postby cmason1015 on Wed Mar 30, 2011 5:19 pm

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:
cmason1015
Level 1
Level 1
 
Posts: 3
Joined: Wed Mar 09, 2011 12:22 am

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

Postby smooveg on Tue Sep 06, 2011 10:20 pm

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!
smooveg
Level 1
Level 1
 
Posts: 9
Joined: Fri Aug 12, 2011 5:59 pm

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

Postby altair4 on Wed Sep 07, 2011 6:41 am

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: 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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

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

Postby eljorge on Thu Sep 22, 2011 1:51 pm

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
eljorge
Level 1
Level 1
 
Posts: 1
Joined: Thu Sep 22, 2011 1:41 pm

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

Postby altair4 on Thu Sep 22, 2011 3:45 pm

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.
altair4
Level 16
Level 16
 
Posts: 6055
Joined: Tue Feb 03, 2009 10:27 am

Linux Mint is funded by ads and donations.
 

Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 9 guests