After you create a file system, you must mount the file system on an Elastic Compute Service (ECS) instance. This way, multiple ECS instances can share access to the file system. This topic describes how to mount a Server Message Block (SMB) file system of Apsara File Storage NAS on a Windows ECS instance.

Prerequisites

  • A Windows ECS instance is available in the region where you create a file system. For more information, see Create an ECS instance.
  • An SMB file system is created and the mount target of the file system is obtained. For more information, see Create a General-purpose NAS file system in the NAS console.
  • The network is available.
    • If the ECS instance and the NAS file system reside in the classic network, make sure that they belong to the same Alibaba Cloud account.
    • The IP address of the Windows ECS instance is in the whitelist of the SMB file system and the ECS instance can access the SMB file system.
    • TCP port 445 is enabled for the ECS instance to access the SMB file system.

      If port 445 is disabled, you must add a rule to a security group of the ECS instance for the port. For more information, see Add a security group rule.

Background information

In most cases, you must use the same identity to log on to Windows and mount a file system. In Windows, the SYSTEM account is used to invoke most system calls, including calls of Services and Scheduled Tasks.

Step 1: Prepare the environment

The first time you mount an SMB file system on a Windows ECS instance, perform the following steps:

  1. Connect to the ECS instance. For more information, see Connection methods.
  2. For Windows 2016 or later, run the following command to allow anonymous access from clients:
    REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters /f /v AllowInsecureGuestAuth /t REG_DWORD /d 1
  3. Enable the Workstation service.
    1. Open the Windows Start menu. Choose All Programs > Accessories > Run or press Win+R. Then, enter services.msc to open the Services window.
    2. Make sure that the Workstation service is in the Started state and the startup type is Automatic.

      By default, the Workstation service is in the Started state.

      Workstation
  4. Enable the TCP/IP NetBIOS Helper service.
    1. On the Network and Sharing Center page, click the active network connection.
    2. Select Properties. In the Connection Properties dialog box, double-click Internet Protocol Version 4 (TCP/IPv4). In the Internet Protocol Version 4 (TCP/IPv4) Properties dialog box, click Advanced.
    3. In the Advanced TCP/IP Settings dialog box, choose WINS > Enable NetBIOS over TCP/IP. Enable NetBIOS over TCP/IP
    4. Open the Windows Start menu. Choose All Programs > Accessories > Run or press Win+R. Then, enter services.msc to open the Services window.
    5. Make sure that the TCP/IP NetBIOS Helper service is in the Started state and the startup type is Automatic.

      By default, the TCP/IP NetBIOS Helper service is in the Started state.

      TCP/IP NetBIOS Helper

Step 2: Mount the SMB file system

SMB file systems can be mounted manually or automatically. When you restart the ECS instance on which a file system is mounted, the mount information about the file system may be lost. To prevent this issue, you can enable automatic mounting by using scripts after you manually mount an SMB file system.

Manually mount the SMB file system

To mount the SMB file system on the Windows ECS instance, you must obtain the mount target of the SMB file system.

  1. Connect to the ECS instance. For more information, see Connection methods.
  2. Open the Command Prompt and run the following command to mount the SMB file system:
    net use Z: \\file-system-id.region.nas.aliyuncs.com\myshare
    ParameterDescription
    ZThe drive letter. If a conflict occurs in drive Z, or if multiple NAS file systems are mounted to drive Z, the NAS file system is mounted to the next drive in reverse alphabetic order.
    file-system-id.region.nas.aliyuncs.comThe domain name of the mount target. The domain name is automatically generated when you create the mount target. Replace the domain name with the actual value.

    To obtain the domain name of the mount target, perform the following steps: Log on to the NAS console. On the File System List page, click the file system ID. Click the Mount Targets tab. Then, move the pointer over the Mount target icon in the Mount Target column.

    myshareThe name of the shared SMB directory. You cannot change the name.

    For Windows 2019 or later, we recommend that you run the New-SmbGlobalMapping command in PowerShell to mount the SMB file system. Run the following command to mount the SMB file system.

    If you are prompted to enter an identity when you run the preceding command, you can enter a valid identity in a workgroup, for example, workgroup\administrator. The password is the password of the ECS administrator.

    • Mount command
      New-SmbGlobalMapping -LocalPath z: -RemotePath \\file-system-id.region.nas.aliyuncs.com\myshare -Persistent $true
    • Unmount command
      Remove-SmbGlobalMapping -LocalPath z:
    • Command to check the mount result
      Get-SmbGlobalMapping
  3. Check whether the SMB file system is mounted.
    • Command
      net use
    • Sample command output

      If an output similar to the following example appears, the mount is successful. After the SMB file system is mounted, you can read data from and write data to the NAS file systems on the ECS instance.

      View the mount result

    If the file system fails to be mounted, you can use a script to automatically locate the issue or troubleshoot the issue based on error codes. For more information, see Fix mount issues and How do I fix the error that occurs when I mount an SMB file system on Windows?

Automatically mount the SMB file system

  1. Open the Command Prompt and run the following command to configure the auto_mount.bat script:
    echo %HOMEPATH%\mount.bat > auto_mount.bat
  2. Run the following commands to enable the auto_mount.bat script to automatically run after user logon, and then grant the read and execute permissions to everyone:
    MOVE auto_mount.bat "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"
    icacls "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\auto_mount.bat" /grant everyone:rx
    REG ADD HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run /f /v MyMount /t REG_SZ /d "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\auto_mount.bat"
  3. Run the following command to configure the mount.bat script:
    echo net use z: \\file-system-id.region.nas.aliyuncs.com\myshare > "%HOMEPATH%\mount.bat"

    Replace z with the actual drive letter and replace file-system-id.region.nas.aliyuncs.com with the actual domain name of the mount target.

    Note If the SMB file system supports Active Directory (AD) and access control lists (ACLs), you can run the following command to configure the script. Then, you can mount the SMB file system as a domain user rather than a Windows logon user:
    echo net use z: \\file-system-id.region.nas.aliyuncs.com\myshare /user:user@domain password > "%HOMEPATH%\mount.bat"

    Replace z with the actual drive letter, replace file-system-id.region.nas.aliyuncs.com with the actual domain name of the mount target, replace user@domain with the actual domain username, and replace password with the actual domain user password.

  4. Restart the ECS instance.
    Run the net use command to check the mount result.

References

  • For the best practices of building Windows applications on NAS, see Windows applications.
  • For information about how to use NAS in various content management systems and web applications to provide efficient storage services for websites and applications, see Web service and content management.
  • For more information about the best practices for using NAS, see Best Practices.