This topic describes how to mount an NFS file system on an Elastic Compute Service (ECS) instance that runs Windows Server and perform read/write operations on the file system.

Background information

We recommend that you mount a Server Message Block (SMB) file system rather than an NFS file system on an ECS Windows instance. Compared with Windows, Linux has better compatibility with NFS. Therefore, we recommend that you mount an NFS file system on an ECS Windows instance only when you need to share data across operating systems.

The topic describes how to mount an NFS file system on an ECS Windows instance that resides in a virtual private cloud (VPC). Windows Server 2012 R2 is used in this example.

Prerequisites

Install the NFS client

  1. Start Server Manager.
  2. Choose Manage > Add Roles and Features.
  3. Follow the provided instructions in the Add Roles and Features Wizard to install the NFS client.
    • In the Server Roles step, choose File and Storage Services > File and iSCSI Services and select Server for NFS.
    • In the Features step, select Client for NFS.
  4. Restart the ECS instance.
  5. Start the command prompt and run the mount command.

    The following command output indicates that the NFS client is installed.

    Installation result

Manually mount the NFS file system

  1. Run the following command to mount the NFS file system:
    mount -o nolock -o mtype=hard -o timeout=60 \\file-system-id.region.nas.aliyuncs.com\! Z:

    In the preceding command, file-system-id.region.nas.aliyuncs.com indicates the domain name of the mount target. You need to replace the domain name with the actual value.

  2. Run the mount command to check whether the NFS file system is mounted.

    If the NFS file system is mounted, the command output shows that the value of mount is hard, the value of locking is no, and the value of timeout is greater than or equal to 10. Otherwise, the NFS file system is not mounted.

    Check the UID and GID
  3. In the This PC window, view the shared file system.

    Create files and folders in the shared file system to check whether you can manage the shared file system.

    Mount result

Automatically mount the NFS file system

  1. Enter the following content in the nas_auto.bat script file and save the file to the corresponding disk path.
    Example: mount -o nolock -o mtype=hard -o timeout=60 \\file-system-id.region.nas.aliyuncs.com\! Z:

    You need to replace the drive letter (Z :) and the domain name (file-system-id.region.nas.aliyuncs.com) with their actual values.

    Note If a success message is displayed but the NAS disk does not appear, move the nas_auto.bat file to the C:\ProgramData\Microsoft\Windows\StartMenu\Programs\StartUp directory. In this case, you do not need to create a task in the Task Scheduler window.
  2. Create a scheduled task.
    1. Open the Control Panel and choose Administrative Tools > Task Scheduler.
    2. In the Task Scheduler window, choose Actions > Create Task.
      Create a task
    3. On the General tab, enter the name of the task, and select Run whether user is logged on or not and Run with highest privileges.
      Configure basic settings
    4. Click the Triggers tab. Click New Trigger. Select At startup from the Begin the task drop-down list. In the Advanced settings section, select Enabled. Click OK.
      Configure trigger settings
    5. Click the Actions tab. Click New Action. Select Start a program from the Action drop-down list, select the nas_auto.bat file in the Program/script field, and then click OK.
      Start a program
    6. Click the Conditions tab. Select Start only if the following network connection is available. Select Any connection from the drop-down list under Start only if the following network connection is available.
      Configure condition settings
    7. Click the Settings tab. Select If the running task does not end when requested, force it to stop. Select Do not start a new instance from the drop-down list under If the task is already running, then the following rule applies.
      Settings
    8. Click OK.
    9. Restart the ECS instance to check whether the scheduled task is created.

      The following example shows that the scheduled task is created.

      Creation result

FAQ

If the file handle error message appears, check the following registry keys.

Note If you cannot find the Locking, AnonymousGID, and AnonymousUID registry keys, you need to follow the format required by the Windows registry to create these keys.
Choose HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > ClientForNFS > CurrentVersion > Users > Default > Mount, create a key named Locking, and set the value of this key to 1.Locking

Create the following registry keys to configure the GID and UID.

  1. Navigate to the Default path: HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > ClientForNFS > CurrentVersion > Default.
  2. Right-click a blank area on the right side of the Registry Editor window, choose New > DWORD (32-bit) Value, and create the following registry keys.
    • AnonymousGID: Set the value of the key to 0.
    • AnonymousUID: Set the value of the key to 0.Default path
  3. Restart the ECS instance.
  4. Run the following command to mount the NAS file system:
    mount -o nolock -o mtype=hard -o timeout=60 \\file-system-id.region.nas.aliyuncs.com\! Z:

    In the preceding command, file-system-id.region.nas.aliyuncs.com indicates the domain name of the mount target. You need to replace the domain name with the actual value.

  5. Run the mount command to check the UID and GID.

    If the NAS file system is mounted, the command output shows that the value of mount is hard, the value of locking is no, and the value of timeout is greater than or equal to 10. Otherwise, the NAS file system is not mounted.

    Check the UID and GID