使用 autofs 挂载 CIFS 共享

Pha*_*nto 14 redhat cifs autofs automount

我有一个运行 RHEL 5.5 的系统,我正在尝试使用autofs. (由于网络在启动时未准备好,我不想使用fstab。)我能够手动安装共享,但autofs只是没有安装它们。

以下是我正在处理的文件:

在结束时/etc/auto.master,我有:

## Mount this test share:
/test    /etc/auto.test    --timeout=60
Run Code Online (Sandbox Code Playgroud)

/etc/auto.test,我有:

test    -fstype=cifs,username=testuser,domain=domain.com,password=password ://server/test
Run Code Online (Sandbox Code Playgroud)

然后我重新启动autofs服务。

但是,这不起作用。 ls-ing 目录不返回任何结果。我在网上遵循了所有这些指南,我要么不理解它们,要么它们就是不工作。

谢谢你

Car*_*don 10

因为我整个上午都在调试同样的问题。让我解释一下上面发生的事情。

/etc/auto.master

## Mount this test share:
/test    /etc/auto.test    --timeout=60
Run Code Online (Sandbox Code Playgroud)

这意味着我想安装一些东西/test并阅读详细信息/etc/auto.test

/etc/auto.test

test    -fstype=cifs,username=testuser,domain=domain.com,password=password ://server/test
Run Code Online (Sandbox Code Playgroud)

这意味着作为 auto.master 中指定的子文件夹,请使用以下信息进行测试。(即安装将/test/test如 slm 正确指出的那样)。

这意味着ls /test/test将显示的内容//server/test

要实现 /test -> //server/test 的原始目标,您需要以下内容:

/etc/auto.master

## Mount this test share:
/    /etc/auto.test    --timeout=60
Run Code Online (Sandbox Code Playgroud)

其他一些注意事项。我发现以下挂载选项很有用。

rw - 挂载它读/写

noserverino - 删除有关 inode 编号支持的错误消息

credentials=[credential file]- 这允许您创建一个单独的文件,其中包含凭据。它具有以下格式:

username=[windows username, domain can be included as well]
password=[windows password]
Run Code Online (Sandbox Code Playgroud)

编辑 -- 2013-06-17 13:28PM GMT-8

slm 在评论中指出挂载到文件系统的根目录可能很危险。lsd 在评论中提出了一种解决方法,即从文件系统的根目录创建一个符号链接到一个不同的位置,您将在该位置安装不会与常见内容重叠的位置。例如,如果你想让 /test 成为一个挂载,那么你实际上可以将东西挂载到 /net/the_test_mount 然后创建一个指向 /net/the_test_mount 的符号链接 /test

  • 这是危险的,因为如果有人将 usr 或 etc 添加到 /etc/auto.test 中,这些挂载将有效地覆盖系统上的那些目录。当然,这是极不可能的,但通常挂载不是在根级别完成的。 (3认同)

lsd*_*lsd 9

应该已经有一个 /etc/auto.smb,使用它,并将以下行添加到 /etc/auto.master:

/cifs   /etc/auto.smb --timeout=60
Run Code Online (Sandbox Code Playgroud)

现在所有 cifs 共享都将显示在 /cifs 下:

ls /cifs/<server>
Run Code Online (Sandbox Code Playgroud)

将显示所有可用的共享。您可能希望在 /etc/auto.smb 中放置一些选项以使用特定模式进行挂载。我有一个 auto.smb,我在某处找到并修改为完全做到这一点:

#!/bin/bash
# $Id: auto.smb,v 1.3 2005/04/05 13:02:09 raven Exp $
# This file must be executable to work! chmod 755!

key="$1"
credfile="/etc/auto.smb.$key"

opts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=eng,gid=eng"
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
    opts=$opts",credentials=$credfile"
    smbclientopts="-A "$credfile
else
    smbclientopts="-N"
fi

$SMBCLIENT $smbclientopts -gNL $key 2>/dev/null| awk -v key="$key" -v opts="$opts" -F'|' -- '
    BEGIN   { ORS=""; first=1 }
    /Disk/  {
              if (first)
                  print opts; first=0
              dir = $2
              loc = $2
              # Enclose mount dir and location in quotes
              # Double quote "$" in location as it is special
              gsub(/\$$/, "\\$", loc);
              print " \\\n\t \"/" dir "\"", "\"://" key "/" loc "\""
            }
    END     { if (!first) print "\n"; else exit 1 }
'
Run Code Online (Sandbox Code Playgroud)

这会做你想做的。我自己用过。