This guide details the steps to ensure an NFS share mounts automatically at boot on a Linux system, incorporating troubleshooting tips and a custom systemd service for reliability.
- NFS client utilities installed on your system.
- Access to edit system configuration files with root permissions.
Ensure the NFS client utilities are installed:
sudo apt update
sudo apt install nfs-common
Edit the /etc/fstab
file to include your NFS share with the appropriate options:
-
Open
/etc/fstab
with a text editor, such as nano:sudo nano /etc/fstab
-
Add the NFS share entry:
10.10.12.85:/mnt/storage/docker-pv /mnt/nfs nfs _netdev,auto,nofail,vers=3 0 0
_netdev
ensures the mount waits for the network.auto
enables automatic mounting at boot.nofail
prevents boot failure if the mount fails.vers=3
specifies NFS version 3.
Make sure the system waits for the network to be fully available before attempting the NFS mount:
sudo systemctl enable NetworkManager-wait-online.service
sudo systemctl start NetworkManager-wait-online.service
If necessary, create a custom systemd service for more reliable NFS mounting:
-
Create the Service File:
Open a new service file in
/etc/systemd/system/
:sudo nano /etc/systemd/system/nfs-mount.service
-
Service File Content:
Input the following configuration, using your provided setup for the retry logic:
[Unit] Description=Mount NFS Share After=network-online.target Wants=network-online.target [Service] Type=oneshot ExecStart=/bin/sh -c 'while ! mount /mnt/nfs; do sleep 5; done' ExecStop=/bin/umount /mnt/nfs RemainAfterExit=yes [Install] WantedBy=multi-user.target
-
Enable and Start the Service:
Reload systemd, enable, and start the service:
sudo systemctl daemon-reload sudo systemctl enable nfs-mount.service sudo systemctl start nfs-mount.service
After setting up, reboot your system to test the automatic mount:
sudo reboot
Verify the NFS share is mounted successfully:
df -h
or
mount | grep nfs
This guide incorporates the necessary steps and a custom systemd service to ensure your NFS share mounts automatically at boot, addressing common issues related to network dependency and permissions.