What I want to do?
I want to configure my /etc/fstab so that my NFS share was:
- mounted automatically when accessed (auto-mount on-demand),
- unmounted automatically after specified idle timeout (x-systemd.idle-timeout).
AFAIK, I can achieve this behavior using AutoFS or systemd automount. I prefer systemd because I don't want to install additional packages unless needed.
What's my problem?
This is excerpt from my /etc/fstab (I followed this tutorial):
192.168.1.14:/home/someuser/somedir /mnt/someuser_share nfs noauto,x-systemd.automount,x-systemd.device-timeout=30,x-systemd.idle-timeout=1min,_netdev 0 0
Note that in the above line there is:
x-systemd.idle-timeout=1min
but it doesn't work. After waiting 1 minute without using /mnt/someuser_share it is still mounted.
Why it doesn't work as expected?
Additional info
Note that after system bootup my share is not mounted as expected. After I type eg. ls /mnt/someuser_share it's mounted (if 192.168.1.14 is online). After next 1 minute I would expect that my share will be unmounted, but it isn't.
I'm using Debian Stretch (9.6), ie. current Debian Stable. systemd version: 232.
As a side note: I'm aware that systemd reads /etc/fstab and creates unit files, specifically automount and mount unit files that can be listed using systemctl command and viewed using systemctl cat name-of-the-unit-file.
Update #1
Removing _netdev mount option from /etc/fstab worked (as suggested by @D'Arcy Nader in the comment below), but I don't understand why it actually helped. _netdev is intended to be used with the remote shares because it forces systemd to consider the mount unit a network mount. So why it breaks things up?
Content of mnt-someuser_share.automount before and after removing _netdev mount option remains the same:
root@someuser:~$ systemctl cat mnt-someuser_share.automount
# /run/systemd/generator/mnt-someuser_share.automount
# Automatically generated by systemd-fstab-generator
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=remote-fs.target
[Automount]
Where=/mnt/someuser_share
TimeoutIdleSec=1min
as opposed to content of mnt-someuser_share.mount which differs. Before removing _netdev:
root@parents-desktop:~$ systemctl cat mnt-someuser_share.mount
# /run/systemd/generator/mnt-someuser_share.mount
# Automatically generated by systemd-fstab-generator
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
[Mount]
What=192.168.1.14:/home/someuser/somedir
Where=/mnt/someuser_share
Type=nfs
Options=noauto,x-systemd.automount,x-systemd.idle-timeout=1min,_netdev
After removing _netdev last line changes – instead of:
Options=noauto,x-systemd.automount,x-systemd.idle-timeout=1min,_netdev
there is:
Options=noauto,x-systemd.automount,x-systemd.idle-timeout=1min
Update #2
After experimenting with NFS shares and mount options, I noticed that my /mnt/someuser_share share is automatically mounted immediately after system bootup and it's not unmounted after 1 minute (again), even though I don't have _netdev option in my /etc/fstab. After I removed all the files from /mnt/someuser_share it worked again.
To make things even more confusing, after I made it work again, I appended _netdev option back to /etc/fstab and it still works fine, so there must be some misunderstanding what does it actually mean that the remote share is idle for 1 minute.