systemd:包含 autofs 的 autofs 无法卸载

systemd:包含 autofs 的 autofs 无法卸载

我正在尝试设置两个目录,每个目录都会自动安装:

  • /mnt/dir
  • /mnt/dir/subdir

就我而言,这些是:

  • /mnt/btrfs-vol/rootfs(只读)
  • /mnt/btrfs-vol/rootfs/btrbk-snap(RW 用于拍摄快照btrbk

我的/etc/fstab包含:

LABEL=rootfs    /mnt/btrfs-vol/rootfs               btrfs   ro,subvol=/,lazytime,compress=lzo,ssd,discard,noauto,x-systemd.automount,x-systemd.idle-timeout=2
LABEL=rootfs    /mnt/btrfs-vol/rootfs/btrbk-snap    btrfs   rw,subvol=/btrbk-snap,lazytime,compress=lzo,ssd,discard,noauto,x-systemd.automount,x-systemd.idle-timeout=2,x-systemd.requires-mounts-for=/mnt/btrfs-vol/rootfs

我愿意:

svelte ~# systemctl daemon-reload && systemctl restart local-fs.target
svelte ~# mount | grep btrfs-vol/rootfs
systemd-1 on /mnt/btrfs-vol/rootfs type autofs (rw,relatime,fd=32,pgrp=1,timeout=2,minproto=5,maxproto=5,direct)

奇怪的是,/mnt/btrfs-vol/rootfs, 已经安装了。

如果我卸载/mnt/btrfs-vol/rootfs,它会立即重新安装:

svelte ~# umount /mnt/btrfs-vol/rootfs
svelte ~# mount | grep btrfs-vol/rootfs
systemd-1 on /mnt/btrfs-vol/rootfs type autofs (rw,relatime,fd=32,pgrp=1,timeout=2,minproto=5,maxproto=5,direct)

现在,如果我 ping 子目录,它会自动挂载:

svelte ~# (cd /mnt/btrfs-vol/rootfs/btrbk-snap/ && mount | grep btrfs-vol/rootfs)
systemd-1 on /mnt/btrfs-vol/rootfs type autofs (rw,relatime,fd=32,pgrp=1,timeout=2,minproto=5,maxproto=5,direct)
/dev/mapper/vg_svelte-rootfs on /mnt/btrfs-vol/rootfs type btrfs (ro,relatime,lazytime,compress=lzo,ssd,discard,space_cache,subvolid=5,subvol=/)

请注意,fstypeof/dev/mapper/vg_svelte-rootfs已从 更改autofsbtrfs

几秒钟后(我有timeout=2测试):

svelte ~# mount | grep btrfs-vol/rootfssystemd-1 on /mnt/btrfs-vol/rootfs type autofs (rw,relatime,fd=32,pgrp=1,timeout=2,minproto=5,maxproto=5,direct)

子目录被卸载,并且fstype恢复/dev/mapper/vg_svelte-rootfsautofs,但它保持安装状态

如何让它自动卸载?


可能有用的信息:

journal输出:

Feb 21 17:16:07 svelte systemd[1]: Reloading.
Feb 21 17:16:23 svelte systemd[1]: Mounting /mnt/btrfs-vol/rootfs...
Feb 21 17:16:23 svelte systemd[1]: Set up automount mnt-btrfs\x2dvol-home-btrbk\x2dsnap.automount.
Feb 21 17:16:23 svelte systemd[1]: Mounted /mnt/btrfs-vol/rootfs.
Feb 21 17:16:23 svelte systemd[1]: mnt-btrfs\x2dvol-rootfs-btrbk\x2dsnap.automount: Directory /mnt/btrfs-vol/rootfs/btrbk-snap to mount over is not empty, mounting anyway.
Feb 21 17:16:23 svelte systemd[1]: Set up automount mnt-btrfs\x2dvol-rootfs-btrbk\x2dsnap.automount.
Feb 21 17:16:23 svelte systemd[1]: Reached target Local File Systems.
Feb 21 17:16:25 svelte systemd[1]: Stopped target Local File Systems.
Feb 21 17:16:25 svelte systemd[1]: Unset automount mnt-btrfs\x2dvol-rootfs-btrbk\x2dsnap.automount.
Feb 21 17:16:25 svelte systemd[1]: Unmounting /mnt/btrfs-vol/rootfs...
Feb 21 17:16:25 svelte systemd[1]: Unmounted /mnt/btrfs-vol/rootfs.
Feb 21 17:17:44 svelte systemd[1]: Unset automount mnt-btrfs\x2dvol-home-btrbk\x2dsnap.automount.

检查目录是否没有打开:

svelte ~# lsof /mnt/btrfs-vol/rootfs
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
svelte ~[2]# ls -l /run/user/1000 | grep gvfs
ls: cannot access '/run/user/1000/gvfs': Permission denied
d????????? ? ?    ?      ?            ? gvfs

我以前从未见过占位符?应该在哪里rwx

答案1

查看 fstabsystemd选项x-systemd.requires-mounts-for=

配置RequiresMountsFor=创建的挂载单元与其他挂载单元之间的依赖关系。参数必须是绝对路径。该选项可以指定多次。详情请RequiresMountsFor=参阅。systemd.unit(5)

相关内容