Autofs CIFS

Hello,

I’m using OS 13.1 on an HP DV-7 laptop and would like to have an auto mounting CIFS file share on my NAS QNAP TS-212. I am able manually mount the NAS with the following;

mount -t cifs //192.168.1.250/multimedia /mnt/test -o username=richard,password=as04bs,uid=1000,gid=100

But I’m unable to get the auto mounting of the CIFS share to work. This is what I have done so far.
The etc/auto.master file:

+auto.master
/mnt/snoeg-nas /etc/auto.cifs --timeout=60

etc/auto.cifs

mnt/snoeg-nas -fstype=cifs,nounix,noexec,username=me,password=secrete,uid=1000,gid=100 ://192.168.1.250/Documents

I realise there are better ways to implement the access credentials in a separate file, but for now I would like to get the basics to work.

The following packages are installed from the opensuse repro:
cifs-util
samba
samba-32bit
autofs

Would you please advise where I’ve gone wrong.
Thank you.

I would like to suggest you just do on-the-fly mounts. CIFS has been reported to have issues, but I just don’t use that method. I use the KDE desktop, and it supports desktop icons. You can open up the icon and see all Samba shares on your network. So, give me a chance, read trough my blog and get my bash script for ALL Samba setup options. I even request you read the blog comments as much info is present there.

S.A.C.T. - Samba Automated Configuration Tool - Version 1.06 - Blogs - openSUSE Forums

SACT can create a default /etc/samba/smb.conf file and open up the right firewall services so as to all full Samba operation and the firewall still turned on and a whole lot more. Good Luck.

Thank You,

James,

Thank you for the post. Would you say this is a bug which is yet to be logged? CIFS is a well used network file system which should just work. Are there any pointers which I could have i.e. typical issues/mistakes made in setting up CIFS? Is there a step by step howto for a CIFS setup?

Thank you.

I think the problem is due to the network not being up yet. You can disable Network Manage in YaST and use “Traditional Method with ipup” to start the network, said to fix the issue. I prefer using Network Manager as NM has proven to be faster in desktop startup speed than ifup and more flexible. My systemd utility can provide assistance in finding how long your startup takes:

SysdCmd - systemd Command Help/Config Editor - Blogs - openSUSE Forums

It is just my opinion there is no need to make this Samba Network connection on all the time and on-the-fly is the way to go. Really, try it, you will like it. For bug report searches, please look here:

Bugzilla Main Page, use your normal forum log-in for searches and I feel it is worth a look.

Thank You,

Thank you very much. I’ll work through your post tonight and will try out your suggestion. As you say, I may just like it ;).

I use autofs with this file /etc/auto.cifs show below. That auto.master has

/cifs/els /etc/auto.cifs --timeout=6

file /etc/auto.cifs:

#!/bin/bash# $Id$
# This file must be executable to work! chmod 755!
#
# Note: create a cred file for each windows/Samba-Server in your network
#       which requires password authentification.  The file should contain
#       exactly two lines:
#          username=user
#          password=*****
#       Please don't use blank spaces to separate the equal sign from the
#       user account name or password.
#       This file must be in $HOME/.smb/creds.key
#         where key corresponds to the hostname

# This script has no means to directly determine the username.  This is
# needed to access the user's credentials files.  The automount point
# directory is used for this.  KEY is the automount directory.

KEY="$1"

SMBCLIENT="$(type -p smbclient 2> /dev/null)"
 -n "$SMBCLIENT" ] || exit 1

USERNAME="$(basename $PWD)"

eval $(awk -v user="$USERNAME" -F ':' '$1 == user { print "USER_UID=" $3 " USER_GID=" $4 " USER_HOME=" $6 }' /etc/passwd)

test -z "$USER_HOME" && exit 1;

CREDS_FILE="$USER_HOME/.smb/creds.$KEY"

if test -r "$CREDS_FILE"; then
    MOUNTOPTS="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=$USER_UID,gid=$USER_GID,noserverino,credentials=$CREDS_FILE"
    SMB_CREDS="-A $CREDS_FILE"
    CIFS_HOST="$(awk -F '=' '$1 == "host" { print $2 }' $CREDS_FILE)"
else
    MOUNTOPTS="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=$USER_UID,gid=$USER_GID,noserverino"
    SMB_CREDS="-N"
fi

if test -n "${CIFS_HOST}"; then
    echo "${MOUNTOPTS} ://${CIFS_HOST}/${KEY}" | sed -e 's/\$/${DOL}/g'
