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
- You can use the SYSTEM account to mount an SMB file system. For more information, see Mount an SMB file system by using the SYSTEM account to allow Windows to access the file system.
- You can also use an AD identity or an Everyone account to mount an SMB file system. For more information, see Add the mount target of an SMB file system to an AD domain and Mount and use an SMB file system on a Windows client as an AD domain user.
Step 1: Prepare the environment
The first time you mount an SMB file system on a Windows ECS instance, perform the following steps:
- Connect to the ECS instance. For more information, see Connection methods.
- 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
- Enable the Workstation service.
- Open the Windows Start menu. Choose
Win+R
. Then, enterservices.msc
to open the Services window. or press - 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.
- Open the Windows Start menu. Choose
- Enable the TCP/IP NetBIOS Helper service.
- On the Network and Sharing Center page, click the active network connection.
- 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.
- In the Advanced TCP/IP Settings dialog box, choose .
- Open the Windows Start menu. Choose
Win+R
. Then, enterservices.msc
to open the Services window. or press - 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.
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.
- Connect to the ECS instance. For more information, see Connection methods.
- 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
Parameter Description Z The 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.com The 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
icon in the Mount Target column.
myshare The 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
- Mount command
- 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.
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?
- Command
Automatically mount the SMB file system
- Open the Command Prompt and run the following command to configure the auto_mount.bat script:
echo %HOMEPATH%\mount.bat > auto_mount.bat
- 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"
- 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 replacefile-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, replacefile-system-id.region.nas.aliyuncs.com
with the actual domain name of the mount target, replaceuser@domain
with the actual domain username, and replacepassword
with the actual domain user password. - 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.