autofs 问题

autofs 问题

我需要 autofs 方面的帮助。它有点复杂。

我被困在了这里。我没有 /data 目录。

The/data directory and the subdirectories fs1/, fs2/, and fs3/ should be automatically created, as you can see in the screenshot below.
$ ls /data

https://i.stack.imgur.com/Lg79a.jpg

https://linuxhint.com/mount-filesystems-automatically-on-demand-using-autofs/

这是我的 auto.sda2

/dev/sda2   ext3    UUID=5b4b2ae5-9aaa-4559-9f41-afb313998c75

我的 auto.master

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#/misc  /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#   "nosuid" and "nodev" options unless the "suid" and "dev"
#   options are explicitly given.
#
#/net   -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# 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.
#
+auto.master
/etc/auto.sda2

答案1

首先,automount是的守护进程部分autofs,但systemd在其上下文中也使用名称 automount(参见man systemd.automount)。

其次,我假设您使用的 Ubuntu 版本仍在支持中(例如 20.04、22.04 等)。

据我了解,您想要自动挂载/dev/sda2/data/fs2

您需要autofs安装该包(sudo apt-get install autofs)。其中有一些示例文件,/etc您可以在其中查看其工作原理。

就您而言,涉及多个文件。

  1. /etc/auto.master(请参阅man auto.master了解完整语法和选项)您已经添加了不正确的行/etc/auto.sda2。从文件中的示例可以看出,缺少挂载点。正确的是/data /etc/auto.sda2,但我宁愿将其命名为auto.data。但让我们坚持使用auto.sda2
  2. /etc/auto.sda2 里面需要有这一行(请参阅man 5 autofs以了解完整的语法和选项):
fs2 -fstype=ext3 :/dev/sda2
  1. 您必须创建挂载点的根目录:sudo mkdir /data
  2. 重新启动 autofs:sudo systemctl restart autofs
  3. 此时一切就绪,你应该可以做到ls /data/fs2

正如名称“automount”所示,它只在“需要”时挂载,也就是访问时。通常ls /data会显示一个空目录。

在文件中/etc/autofs.conf(请参阅man 5 autofs.conf了解完整语法和选项),您可以更改多个选项。其中一个选项名为,默认browse_mode设置为。在现有文件中搜索它,取消注释并将其设置为( )。重新启动 autofs(请参阅上文)。现在您将始终看到 中的目录,即使它们尚未挂载。no/etc/autofs.confyesbrowse_mode = yes/data

相关内容