else

    $SMBCLIENT $SMB_CREDS -gL $KEY 2>/dev/null \
        | awk -v key="$KEY" -v opts="$MOUNTOPTS" -F'|' -- '
        BEGIN   { ORS=""; first=1 }
        /Disk/  { if (first) { print opts; first=0 };
                  gsub(/ /, "\\ ", $2);
                  sh=$2
                  mp=$2
                  gsub(/\$/, "\\${DOL}", sh);
                  gsub(/\$/, "${DOL}", mp);
                  print " \\
	 /" mp, "://" key "/" sh }
        END     { if (!first) print "
"; else exit 1 }
        ' 
fi

Botkeeper,

Thank you for the script which I have placed in etc/auto.cifs and made the file executable. The auto.master file was also amended to suite to include the line
“/mnt/snoeg-nas /etc/auto.cifs --timeout=60” and a creds file was created //home/richard/.smb/creds.key including the two line i.e. username=me and password=topsecrete.

I have also deactivated the old fstab lines with “#”. The system is then rebooted but no mounts appear under /mnt/snoeg-nas? How can I find the reason for it not mounting with autofs? The autofs service was manually active in Yast services (runlevel).

Some pointers would be welcome.
Thank you.

SOLVED:

These are the steps taken to connect to a Samba/Windows share using CIFS and autofs in Opensuse 13.1. As mentioned above I am running a laptop which connects to a NAS Qnap TS-212. I prefer the CIFS mount to Samba mount because it mounts it as a local folder which means Amarok and Digikam are able to link to it including backup software. It is also better than using the fstab method as it deals with the network connection as to when it is available or not, so you don’t have the timeout issues.

This is the reference which I made to suite and work on a clean Opensuse 13.1 laptop install: Accessing Windows Or Samba Shares Using AutoFS | HowtoForge - Linux Howtos and Tutorials

Please note the nas is called ts-212 on the network and in the reference it is FILESERVERNAME.

Step 1: Ensure your Firewall will allow the network connection.
With the YAST firewall module I added samba client to “allowed service”.

Step 2: Activate the autofs service through YAST service (runlevel). If the service is not listed you will need to install autofs but it seems to be installed by default.

Step 3: As root user create the file ** /etc/auto.smb.[size=2][FONT=arial]ts-212[/size] containing the following two lines:

username=username
password=topsecrete

Once created;

chmod 600 /etc/auto.smb.ts-212

Step 4: Add a line at the bottom of the **/etc/**auto.master file. Please note I changed the local mount point to /mnt and reduced the timeout from 60 to 6 which may not suite all users.

/mnt /etc/auto.cifs –timeout=6

Step 5: create a file called /etc/auto.cifs, then paste the script below into it and make it executable. I have included an altered line to make this work with my default system.


#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# Note: create a cred file for each windows/Samba-Server in your network
#       which requires password authentification.  The file should contain
#       exactly two lines:
#          username=user
#          password=*****
#       Please don't use blank spaces to separate the equal sign from the
#       user account name or password.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=1000,gid=100"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
        if  -x $P/smbclient ]
        then
                SMBCLIENT=$P/smbclient
                break
        fi
done
 -x $SMBCLIENT ] || exit 1
if  -e "$credfile" ]
then
        mountopts=$mountopts",credentials=$credfile"
        smbclientopts="-A "$credfile
else
        smbclientopts="-N"
fi
$SMBCLIENT $smbclientopts -gL $key 2>/dev/null \
   | awk -v key="$key" -v opts="$mountopts" -F'|' -- '
        BEGIN   { ORS=""; first=1 }
    /Disk/  { if (first) { print opts; first=0 };
          gsub(/ /, "\\ ", $2);
          sub(/\$/, "\\$", $2);
          print " \\
	 /" $2, "://" key "/" $2 }
        END     { if (!first) print "
"; else exit 1 }
        '

Step 6: Type the following into the terminal as root.

/etc/init.d/autofs restart

Step 7:
In KDE system settings>Network settings; I changed all the Connection preferences to 8 seconds. This change may not suite everyone.[/FONT]
**

Hello,

I have a problem connecting NAS disk according to your instructions.
For the third night with the tormented, it took me a while to understand
how it works, and whenever I had thought that it must work no result. There is still mapped folder is empty.

If you use the manual mapping, it works without no problems. mount -t cifs //Diskstationn/video /home/darina/Videa -o username=Ales,password=mojeheslo,uid=1000,gid=100

The first problem was that my manual mapping worked only with the IP address, called NAS not, but I solved it by adding a name to the IP address in the hosts, then he worked the above link. Title I needed because of the above discussion, if I understand it correctly.

When it all now start the process and check the autofs, I see this error: Local domain name not set
A passed through her away can`t get. I think that because I’m not working, but I do not know how to get out. The entire listing is here:

autofs.service - Automounts filesystems on demand
Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled)
Active: active (running) since Sun 2015-01-11 09:05:30 CET; 3min 38s ago
Docs: man:automount(8)
man:autofs(5)
Process: 1383 ExecStart=/usr/sbin/automount ${AUTOFS_OPTIONS} -p /var/run/automount.pid (code=exited, status=0/SUCCESS)
Main PID: 1396 (automount)
CGroup: /system.slice/autofs.service
`-1396 /usr/sbin/automount -p /var/run/automount.pid

Jan 11 09:05:30 linux-yw6t automount[1396]: lookup_init:139: lookup(yp): map auto.master: Local domain name not set
Jan 11 09:05:30 linux-yw6t automount[1396]: [1B blob data]
Jan 11 09:05:30 linux-yw6t automount[1396]: [1B blob data]
Jan 11 09:05:30 linux-yw6t automount[1396]: [1B blob data]

Nothing would be wrong in auto.master I found, after all there is to add only one line
what and where to be mapped. :frowning:
Can you please advise me why I do not work?

Here I send my check for modified files.

https://www.dropbox.com/sh/d1zat44e8otue0p/AABWztMoyAOgf9U3uo5jHJD2a?dl=0

Thanks so much for your help, I really do not know your advice.
Sorry for English, English can not I use Google translator, but I hope you understand my problem.

Aleš

Hello,

You are welcome on these forums, but it is very unlikely that you problem is exactly the same as this very old one. Also, not very many people will watch this old thread for new posts and thus not very many people will see that you have a problem. It is much better to create a new thread. Which a good title that will atrackt the attention of people that are knoledgable in your subject.

And plase do not forget to at least tell what your openSUSE version is and which desktop (KDE, Gnome, …) you are usiing.

To others: this thread will be closed to avoid having a discussion hanging at the end of it.
Please wait for the new thread and help there.