NFS: Difference between revisions

Pigs (talk | contribs)
Using bind mounts: Add link to the filesystem bind mount section
Tags: Mobile edit Mobile web edit Advanced mobile edit
Klinger (talk | contribs)
m Intro Sentence, Link, Category:Networking added (its not only a filesystem its a way to define networks too)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
__FORCETOC__
__FORCETOC__
[[wikipedia:Network_File_System|NFS]] is a distribute filesystem protocol to access directories and files over a network.
= Server =
= Server =


Line 54: Line 57:


This configuration exposes all our shares to 2 local IPs; you can find more examples at [https://wiki.gentoo.org/wiki/NFSv4 Gentoo's wiki on NFS].
This configuration exposes all our shares to 2 local IPs; you can find more examples at [https://wiki.gentoo.org/wiki/NFSv4 Gentoo's wiki on NFS].
To list the current loaded exports, use: <code>exportfs -v</code>


Other options are available on the [https://search.nixos.org/options?query=nfs NixOS option page] or via the <code>nixos-option</code> command.
Other options are available on the [https://search.nixos.org/options?query=nfs NixOS option page] or via the <code>nixos-option</code> command.
Line 86: Line 91:
= Client =
= Client =


To ensure the client has the necessary utilities installed, add
To ensure the client has the necessary NFS utilities installed, add the following to your system configuration (for example, in <code>configuration.nix</code>).
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
   boot.supportedFilesystems = [ "nfs" ];
   boot.supportedFilesystems = [ "nfs" ];
</syntaxhighlight>
</syntaxhighlight>


to your Nix configuration (e.g. <code>configuration.nix</code>) file.
NFS shares can be mounted on a client system using the standard <code>filesystem</code> option. Continuing the server example, to mount the <code>tomoyo</code> share:
 
Continuing the server example, mounting the now-exposed ''tomoyo'' share on another box (on a client) is as simple as:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 103: Line 107:
}
}
</syntaxhighlight>
</syntaxhighlight>
Replace "server" in the above device attribute with the IP address or DNS entry of the NFS server. Note that clients see exposed shares as if they were exposed at the root level - i.e. <code>/export/foo</code> becomes <code>/foo</code> (in the <code>device</code> option). Other, regular '''fileSystems''' options apply.
 
In the above configuration, replace "server" with the appropriate IP address or DNS entry of your NFS server. Other, regular [https://search.nixos.org/options?query=filesystems.%3Cname%3E filesystem options] apply.
 
{{note| On the client side, the exposed shares are as if they were exposed at the root level - i.e. <code>/export/foo</code> becomes <code>/foo</code> (in the <code>device</code> option) }}


== Specifying NFS version ==
== Specifying NFS version ==
Line 145: Line 152:
== Using systemd.mounts and systemd.automounts ==
== Using systemd.mounts and systemd.automounts ==


Here is an example with auto-disconnecting and lazy-mounting implemented, and the <code>noatime</code> mount option added.
This section provides an alternative approach for users who prefer to manage mounts using dedicated systemd units. 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.  
Note that <code>wantedBy = [ "multi-user.target" ];</code> is required for the automount unit to start at boot.  
Line 221: Line 228:
<syntaxhighlight lang="console"><host_or_ip>/nix /nix nfs nofail,x-systemd.device-timeout=4,local_lock=all 0 0</syntaxhighlight>'''TODO:''' Why this? That seems extremely unsafe. This disables NFS locks (which apply to all NFS clients), and makes locks ''local'', meaning a lock taken by one NFS client isn't seen by another, and both can take their locks. So this removes protection against concurrent writes, which Nix assumes.
<syntaxhighlight lang="console"><host_or_ip>/nix /nix nfs nofail,x-systemd.device-timeout=4,local_lock=all 0 0</syntaxhighlight>'''TODO:''' Why this? That seems extremely unsafe. This disables NFS locks (which apply to all NFS clients), and makes locks ''local'', meaning a lock taken by one NFS client isn't seen by another, and both can take their locks. So this removes protection against concurrent writes, which Nix assumes.
[[Category:Filesystem]]
[[Category:Filesystem]]
[[Category:Networking]]