If you want to share data across operating systems, you can mount a Network File System (NFS) file system on a Windows Elastic Compute Service (ECS) instance. This way, you can upload data to and download data from the NFS file system. This topic describes how to mount an NFS file system on an ECS instance that resides in a virtual private cloud (VPC). In this example, Windows Server 2012 R2 is used.

Install an NFS client

  1. Connect to the ECS instance. For more information, see Connection methods.
  2. Start Server Manager.
  3. Choose Manage > Add Roles and Features.
  4. Follow the Add Roles and Features Wizard to install the NFS client.
    1. In the Server Roles step, choose File and Storage Services > File and iSCSI Services and select Server for NFS.
    2. In the Features step, select Client for NFS.
  5. Restart the ECS instance.
  6. 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. On a Windows client, 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 endpoint of the mount target. You must replace the endpoint file-system-id.region.nas.aliyuncs.com with an actual endpoint. For more information about the endpoints of mount targets, see View the endpoint of a mount target.

    Note If you mount a subdirectory of an Apsara File Storage NAS file system, the mount may fail. We recommend that you do not mount a subdirectory of a NAS file system. For more information, see How do I resolve the invalid device error that is returned when I try to rename a file on the Windows NFS client?
  2. Run the mount command to check the mount result.

    If the command output is similar to the following information and contains mount=hard, locking=no, and timeout=<a value that is greater than or equal to 10>, the NFS file system is mounted. Otherwise, the NFS file system fails to be mounted.

    Check the UID and the GID
  3. Double-click the This PC icon to 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 results

Automatically mount the NFS file system

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

    In the preceding example, you must replace the drive letter Z: and the endpoint file-system-id.region.nas.aliyuncs.com with an actual drive letter and an actual endpoint. For more information, see Automatically mount the NFS file system.

  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.
      Notice If you use Windows Server 2016, you must select Run only when user is logged on. Otherwise, the configurations of automatic mounting for an NFS file system do not take effect.
      General tab
    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.
      Triggers tab
    5. Click the Actions tab. Click New Action. Select Start a program from the Action drop-down list and then specify the nas_auto.bat file that you created in Step 1 in the Program/script field. Click OK.
      New Trigger dialog box
    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.
      Conditions tab
    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.
      Audio Parameters step
    8. Click OK.
    9. Restart the ECS instance to check whether the scheduled task is created.

      If the output that is similar to the following information appears, the scheduled task is created.

      Creation result
      Note If the scheduled task is created but the NAS disk does not appear, move the nas_auto.bat file to the C:\ProgramData\Microsoft\Windows\StartMenu\Programs\StartUp directory. You do not need to create a task in the Task Scheduler window.

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 must create the keys in the format that is required by the Windows registry.
Choose HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > ClientForNFS > CurrentVersion > Users > Default > Mount, create a key named Locking, and then set the value of the key to 1. Locking

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

  1. Go to the Default directory: 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 then 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 endpoint of the mount target. You must replace the endpoint file-system-id.region.nas.aliyuncs.com with an actual endpoint.

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

    If the command output is similar to the following information and contains mount=hard, locking=no, and timeout=<a value that is greater than or equal to 10>, the NFS file system is mounted. Otherwise, the NFS file system fails to be mounted.

    Check the UID and the GID