To mount an NFS (Network File System) drive automatically at boot in Ubuntu using the /etc/fstab file, follow these steps:
✅ Step-by-Step Guide to Mount NFS via /etc/fstab
🔧 1. Install NFS Client
Ensure the NFS client utilities are installed:
sudo apt update
sudo apt install nfs-common
📁 2. Create a Mount Point
Choose or create a directory where you want the NFS share to be mounted:
sudo mkdir -p /mnt/nfs_share
Replace /mnt/nfs_share with your desired mount point.
🌐 3. Test Mount Manually (Optional but Recommended)
Before editing fstab, test mounting the NFS share manually:
sudo mount <nfs_server_ip>:/path/to/exported/folder /mnt/nfs_share
Example:
sudo mount 192.168.1.100:/exports/data /mnt/nfs_share
Check if it's mounted:
df -h
Or:
mount | grep nfs
Unmount after testing:
sudo umount /mnt/nfs_share
📄 4. Edit /etc/fstab
Open the fstab file for editing:
sudo nano /etc/fstab
Add a line like this at the end of the file:
<server_ip>:/exported/path /mnt/mount_point nfs defaults,_netdev 0 0
Example:
192.168.1.100:/exports/data /mnt/nfs_share nfs defaults,_netdev 0 0
💡 Explanation of Options:
defaults: Use default NFS mount options.
_netdev: Ensures the mount waits until the network is up (important for booting).
You can also specify additional options like nfsvers=4, bg, soft, etc., depending on your needs:
Example with specific version:
192.168.1.100:/exports/data /mnt/nfs_share nfs defaults,_netdev,nfsvers=3 0 0
🔄 5. Test the FSTAB Entry
After saving /etc/fstab, test it by running:
sudo mount -a
This command mounts all entries in fstab. If there’s an error, double-check the syntax and connectivity.
Check if it's mounted:
df -h
🛡️ 6. Reboot (Optional)
To ensure everything works on boot:
sudo reboot
After reboot, check that the NFS share is mounted correctly.
❗ Troubleshooting Tips
- Ensure the server's firewall allows NFS traffic.
- Make sure the NFS server is exporting the correct path.
- Check logs with
dmesg | grep nfs or /var/log/syslog.
- If the mount fails during boot, ensure
_netdev is included in options.
Let me know if you need help configuring NFS server-side too!