Post

Install & configure NFSv4.1

Install & configure NFSv4.1

Introduction

I use NFS shares on my own homelab and I need it to access files like movies and tv shows on my NAS. So therefor I just need a fast and unencrypted file share in my network nothing else.

Installation

1
pacman -S nfs-utils

Preparation

In order to prevent permission issues between your NAS (or NFS file server) and your client I’ll strongly recommend to reassign the UID and GID of your current clients user according to the UID/GID on the server.

Scenario

  • Old identity: username → UID:GID 1000:1000
  • New identity: username → UID:GID 1027:100

First is the common case on Linux filesystems. The second entry shows the UID/GID example of a Synology NAS.

Log off from GUI

First of all log off from your desktop session completly and switch to another terminal by pressing Ctrl+F3. After that logon as root.

In order to prevent any issues it would be best practice to use any Live-Image and chroot into your installation. For example if you use CachyOS you can use cachy-chroot in the terminal. It will do all needed steps automatically for you.

Switch UID / GID

After that switch the ids. Replace <user> with the username you want to switch the ids.

1
2
usermod -u 1027 <user>
usermod -g 100 <user>

Reassign Ownership by UID

Change ownership of all files that still belong to the old UID:

1
find / -user 1000 -exec chown -h 1027 {} \;

Change ownership of all files that still belong to the old GID:

1
find / -group 1000 -exec chgrp -h 100 {} \;
ParameterExplanation
/Start at the filesystem root.
-xdevDo not cross filesystem boundaries (prevents touching /proc, /sys, NFS mounts, etc.).
-(g,u)id 1000Match only files owned by the old UID.
-exec chown -h 1027 {} \;Change the owner to the new UID.
-hEnsures symbolic links are updated without dereferencing.

Final Step

This step is highly recommended.

1
reboot

After reboot logon with your normal user account and verify that all is working correctly. Also check the new ids with id command.

Verification

1
2
3
4
id $USER
getent passwd $USER
getent group | grep 100
ls -ln /home/$USER | head

Mounting

Server » Client

1
2
# NFS-Share
192.168.0.5:/volume1/backups /mnt/nas/backups nfs4 users,_netdev,noatime,nofail,x-systemd.automount,x-systemd.idle-timeout=600,x-gvfs-show,hard,nfsvers=4.1,proto=tcp,lock,noatime,lookupcache=positive 0 0
OptionCategoryDescriptionNotes / Impact
_netdevBoot / NetworkingTells the system that this filesystem requires network access. Prevents the system from blocking during boot if the network or NAS is unavailable.Essential for systems where the NAS is not always online.
nofailBoot HandlingAllows the system to continue booting even if the mount fails.Prevents emergency mode when the NAS is offline.
x-systemd.automountsystemdDefers the actual mount operation until the directory is first accessed.Eliminates boot delays and mount errors when the NAS is offline.
x-systemd.idle-timeout=600systemdAutomatically unmounts the share after 600 seconds (10 minutes) of inactivity.Allows clean NAS shutdowns and avoids stale mounts.
x-gvfs-showDesktop IntegrationMakes the mount visible in graphical file managers (GVFS-based, e.g., GNOME Files).Optional; useful on laptops or desktop systems.
hardNFS SemanticsEnsures NFS operations retry indefinitely until the server responds. Guarantees data integrity.Recommended for writable shares; may block processes during active I/O if the NAS goes offline.
nfsvers=4.1NFS ProtocolForces use of NFS version 4.1.Synology DSM 7 defaults to 4.1; explicit setting avoids negotiation issues.
proto=tcpTransportForces TCP as the transport protocol for NFS traffic.TCP is reliable and standard for NFSv4.
lockFile LockingEnables NFS file locking support.With NFSv4, locking is integrated; this option is effectively a no-op but harmless.
noatimeFilesystem MetadataDisables access time updates on files.Reduces write I/O and improves performance.
lookupcache=positiveNFS Client CacheCaches only positive name lookups (existing files), not negative ones.Improves consistency when files are created or removed on the server.

Server » Server

1
2
# NFS-Share
192.168.178.5:/volume1/backups /mnt/nas/backups nfs4 _netdev,hard,nfsvers=4.1,proto=tcp,lock,noatime,rsize=1048576,wsize=1048576,timeo=600,retrans=5,actimeo=1,nofail 0 0
OptionCategoryShort Explanation
_netdevBoot / NetworkingMarks the filesystem as network-dependent to prevent boot blocking if the network or server is unavailable.
hardNFS SemanticsForces NFS operations to retry until the server responds, ensuring data integrity.
nfsvers=4.1NFS ProtocolExplicitly selects NFS version 4.1 for compatibility and stability.
proto=tcpTransportUses TCP for NFS traffic, providing reliable data transmission.
lockFile LockingEnables NFS file locking (integrated by default in NFSv4).
noatimeFilesystem MetadataDisables access time updates to reduce write overhead.
rsize=1048576PerformanceSets the read buffer size to 1 MiB for higher throughput.
wsize=1048576PerformanceSets the write buffer size to 1 MiB for higher throughput.
timeo=600TimeoutSets the NFS RPC timeout to 60 seconds (600 tenths of a second).
retrans=5Retry PolicyLimits the number of retransmissions before reporting an error.
actimeo=1Attribute CachingCaches file attributes for 1 second to balance performance and consistency.
nofailBoot HandlingAllows the system to continue booting even if the mount fails.
This post is licensed under CC BY 4.0 by the author.