2

I'm trying to set up two directories, each automounted:

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

In my case, these are:

  • /mnt/btrfs-vol/rootfs (read only)
  • /mnt/btrfs-vol/rootfs/btrbk-snap (RW for taking snapshots with btrbk)

My /etc/fstab contains:

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

I do:

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)

Strangely, /mnt/btrfs-vol/rootfs, is already mounted.

If I unmount /mnt/btrfs-vol/rootfs, it is immediately remounted:

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)

Now if I ping the subdirectory, it automounts:

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=/)

Note that the fstype of /dev/mapper/vg_svelte-rootfs has changed from autofs to btrfs.

A few seconds later (I have timeout=2 for testing`):

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)

The subdirectory is unmounted, and the fstype of /dev/mapper/vg_svelte-rootfs reverts to autofs, but it stays mounted.

How do I get it to automatically unmount?


Possibly useful information:

journal output:

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.

Checking that nothing has the directory open:

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

I've never seen ? where I'd expect the rwx placehoders to be before.

  • I'm actually trying to get mounts to automatically unmount with x-systemd.idletimeout=2 in Debian Stretch with no luck. Were you ever able to solve this? – maulinglawns Aug 6 '18 at 13:24
  • @maulinglawns I've suggested an answer below. – Tom Hale Aug 8 '18 at 5:07
0

Take a look at fstab systemd option x-systemd.requires-mounts-for=:

Configures a RequiresMountsFor= dependency between the created mount unit and other mount units. The argument must be an absolute path. This option may be specified more than once. See RequiresMountsFor= in systemd.unit(5) for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.