乐闻世界logo
搜索文章和话题

How do you configure a Linux system to automatically mount an NFS share at startup?

1个答案

1

1. Ensure the NFS client is installed

First, verify that the NFS client is installed on the system. Use the following command to install:

bash
sudo apt-get install nfs-common # For Debian-based systems, such as Ubuntu

Or, for RPM-based systems, such as CentOS:

bash
sudo yum install nfs-utils

2. Create a mount point

Next, create a directory to serve as the local mount point for the NFS share:

bash
sudo mkdir /mnt/nfs_share

3. Edit the /etc/fstab file

The /etc/fstab file defines filesystems that are automatically mounted at system boot. Edit this file to add a line specifying the NFS server details and mount configuration.

Assuming the NFS server IP is 192.168.1.100 and the shared directory is /exported/path, the added line would be:

plaintext
192.168.1.100:/exported/path /mnt/nfs_share nfs defaults 0 0

Here, defaults specifies the use of default mount options, and 0 0 are the dump and pass options for the filesystem, typically set to 0 for NFS mounts.

4. Test the mount configuration

Before rebooting, verify the mount by manually testing:

bash
sudo mount -a

This command attempts to mount all filesystems defined in /etc/fstab. If successful, check the mount result with:

bash
df -h

Or:

bash
mount | grep nfs

5. Verify after system reboot

Finally, reboot the system to ensure the mount occurs automatically at boot:

bash
sudo reboot

After rebooting, run df -h or mount | grep nfs again to confirm that the NFS share is automatically mounted.

Example

For instance, in my previous work, we needed to ensure application servers automatically connected to a central NFS server upon each boot to retrieve configuration files and application data. By following these steps, we ensured services could immediately resume after system restarts while maintaining configuration consistency and data availability.

This configuration method is general-purpose and applicable to most Linux distributions. Adjust mount options such as read-only (ro) or read-write (rw) to meet specific application requirements.

2024年8月14日 13:15 回复

你的答案