This guide demonstrates how to mount an NFS share using systemd mount units instead of traditional /etc/fstab entries. Systemd mount units provide better integration with the system’s dependency management and offer more control over mount behavior.
Prerequisites
- NFS utilities installed on your system
- Access to an NFS server
- Root or sudo privileges
Step 1: Create the Mount Point
First, create the directory where the NFS share will be mounted:
sudo mkdir /mnt/vmnfs
Step 2: Generate the Systemd Unit Name
Use systemd-escape to generate the correct systemd unit name from your mount path:
systemd-escape -p --suffix=mount /mnt/vmnfs/
Output:
mnt-vmnfs.mount
Important: The unit file name must exactly match the mount path with slashes converted to dashes and the .mount suffix added.
Step 3: Create the Systemd Mount Unit
Create the mount unit file at /etc/systemd/system/mnt-vmnfs.mount:
sudo nano /etc/systemd/system/mnt-vmnfs.mount
Add the following configuration:
[Unit]
Description=NFS mount
[Mount]
What=atlas.uclab8.net:/volume1/VM-NFS
Where=/mnt/vmnfs
Type=nfs
Options=defaults
TimeoutSec=5
[Install]
WantedBy=multi-user.target
Configuration Breakdown
- What: The NFS server and export path (
server:/path) - Where: The local mount point (must match the unit filename)
- Type: Filesystem type (nfs, nfs4, cifs, etc.)
- Options: Mount options (same as you would use in fstab)
- TimeoutSec: Maximum time to wait for the mount operation
- WantedBy: Ensures the mount is activated at boot during multi-user target
Step 4: Reload Systemd
After creating or modifying the unit file, reload the systemd daemon:
sudo systemctl daemon-reload
Step 5: Enable and Start the Mount
Enable the mount to start automatically at boot:
sudo systemctl enable mnt-vmnfs.mount
Start the mount immediately:
sudo systemctl start mnt-vmnfs.mount
Step 6: Verify the Mount
Check the status of your mount:
systemctl status mnt-vmnfs.mount
Expected output:
● mnt-vmnfs.mount - NFS mount
Loaded: loaded (/proc/self/mountinfo; enabled; preset: disabled)
Active: active (mounted) since Sat 2025-11-08 10:16:37 CET; 3h 38min ago
Where: /mnt/vmnfs
What: atlas.uclab8.net:/volume1/VM-NFS
Tasks: 0 (limit: 18577)
Memory: 1.1M (peak: 2.5M)
CPU: 16ms