NFS: Difference between revisions
imported>2r firewall configuration for nfsv3 |
imported>Allopsychic21 adds systemd.mounts and systemd.automounts method of configuration |
||
Line 125: | Line 125: | ||
options = [ "x-systemd.idle-timeout=600" ]; # disconnects after 10 minutes (i.e. 600 seconds) | options = [ "x-systemd.idle-timeout=600" ]; # disconnects after 10 minutes (i.e. 600 seconds) | ||
}; | }; | ||
} | |||
</syntaxhighlight> | |||
=== Using systemd.mounts and systemd.automounts === | |||
Using <code>systemd.mounts</code> and <code>systemd.automounts</code> was the only way to solve NFS client hangs experienced with the above configurations. Here is an example with auto-disconnecting and lazy-mounting implemented, and the <code>noatime</code> mount option added. | |||
Note that <code>wantedBy = [ "multi-user.target" ];</code> is required for the automount unit to start at boot. | |||
Also note that <code>x-systemd</code> mount options are unneeded, as they are a representation of systemd options in <code>fstab(5)</code> format. They get parsed and converted to unit files by <code>systemd-fstab-generator(8)</code> as mentioned in <code>systemd.mount(5)</code>. | |||
<syntaxhighlight lang="nix"> | |||
{ | |||
systemd.mounts = { | |||
type = "nfs"; | |||
mountConfig = { | |||
Options = "noatime"; | |||
}; | |||
what = "server:/tomoyo"; | |||
where = "/mnt/tomoyo"; | |||
}; | |||
systemd.automounts = { | |||
wantedBy = [ "multi-user.target" ]; | |||
automountConfig = { | |||
TimeoutIdleSec = "600"; | |||
}; | |||
where = "/mnt/tomoyo"; | |||
}; | |||
} | |||
</syntaxhighlight> | |||
Multiple mounts with the exact same options can benefit from abstraction. | |||
<syntaxhighlight lang="nix"> | |||
{ | |||
systemd.mounts = let commonMountOptions = { | |||
type = "nfs"; | |||
mountConfig = { | |||
Options = "noatime"; | |||
}; | |||
}; | |||
in | |||
[ | |||
(commonMountOptions // { | |||
what = "server:/tomoyo"; | |||
where = "/mnt/tomoyo"; | |||
}) | |||
(commonMountOptions // { | |||
what = "server:/oyomot"; | |||
where = "/mnt/oyomot"; | |||
}) | |||
]; | |||
systemd.automounts = let commonAutoMountOptions = { | |||
wantedBy = [ "multi-user.target" ]; | |||
automountConfig = { | |||
TimeoutIdleSec = "600"; | |||
}; | |||
}; | |||
in | |||
[ | |||
(commonAutoMountOptions // { where = "/mnt/tomoyo"; }) | |||
(commonAutoMountOptions // { where = "/mnt/oyomot"; }) | |||
]; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |