HowTo: Auto Mounting Samba Shares Using AutoFS

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
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

altair4 wrote:Why not post the mount command you use to access the server from Mint and we'll use that as an example of how you would mount it using AutoFS?
Thanks for the quick reply!

Here's the relevant parts of my /etc/samba/smb.conf:

Code: Select all

security = user
encrypt passwords = true
[Dan]
path = /mnt/Storage/dan
valid users = dan
guest ok = no
writable = yes
browsable = yes
And the mount command I use:

Code: Select all

sudo mount -t cifs //192.168.2.42/dan ~/Public -o credentials=~/.smbcred
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

sudo mount -t cifs //192.168.2.42/dan ~/Public -o credentials=~/.smbcred
It's not a good idea to have AutoFS mount things to the home directory so I''m going to follow the HowTo and mount it to /mnt/Samba/Dan instead:

[1] After installing autofs edit /etc/auto.master by adding the line per the HowTo:
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
+auto.master
You don't need to create the /mnt/Samba folder since AutoFS will do that for you. If you already created it that's fine too - autofs is flexible.

[2] Then create the /etc/auto.sambashares file and add the equivalent of your terminal mount command:

Code: Select all

Dan -fstype=cifs,rw,credentials=${HOME}/.smbcred,iocharset=utf8 ://192.168.2.42/dan
Then run the following command to enable autofs with the new instructions:

Code: Select all

sudo service autofs restart
When your access /mnt/Samba/Dan autofs will automatically mount 192.168.2.42/dan to it.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

OK, I did all that, but when I browse to /mnt in Thunar, there's no Samba directory :-(
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Post the output of the following commands please:

Code: Select all

cat /etc/auto.master

Code: Select all

cat /etc/auto.sambashares
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

Code: Select all

dan@slave:~$ cat /etc/auto.master
+dir:/etc/auto.master.d
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
+auto.master

dan@slave:~$ cat /etc/auto.sambashares
Dan -fstype=cifs,rw,credentials=${HOME}/.smbcred,iocharset=utf8 ://192.168.2.42/dan
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Can you see the contents of the share this way:

Code: Select all

ls -l /mnt/Samba/Dan
If you cannot then stop the service:

Code: Select all

sudo service autofs stop
In one terminal run this command:

Code: Select all

sudo automount -vf 
In a different terminal run this again:

Code: Select all

ls -l /mnt/Samba/Dan
Any error messages?
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

I can't see the mount like that and get the following error message after the last command you gave:

Code: Select all

username@proxy ~ $ ls -l /mnt/Samba/Dan
ls: cannot access /mnt/Samba/Dan: No such file or directory
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

ANd what are the error messages in the terminal where you are running sudo automount -vf

EDIT: Just to be clear about what I'm getting at here I'm trying to diagnose the issue since I can't reproduce it on my systems here. So I want you to open 2 instances of the terminal and place them next to each other on your desktop.

On the left terminal:
sudo service autofs stop
sudo automount -vf

On the right terminal:
ls -l /mnt/Samba/Dan

What is the output of the left terminal when you issue the "ls -l /mnt/Samba/Dan" on the right terminal?
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

Ah, my bad - I think this is what you're after:

Code: Select all

dan@slave:~$ sudo automount -vf
Starting automounter version 5.0.7, master map /etc/auto.master
using kernel protocol version 5.02
lookup(dir): dir map /etc/auto.master.d missing or not readable
lookup(file): failed to read included master map dir:/etc/auto.master.d
lookup(file): failed to read included master map auto.master
mounted indirect on /mnt/Samba with timeout 30, freq 8 seconds
ghosting enabled
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Well, that's different:
lookup(dir): dir map /etc/auto.master.d missing or not readable
lookup(file): failed to read included master map dir:/etc/auto.master.d
lookup(file): failed to read included master map auto.master
It says it couldn't read among other things auto.master yet it did in fact create the mount point parent - at least it thinks it did:
mounted indirect on /mnt/Samba with timeout 30, freq 8 seconds
I will do my best to see if I can recreate this error.
Last edited by altair4 on Tue Aug 19, 2014 1:48 pm, edited 1 time in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

altair4 wrote:I will do my best to see if I can recreate this error.
Thanks for your help!
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

