This topic describes how to modify Linux configuration files to enable an automatic amount at startup for an NFS file system.

Prerequisites

  1. A file system is created. For more information, see Create a file system.
  2. A mount target is created. For more information, see Add a mount target.
  3. An NFS client is installed. For more information, see Install an NFS client.

NAS Capacity and NAS Performance

We recommend that you configure the /etc/fstab file to enable an automatic mount at startup for an NFS file system. You can also configure the /etc/rc.local file to enable an automatic mount.

  1. Log on to the ECS console.
  2. Configure an automatic mount.
    • Recommended. Open the /etc/fstab configuration file and add the following command.
      Note If you want to configure an automatic mount on CentOS 6.x, use the chkconfg netfs on command to enable the netfs service to run at startup.
      • To mount an NFSv4 file system, add the following command.
        file-system-id.region.nas.aliyuncs.com:/ /mnt nfs vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0
      • To mount an NFSv3 file system, add the following command.
        file-system-id.region.nas.aliyuncs.com:/ /mnt nfs vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0
    • Open the /etc/rc.local configuration file and add the mount command.
      Note

      Before configuring the /etc/rc.local file, ensure that you have execute permissions for the /etc/rc.local and /etc/rc.d/rc.local files. For example, on CentOS 7.x, no execute permission is granted by default. You must be granted the execute permission before configuring the /etc/rc.local file.

      • To mount an NFSv4 file system, add the following command.
        sudo mount -t nfs -o vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport file-system-id.region.nas.aliyuncs.com:/ /mnt
      • To mount an NFSv3 file system, add the following command.
        sudo mount -t nfs -o vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport file-system-id.region.nas.aliyuncs.com:/ /mnt
      The following table describes the parameters used in the commands.
      Parameter Description
      file-system-id.region.nas.aliyuncs.com:/ /mnt file-system-id.region.nas.aliyuncs.com specifies the mount target of the NAS file system, the forward slash (/) following the mount target specifies the root directory of the NAS file system, and /mnt specifies a local mount point that resides on the Linux ECS instance. You need to replace the example parameters based on your business requirements.
      • The mount target, for example, file-system-id.region.nas.aliyuncs.com. To obtain information about a mount target, follow these steps. Log on to the NAS console, find the target system, click Manage next to the file system to go to the Details page. The Details page shows information about the mount target.
      • The directory of the NAS file system: specifies the root directory (/) or a subdirectory (/share). If a subdirectory is specified, ensure that the subdirectory exists.
      • The local directory on which you want to mount a file system: specifies the root directory (/) or a subdirectory (/mnt) of a system such as Linux. If a subdirectory is specified, ensure that the subdirectory exists.
      vers The version of the file system. Only NFSv3 and NFSv4 are applicable.
      _netdev Prevents a file system from mounting on an ECS instance before a network connection is established.
      0 (the first zero after noresvport) Non-zero values indicate that a file system must be backed up by using dump. For a NAS file system, the value of the parameter is 0.
      0 (the second zero after noresvport) This value indicates the order in which fsck checks available file systems at startup. For a NAS file system, the value of the parameter is 0. It indicates that fsck is not allowed to run at startup.
      Mount options Multiple mount options are available when you mount a file system. For more information, see the following table.
      Notice When you set parameters, take note of the following items.
      • To avoid a decrease in performance, we recommend that you specify the maximum value (1048576) for both the rsize parameter and the wsize parameter.
      • If you need to modify the timeo parameter, we recommend that you specify a minimum of 150 for the parameter. The timeo parameter is measured in deciseconds (tenths of a second). For example, a value of 150 indicates 15 seconds.
      • To avoid data inconsistency, we recommend that you do not use the soft parameter. Use caution with the soft parameter.
      • We recommend that you use the default values for other mount parameters. For example, a decrease in performance may occur due to changes in some mount parameters. These mount parameters include the size of the read or write buffer or the use of attribute caching.
      Separate multiple mount parameters with commas (,). The following table describes the mount parameters.
      Parameter Description
      rsize Specifies the maximum number of bytes in each read request that the NFS client can receive. Recommended value: 1048576
      wsize Specifies the maximum number of bytes in each write request that the NFS client can send. Recommended value: 1048576
      hard Specifies that applications must stop accessing a file system when the file system is unavailable, and wait until the file system is available. We recommended that you use the hard parameter.
      timeo Specifies the time in deciseconds that the NFS client waits before it retries an NFS request. Recommended value: 60 seconds
      retrans Specifies the number of times the NFS client retries a request. Recommended value: 2
      noresvport Specifies that the NFS client uses a different TCP source port for a new network connection to ensure data integrity. We recommend that you use the noresvport parameter.
  3. Run the reboot command to restart the ECS instance.
  4. Use the mount -l command to view the mount result.

    The following figure shows an example of a successful mount.

    View the mount result

    After a file system is mounted, you can use the df -h command to view the size of the file system.

  5. After you mount an NAS file system on an ECS instance, you can access the file system from the ECS instance.

    You can access the file system in the same way you access a local directory. The following figure shows an example.

    Read and write operations

Troubleshoot common errors

If a mount operation fails, you can troubleshoot the issue. For more information, see Troubleshoot and fix mount issues.