Linux – AutoFS mount multiple CIFS Shares to same directory

autofslinuxlinux-networking

As long as I had only one mount everything was fine.

file: /etc/auto.master
/mnt /etc/auto.srv1_share1
file: /etc/auto.srv1_share1
sh1 -fstype=cifs,rw,user=jdoe,domain=srv1,noexec,password=xxx ://srv1/share1

which resulted in //srv1/share1 mounted to /mnt/sh1.

But so far I've been unable to mount multiple shares. The result should be something like that:
//srv1/share1 to /mnt/srv1_share1
//srv1/share2 to /mnt/srv1_share2
or
//srv1/share1 to /mnt/srv1/share1
//srv1/share2 to /mnt/srv1/share2

After trying, googling and reading(tfm) for hours, I need your help.

My current solution/workaround is this:

file: /etc/auto.master
/mnt/srv1_share1 /etc/auto.srv1_share1
/mnt/srv1_share2 /etc/auto.srv1_share2
file: /etc/auto.srv1_share1
share -fstype=cifs,rw,user=jdoe,domain=srv1,noexec,password=xxx ://srv1/share1
file: /etc/auto.srv1_share2
share -fstype=cifs,rw,user=jdoe,domain=srv1,noexec,password=xxx ://srv1/share2

resulting in these mounts:
//srv1/share1 to /mnt/srv1_share1/share
//srv1/share2 to /mnt/srv1_share2/share

Altough I can access all files I still want to get rid of those extra share-directories.

How can I accomplish this?

Best Answer

You can get the informations from this link: Ubuntu community, Autofs, 3.1.1. Direct and Indirect Maps "Direct maps create a mount-point at the path specified in the relevant map file. The mount-point entry in auto.master is always /-"

Let's create our mount-points, and add lines to /etc/auto.master

/-        /etc/auto.srv1_share1
/-        /etc/auto.srv1_share2

Created mount-points will be specified at the place in auto.srv1_share1 and auto.srv1_share2 files. Edit your files and add full /path/to/folder and it will work.

For example, /etc/auto.srv1_share1 should look like this line:

/path/to/share -fstype=cifs,rw,user=jdoe,domain=srv1,noexec,password=xxx ://srv1/share1