I just brought up a fresh install of Mint17 XFCE and went through the Howto and it works just as advertised. At this point I'm guessing but what if we took the error message literally:
lookup(dir): dir map /etc/auto.master.d missing or not readable
lookup(file): failed to read included master map dir:/etc/auto.master.d
lookup(file): failed to read included master map auto.master
Your /etc/auto.master looks like this:
dan@slave:~$ cat /etc/auto.master
+dir:/etc/auto.master.d
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
+auto.master
Comment out the +dir:/etc/auto.master.d and +dir:auto.master lines:
dan@slave:~$ cat /etc/auto.master
#+dir:/etc/auto.master.d
/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost
#+auto.master
Then restart autofs:

Code: Select all

sudo service autofs restart
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

Commented that out and restarted:

Code: Select all

dan@slave:~$ sudo service autofs restart
[ ok ] Stopping automount....
[....] Starting automount.../usr/sbin/automount: program is already running.
. ok 
No change. Samba directory is still not there.

Not sure why it says automount is already running... I get the same response if I issue explicit stop and start commands.

Also, keep in mind my server is Debian Wheezy. Not sure if that makes a difference.

EDIT - Tried this again:

Code: Select all

dan@slave:~$ sudo service autofs stop
[sudo] password for dan: 
[ ok ] Stopping automount....
dan@slave:~$ sudo automount -vf
automount: program is already running.
dan@slave:~$ 
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

You are doing all of this on Mint right? Not Debian.

Stopping autofs should return:

Code: Select all

autofs stop/waiting
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

No - my server is Debian Wheezy as it needs a non-PAE kernel. My client is Linux Mint 17 XFCE (I think I did mention that in my first post). Does that change things?

Code: Select all

dan@slave:~$ sudo service autofs stop
[sudo] password for dan: 
[ ok ] Stopping automount....
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

Now you're confusing me - which really isn't all the hard to do but ....

AutoFS is a client application. It's designed in this particular case to connect to and mount the "dan" share on the Debian server. autofs has to be installed and configured on the Mint17 client not the Debian server.
Last edited by altair4 on Tue Aug 19, 2014 3:05 pm, edited 1 time in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

Oh well, that's embarassing! I thought this all had to be done on the server... I'm so sorry!
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

OK, so I've set everything up on my client now...

The directory structure appears (/mnt/Samba/Dan) when I browse it in Thunar, but Dan seems to be owned by root and I can't right-click and create a new file.

EDIT: Nevermind, it's all working now. I tried creating a file from the terminal and that worked, so I restarted Thunar and now everything seems to be working great!

Thanks so much for your help and apologies for the confusion!
altair4
Level 20
Level 20
Posts: 11452
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by altair4 »

safetycopy wrote:OK, so I've set everything up on my client now...

The directory structure appears (/mnt/Samba/Dan) when I browse it in Thunar, but Dan seems to be owned by root and I can't right-click and create a new file.

EDIT: Nevermind, it's all working now. I tried creating a file from the terminal and that worked, so I restarted Thunar and now everything seems to be working great!

Thanks so much for your help and apologies for the confusion!
1st: Whew! I'm glad we got that settled.

2nd: There is one teensie weensie little problem left I'm afraid. And you already found it.

There's a very strange bug in the latest thunar that is really very hard to describe. If you wait long enough ( 30 seconds ) and open up /mnt/Samba/Dan you will be able to read and even edit a file that is already there. But you won't be able to add a new one.

You can work around this problem by:

Accessing it with an ls -l first which is kind of inconvienient.
You can access it once through thunar - close thunar - and access it again within the 30 second timeout - and now you can write - also inconvenient.
Use something other than thunar. The XFE file manager is my choice.

I should note that this affects only Thunar. If you open up gedit for example and want to save a new file there it's not an issue.

A bug report has been submitted to XFCE itself on this issue by one of the forum administrators on the XFCE forum.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
safetycopy

Re: HowTo: Auto Mounting Samba Shares Using AutoFS

Post by safetycopy »

I will look into XFE (it's pretty ugly by default!) - thanks for the suggestion and thanks again for your help!

Next project will be to add a shared share (a directory more than one user can access), but that's for tomorrow :-)
Post Reply

Return to “Tutorials”