Mount NFS Systemd
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:
Step 2: Generate the Systemd Unit Name
Use systemd-escape to generate the correct systemd unit name from your mount path:
Output:
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:
Add the following configuration:
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:
Step 5: Enable and Start the Mount
Enable the mount to start automatically at boot:
Start the mount immediately:
Step 6: Verify the Mount
Check the status of your mount:
Expected output: